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 std::string escape_seqs_full[] = {
"&",
"<",
">",
"'",
""" };
64 static const unsigned escape_size = 5;
66 const std::string
escape( std::string what )
68 for(
size_t val, i = 0; i < what.length(); ++i )
70 for( val = 0; val < escape_size; ++val )
72 if( what[i] == escape_chars[val] )
75 what.insert( i+1, escape_seqs[val] );
76 i += escape_seqs[val].length();
86 size_t rangeStart = 0, rangeCount = 0;
87 size_t length = data.length();
88 const char* dataPtr = data.data();
89 for(
size_t val, i = 0; i < length; ++i )
91 const char current = dataPtr[i];
92 for( val = 0; val < escape_size; ++val )
94 if( current == escape_chars[val] )
105 target.append( data, rangeStart, rangeCount );
107 target.append( escape_seqs_full[val] );
114 if( rangeStart <= i )
126 target.append( data, rangeStart, rangeCount );
135 const char* dataPtr = data.data();
136 const char* end = dataPtr + data.length();
137 for( ; dataPtr != end; ++dataPtr )
139 unsigned char current = (
unsigned char) *dataPtr;
151 else if( current >= 0xf5 )
154 else if( current == 0xc0
163 return ( dataPtr == end );
166 void replaceAll( std::string& target,
const std::string& find,
const std::string& replace )
168 std::string::size_type findSize = find.size();
169 std::string::size_type replaceSize = replace.size();
174 std::string::size_type index = target.find( find, 0 );
176 while( index != std::string::npos )
178 target.replace( index, findSize, replace );
179 index = target.find( find, index+replaceSize );