#include #include #include namespace s11n { namespace io { namespace strtool { size_t translate_entities( std::string & str, const entity_map & map, bool reverse ) { if( str.empty() || ( 0 == map.size() ) ) return 0; size_t count = 0; std::string::size_type pos = str.npos; std::string::size_type pos2 = str.npos; entity_map::const_iterator mit; entity_map::const_iterator met = map.end(); std::string key; std::string val; if( reverse ) { // CERR << "Reverse-translating entities.\n"; // treat KEY=VAL as VAL=KEY mit = map.begin(); for( ; mit != met; ++mit ) { key = (*mit).second; val = (*mit).first; //CERR << "reverse-map key=["<, // default_escapes_initializer // > TMap; static entity_map bob; if( bob.empty() ) { default_escapes_initializer()( bob ); } return bob; } size_t strip_slashes( std::string &str, const char slash ) { std::string::size_type osz; if( str.empty() || ((osz = str.size()) < 2 ) ) return 0; std::string::size_type pos = 0; size_t count = 0; pos = str.find( slash ); if( pos == str.npos ) return 0; if( osz < 2 ) return 0; // strip escaped newlines. this is in a separate loop // because it used to be in a different function. :/ pos = osz-2; std::string::size_type search; while( pos > 2 ) { char c = str[pos]; if( slash == c && (str[pos-1] != slash) ) { ++count; search = str.find_first_not_of( " \t\n", pos +1 ); if( search > pos + 1 ) { //COUT << "stripping until " << search << ":["< str.size()-2) ) ) { // todo: search from the end, going // backwards. This "might" be faster in terms // of string's required workload. ++count; str.erase( pos, 1 ); if( slash != str[pos+1] ) { pos += 1; } else pos += 2; pos = str.find( slash, pos ); } return count; } void normalize_string( std::string &str ) { //COUT << "normalize_string("<= 48 && c <=57 ) // 0-9 { i = ((int)c - 48); } else if( c >= 65 && c <=70 ) // A-F { i = ((int)c - 65) + 10; } else if( c >= 97 && c <=102 ) // a-f { i = ((int)c - 97) + 10; } return i; } int hex2int( const std::string & wd ) { unsigned int mult = 1; int ret = 0; char c; for( std::string::size_type i = wd.size(); i > 0; --i ) { //COUT << "i="<= 0 && pos_a != string::npos; pos_a-- ) { atc = buffer[pos_a]; if( atc != vardelim ) { continue; } if( pos_a>0 && !slashmode && buffer[pos_a-1] == '\\' ) slashmode = true; if( slashmode ) { // arguable: --pos_a; // strip 1 slash buffer.erase( pos_a, 1 ); // todo: only remove slashe preeding $. // end arguable slashmode = false; continue; } pos_b = buffer.find_first_not_of( allowable_chars, pos_a+1 ); // find first non-variablename char if( pos_b != pos_a +1 ) pos_b -= 1; if( pos_b == string::npos ) { pos_b = buffer.size() -1; } tmpvar.clear(); if( pos_b == pos_a + 1 ) // ${VAR} or $F, hopefully { atc = buffer[pos_b]; if( atc != opener ) { // $NONBRACED_VAR pos_b = buffer.find_first_not_of( allowable_chars, pos_b ); tmpvar = buffer.substr( pos_a + 1, pos_b ); //CERR << "nonbraced var? ["<