void NamedColumnsParser::reinitMap(std::string s, const std::string& delim, bool prune) { if (myAmCaseInsensitive) { s = StringUtils::to_lower_case(s); } myDefinitionsMap.clear(); int pos = 0; StringTokenizer st(s, delim); while (st.hasNext()) { std::string next = st.next(); checkPrune(next, prune); myDefinitionsMap.insert(std::map<std::string, int>::value_type(next, pos++)); } }
std::string NamedColumnsParser::get(const std::string& name, bool prune) const { PosMap::const_iterator i = myDefinitionsMap.find(name); if (i == myDefinitionsMap.end()) { if (myAmCaseInsensitive) { i = myDefinitionsMap.find(StringUtils::to_lower_case(name)); } if (i == myDefinitionsMap.end()) { throw UnknownElement(name); } } int pos = (*i).second; if (myLineParser.size() <= pos) { throw OutOfBoundsException(); } std::string ret = myLineParser.get(pos); checkPrune(ret, prune); return ret; }
void encode(FILE* infile, FILE* outfile, unsigned int maxBits, unsigned int window, bool eFlag) { stringTable* table = stringTableNew(maxBits, eFlag); pruneInfo* pi = pruneInfoNew(maxBits); // write maxBits, window, and eFlag to outfile putBits(NBITS_MAXBITS, maxBits, outfile); putBits(NBITS_WINDOW, window, outfile); eFlag ? putBits(NBITS_EFLAG, 1, outfile) : putBits(NBITS_EFLAG, 0, outfile); // the string table is populated with (c, k) pairs; c is the code for the // prefix of the entry, k is the char appended to the end of the prefix unsigned int c = EMPTY_PREFIX; int k; unsigned char nbits = (eFlag) ? 2 : 9; // number of bits sent per code while((k = fgetc(infile)) != EOF) { tableElt* elt = stringTableHashSearch(table, c, k); if(elt) { c = elt->code; } else if(c == EMPTY_PREFIX) { // we're escaping k, so leave the prefix empty escapeChar(table, pi, k, &nbits, outfile); table = checkPrune(table, pi, window, &c, &nbits, outfile); } else { putBits(nbits, c, outfile); pruneInfoSawCode(pi, c); stringTableAdd(table, c, k, NULL); table = checkPrune(table, pi, window, &c, &nbits, outfile); checkNbits(&nbits, table, outfile); tableElt* kCode = stringTableHashSearch(table, EMPTY_PREFIX, k); if(kCode) { c = kCode->code; } else { escapeChar(table, pi, k, &nbits, outfile); c = EMPTY_PREFIX; // since we escaped k, we now have no prefix checkPrune(table, pi, window, &c, &nbits, outfile); } } } if(c != EMPTY_PREFIX) putBits(nbits, c, outfile); putBits(nbits, STOP_CODE, outfile); flushBits(outfile); stringTableDelete(table); pruneInfoDelete(pi); }