25 if ( n >= 1<<16 ) { n >>= 16; pos += 16; }
26 if ( n >= 1<< 8 ) { n >>= 8; pos += 8; }
27 if ( n >= 1<< 4 ) { n >>= 4; pos += 4; }
28 if ( n >= 1<< 2 ) { n >>= 2; pos += 2; }
29 if ( n >= 1<< 1 ) { pos += 1; }
30 return ( (n == 0) ? (-1) : pos );
33 unsigned _lookup(
const std::string& str,
const char* values[],
unsigned size,
int def )
36 for( ; i < size && str != values[i]; ++i )
38 return ( i == size && def >= 0 ) ? (unsigned)def : i;
41 const std::string
_lookup(
unsigned code,
const char* values[],
unsigned size,
const std::string& def )
43 return code < size ? std::string( values[code] ) : def;
46 unsigned _lookup2(
const std::string& str,
const char* values[],
47 unsigned size,
int def )
52 const std::string
_lookup2(
unsigned code,
const char* values[],
unsigned size,
const std::string& def )
55 return i < size ? std::string( values[i] ) : def;
58 static const char escape_chars[] = {
'&',
'<',
'>',
'\'',
'"' };
60 static const std::string escape_seqs[] = {
"amp;",
"lt;",
"gt;",
"apos;",
"quot;" };
62 static const unsigned escape_size = 5;
64 const std::string
escape( std::string what )
66 for(
size_t val, i = 0; i < what.length(); ++i )
68 for( val = 0; val < escape_size; ++val )
70 if( what[i] == escape_chars[val] )
73 what.insert( i+1, escape_seqs[val] );
74 i += escape_seqs[val].length();
87 std::string::const_iterator it = data.begin();
88 for( ; it != data.end()
89 && ( (
unsigned char)(*it) == 0x09
90 || (
unsigned char)(*it) == 0x0a
91 || (
unsigned char)(*it) == 0x0d
92 || ( (
unsigned char)(*it) >= 0x20
93 && (
unsigned char)(*it) != 0xc0
94 && (
unsigned char)(*it) != 0xc1
95 && (
unsigned char)(*it) < 0xf5 ) ); ++it )
98 return ( it == data.end() );
101 void replaceAll( std::string& target,
const std::string& find,
const std::string& replace )
103 std::string::size_type findSize = find.size();
104 std::string::size_type replaceSize = replace.size();
109 std::string::size_type index = target.find( find, 0 );
111 while( index != std::string::npos )
113 target.replace( index, findSize, replace );
114 index = target.find( find, index+replaceSize );