Annotation of parser3/src/include/pa_string.h, revision 1.186
1.41 paf 1: /** @file
1.43 paf 2: Parser: string class decl.
3:
1.179 misha 4: Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)
1.124 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_STRING_H
9: #define PA_STRING_H
1.140 paf 10:
1.186 ! misha 11: static const char * const IDENT_STRING_H="$Date: 2009-05-15 06:57:43 $";
1.145 paf 12:
13: // includes
1.4 paf 14: #include "pa_types.h"
1.145 paf 15: #include "pa_array.h"
16:
17: extern "C" { // cord's author forgot to do that
18: #define CORD_NO_IO
19: #include "cord.h"
1.186 ! misha 20:
! 21: #ifdef CORD_CAT_OPTIMIZATION
! 22: #define CORD_cat(x, y) CORD_cat_optimized(x, y)
! 23: #define CORD_cat_char_star(x, y, leny) CORD_cat_char_star_optimized(x, y, leny)
! 24: #endif
1.145 paf 25: };
1.4 paf 26:
1.164 paf 27: // defines
28:
1.183 misha 29: // cache hash code in String::Body for faster hash access
30: #define HASH_CODE_CACHING
31:
1.146 paf 32: // cord extension
33: /* Returns true if x does contain */
34: /* char not_c at positions i..i+n. Value i,i+n must be < CORD_len(x). */
35: int CORD_range_contains_chr_greater_then(CORD x, size_t i, size_t n, int c);
1.148 paf 36: size_t CORD_block_count(CORD x);
1.146 paf 37:
1.145 paf 38: // forwards
1.9 paf 39:
1.145 paf 40: class Charset;
1.135 paf 41: class Table;
1.71 paf 42: class SQL_Connection;
1.101 parser 43: class Dictionary;
1.145 paf 44: class Request_charsets;
45: class String;
46: typedef Array<const String*> ArrayString;
1.178 misha 47: class VRegex;
1.145 paf 48:
1.155 paf 49: // generally useful
50:
51: int pa_atoi(const char* str, const String* problem_source=0);
52: double pa_atod(const char* str, const String* problem_source=0);
53:
1.145 paf 54: /// this is result of pos functions which mean that substr were not found
55: #define STRING_NOT_FOUND ((size_t)-1)
56:
1.146 paf 57: template<typename T>
58: inline size_t get_length(T current) {
59: return current;
60: }
1.147 paf 61:
1.42 paf 62: /**
1.146 paf 63: String which knows the lang of all it's langs.
1.41 paf 64:
65: All pieces remember
66: - whether they are tainted or not,
1.146 paf 67: and the lang which should be used to detaint them
1.41 paf 68: */
1.176 misha 69:
70:
1.145 paf 71: class String: public PA_Object {
1.1 paf 72: public:
1.48 paf 73:
1.146 paf 74: /** piece is tainted or not. the lang to use when detaint
1.106 parser 75: remember to change String_Untaint_lang_name @ untaint.C along
1.148 paf 76:
77: WARNING WARNING WARNING WARNING WARNING WARNING
78:
79: pos function compares(<=) languages, that is used in searching
80: for table column separator being L_CLEAN or L_AS_IS.
81: they search for AS_IS, meaning AS_IS|CLEAN [doing <=L_AS_IS check].
82:
83: letters assigned for debugging, but it's important for no language-letter
84: come before L_AS_IS other then L_CLEAN
85:
86: WARNING WARNING WARNING WARNING WARNING WARNING
1.106 parser 87: */
1.145 paf 88: enum Language {
1.146 paf 89: L_UNSPECIFIED=0, ///< no real string has parts of this lange: it's just convinient to check when string's empty
1.145 paf 90: // these two must go before others, there are checks for >L_AS_IS
1.170 misha 91: L_CLEAN='0', ///< clean WARNING: read above warning before changing
92: L_AS_IS='A', ///< leave all characters intact WARNING: read above warning before changing
1.122 paf 93:
1.148 paf 94: L_PASS_APPENDED='P',
1.41 paf 95: /**<
1.146 paf 96: leave lang built into string being appended.
1.41 paf 97: just a flag, that value not stored
98: */
1.170 misha 99: L_TAINTED='T', ///< tainted, untaint lang as assigned later
1.146 paf 100: // untaint langs. assigned by ^untaint[lang]{...}
1.170 misha 101: L_FILE_SPEC='F', ///< file specification
102: L_HTTP_HEADER='h', ///< text in HTTP response header
103: L_MAIL_HEADER='m', ///< text in mail header
104: L_URI='U', ///< text in uri
105: L_SQL='Q', ///< ^table:sql body
106: L_JS='J', ///< JavaScript code
1.148 paf 107: L_XML='X', ///< ^dom:set xml
1.170 misha 108: L_HTML='H', ///< HTML code
109: L_REGEX='R', ///< RegEx expression
110: L_HTTP_COOKIE='C', ///< cookies encoded as %uXXXX for compartibility with js functions encode/decode
1.175 misha 111: L_FILE_POST='f', ///temporary escaping zero-char
1.148 paf 112: // READ WARNING ABOVE BEFORE ADDING ANYTHING
1.146 paf 113: L_OPTIMIZE_BIT = 0x80 ///< flag, requiring cstr whitespace optimization
1.27 paf 114: };
115:
1.157 paf 116: enum Trim_kind {
117: TRIM_BOTH,
118: TRIM_START,
119: TRIM_END
120: };
121:
1.176 misha 122:
1.147 paf 123: union Languages {
1.146 paf 124:
1.147 paf 125: struct {
1.160 paf 126: #ifdef PA_LITTLE_ENDIAN
1.147 paf 127: Language lang:8;
1.179 misha 128: size_t is_not_just_lang:sizeof(CORD)*8-8;
1.160 paf 129: #elif defined(PA_BIG_ENDIAN)
1.179 misha 130: size_t is_not_just_lang:sizeof(CORD)*8-8;
1.160 paf 131: Language lang:8;
132: #else
133: # error word endianness not determined for some obscure reason
134: #endif
1.147 paf 135: } opt;
136: CORD langs;
1.146 paf 137:
138: template<typename C>
139: CORD make_langs(C current) const {
1.147 paf 140: return opt.is_not_just_lang?
1.146 paf 141: langs
1.162 paf 142: :CORD_chars((char)opt.lang, get_length(current));
1.146 paf 143: }
144:
145: CORD make_langs(size_t aoffset, size_t alength) const {
1.147 paf 146: return opt.is_not_just_lang?
1.146 paf 147: CORD_substr(langs, aoffset, alength)
1.162 paf 148: :CORD_chars((char)opt.lang, alength);
1.145 paf 149: }
150:
1.157 paf 151: /// appending when 'langs' already contain something [simple cases handled elsewhere]
1.146 paf 152: template<typename C>
153: void append(C current,
154: const CORD to_nonempty_target_langs) {
155: assert(langs);
156:
1.147 paf 157: if(opt.is_not_just_lang)
1.146 paf 158: langs=CORD_cat(langs, to_nonempty_target_langs);
159: else { // we were "just lang"
160: size_t current_size=get_length(current);
161: assert(current_size);
162: langs=CORD_cat(
1.162 paf 163: CORD_chars((char)opt.lang, current_size), // first piece [making from just 'lang']
1.146 paf 164: to_nonempty_target_langs); // new piece
165: }
1.145 paf 166: }
1.146 paf 167:
1.145 paf 168: public:
1.146 paf 169:
170: const char* v() const;
1.164 paf 171: void dump() const;
1.146 paf 172:
173: Languages(): langs(0) {}
1.147 paf 174: Languages(Language alang) {
175: opt.lang=alang;
176: opt.is_not_just_lang=0;
177: }
1.146 paf 178:
179: /// MUST be called exactly prior to modification of current [uses it's length]
180: template<typename C>
181: void append(C current, Language alang, size_t asize) {
182: assert(alang);
183: assert(asize);
184:
1.147 paf 185: if(!opt.is_not_just_lang)
186: if(opt.lang) {
1.181 misha 187: if(opt.lang==alang) // same language? ignoring
1.146 paf 188: return;
189: } else {
1.147 paf 190: opt.lang=alang; // to uninitialized
1.146 paf 191: return;
1.145 paf 192: }
1.146 paf 193:
1.162 paf 194: append(current, CORD_chars((char)alang, asize));
1.146 paf 195: }
196:
1.176 misha 197: template<typename C>
198: void appendHelper(C current, Language alang, C asize_helper) {
199: assert(alang);
200:
201: if(!opt.is_not_just_lang)
202: if(opt.lang) {
1.183 misha 203: if(opt.lang==alang) // same language? ignoring
1.176 misha 204: return;
205: } else {
206: opt.lang=alang; // to uninitialized
207: return;
208: }
209:
210: append(current, CORD_chars((char)alang, asize_helper.length()));
211: }
212:
213: template<typename C>
1.186 ! misha 214: void appendHelper(C current, const Languages src, C length_helper) {
! 215: if(!langs){
1.176 misha 216: langs=src.langs; // to uninitialized
1.186 ! misha 217: #ifdef CORD_CAT_OPTIMIZATION
! 218: if(opt.is_not_just_lang && !CORD_IS_STRING(langs))
! 219: CORD_concatenation_protect(langs);
! 220: #endif
! 221: }
1.176 misha 222: else if(!src.opt.is_not_just_lang)
223: appendHelper(current, src.opt.lang, length_helper); // simplifying when simple source
224: else
225: append(current, src.make_langs(length_helper));
226: }
227:
228:
1.146 paf 229: /// MUST be called exactly prior to modification of current [uses it's length]
230: template<typename C>
231: void append(C current,
232: const Languages src, size_t aoffset, size_t alength) {
233: assert(alength);
234:
235: if(!langs) // to uninitialized?
1.147 paf 236: if(src.opt.is_not_just_lang)
1.146 paf 237: langs=CORD_substr(src.langs, aoffset, alength); // to uninitialized complex
238: else
1.147 paf 239: opt.lang=src.opt.lang; // to uninitialized simple
1.146 paf 240: else
1.147 paf 241: if(!opt.is_not_just_lang && !src.opt.is_not_just_lang && opt.lang==src.opt.lang) // both simple & of same language?
1.146 paf 242: return; // ignoring
243: else
244: append(current, src.make_langs(aoffset, alength));
245: }
246:
247: /// checks if we have lang<=alang all from aoffset to aoffset+alength
248: bool check_lang(Language alang, size_t aoffset, size_t alength) const {
249: if(alang==L_UNSPECIFIED) // ignore lang?
250: return true;
251:
1.147 paf 252: if(opt.is_not_just_lang)
1.146 paf 253: return CORD_range_contains_chr_greater_then(langs, aoffset, alength, (unsigned)alang)==0;
254: else
1.169 misha 255: return (unsigned)opt.lang<=(unsigned)alang;
1.146 paf 256: }
257:
1.148 paf 258: /// @returns count of blocks
259: /// @todo currently there can be adjucent blocks of same language. someday merge them
260: size_t count() const {
261: return opt.is_not_just_lang?
262: CORD_block_count(langs)
263: : opt.lang?
264: 1
265: : 0;
266: };
267:
1.146 paf 268: template<typename C, typename I>
269: void for_each(C current,
270: int callback(char, size_t, I), I info) const {
271:
1.147 paf 272: if(opt.is_not_just_lang)
1.146 paf 273: CORD_block_iter(langs, 0, (CORD_block_iter_fn)callback, info);
274: else
1.147 paf 275: callback(opt.lang, get_length(current), info);
1.146 paf 276: }
277:
1.164 paf 278: bool invariant(size_t current_length) const {
1.146 paf 279: if(!langs)
280: return current_length==0;
1.147 paf 281: if(opt.is_not_just_lang)
1.146 paf 282: return CORD_len(langs)==current_length;
283: return true; // uncheckable, actually
284: }
285: };
286:
287: class Body {
288:
289: CORD body;
290:
1.183 misha 291: #ifdef HASH_CODE_CACHING
292: // cached hash code is not reseted on write operations as test shows
293: // that string body does not change after it is stored as a hash key
294: mutable uint hash_code;
295: #endif
296:
1.146 paf 297: public:
298:
299: const char* v() const;
1.164 paf 300: void dump() const;
1.146 paf 301:
1.183 misha 302: #ifdef HASH_CODE_CACHING
303: Body(): body(CORD_EMPTY), hash_code(0) {}
304: Body(CORD abody, uint ahash_code): body(abody), hash_code(ahash_code) {}
305: Body(CORD abody): body(abody), hash_code(0) {
306: #else
1.146 paf 307: Body(): body(CORD_EMPTY) {}
308: Body(CORD abody): body(abody) {
1.183 misha 309: #endif
1.186 ! misha 310: #ifdef CORD_CAT_OPTIMIZATION
! 311: assert(!body // no body
! 312: || *body // ordinary string
! 313: || body[1]==1 // CONCAT_HDR
! 314: || body[1]==3 // CONCAT_HDR_READ_ONLY
! 315: || body[1]==4 // FN_HDR
! 316: || body[1]==6 // SUBSTR_HDR
! 317: );
! 318: #else
1.146 paf 319: assert(!body // no body
320: || *body // ordinary string
321: || body[1]==1 // CONCAT_HDR
322: || body[1]==4 // FN_HDR
323: || body[1]==6 // SUBSTR_HDR
324: );
1.186 ! misha 325: #endif
1.146 paf 326: }
1.181 misha 327:
1.146 paf 328: static Body Format(int value);
329:
330: void clear() { body=CORD_EMPTY; }
331:
332: bool operator! () const { return is_empty(); }
333:
1.183 misha 334: CORD get_cord() const { return body; }
335: uint get_hash_code() const;
1.146 paf 336:
337: const char* cstr() const { return CORD_to_const_char_star(body); }
338: char* cstrm() const { return CORD_to_char_star(body); }
339:
340: size_t length() const { return CORD_len(body); }
341:
342: bool is_empty() const { return body==CORD_EMPTY; }
343:
344: void append_know_length(const char *str, size_t known_length) {
345: if(known_length)
346: body=CORD_cat_char_star(body, str, known_length);
347: }
348: void append_strdup_know_length(const char* str, size_t known_length) {
349: if(known_length)
350: append_know_length(pa_strdup(str, known_length), known_length);
351: }
352: void append(char c) { body=CORD_cat_char(body, c); }
353: Body& operator << (const Body src) { body=CORD_cat(body, src.body); return *this; }
354: Body& operator << (const char* str) { append_know_length(str, strlen(str)); return *this; }
355:
356: // could not figure out why this operator is needed [should do this chain: string->simple->==]
357: bool operator < (const Body src) const { return CORD_cmp(body, src.body)<0; }
358: bool operator > (const Body src) const { return CORD_cmp(body, src.body)>0; }
359: bool operator <= (const Body src) const { return CORD_cmp(body, src.body)<=0; }
360: bool operator >= (const Body src) const { return CORD_cmp(body, src.body)>=0; }
361: bool operator != (const Body src) const { return CORD_cmp(body, src.body)!=0; }
362: bool operator == (const Body src) const { return CORD_cmp(body, src.body)==0; }
363:
364: int ncmp(size_t x_begin, const Body y, size_t y_begin, size_t size) const {
365: return CORD_ncmp(body, x_begin, y.body, y_begin, size);
1.145 paf 366: }
367:
1.146 paf 368: char fetch(size_t index) const { return CORD_fetch(body, index); }
369: Body mid(size_t index, size_t length) const { return CORD_substr(body, index, length); }
370: size_t pos(const char* substr, size_t offset=0) const { return CORD_str(body, offset, substr); }
371: size_t pos(const Body substr, size_t offset=0) const {
1.180 misha 372: if(substr.is_empty())
1.146 paf 373: return STRING_NOT_FOUND; // in this case CORD_str returns 0 [parser users got used to -1]
1.150 paf 374:
375: // CORD_str checks for bad offset [CORD_chr does not]
1.146 paf 376: return CORD_str(body, offset, substr.body);
377: }
378: size_t pos(char c,
379: size_t offset=0) const {
1.150 paf 380: if(offset>=length()) // CORD_chr does not check that [and ABORT's in that case]
381: return STRING_NOT_FOUND;
382:
1.146 paf 383: return CORD_chr(body, offset, c);
1.145 paf 384: }
1.146 paf 385:
1.159 paf 386: template<typename I> int for_each(
387: int (*f)(char c, I),
388: I info) const {
389: return CORD_iter(body, (CORD_iter_fn)f, (void*)info);
390: }
391:
392: template<typename I> int for_each(
1.149 paf 393: int (*f1)(char c, I),
394: int (*f2)(const char* s, I),
395: I info) const {
1.159 paf 396: return CORD_iter5(body, 0, (CORD_iter_fn)f1, (CORD_batched_iter_fn)f2, info);
1.148 paf 397: }
1.146 paf 398:
399: void set_pos(CORD_pos& pos, size_t index) const { CORD_set_pos(pos, body, index); }
400:
401: /*Body normalize() const {
402: return Body(CORD_balance(body));
403: }*/
1.157 paf 404:
405: /// @returns this or 0 or mid. if returns this or 0 out_* are not filled
406: Body trim(Trim_kind kind=TRIM_BOTH, const char* chars=0,
407: size_t* out_start=0, size_t* out_length=0) const;
1.145 paf 408: };
409:
410: struct C {
411: const char *str;
412: size_t length;
413: operator const char *() { return str; }
1.158 paf 414: C(): str(0), length(0) {}
1.145 paf 415: C(const char *astr, size_t asize): str(astr), length(asize) {}
416: };
417:
418: struct Cm {
419: char *str;
420: size_t length;
421: //operator char *() { return str; }
1.158 paf 422: Cm(): str(0), length(0) {}
1.145 paf 423: Cm(char *astr, size_t asize): str(astr), length(asize) {}
424: };
425:
426: private:
427:
1.152 paf 428: Body body; ///< all characters of string
1.146 paf 429: Languages langs; ///< string characters lang
430:
431: const char* v() const;
1.164 paf 432: void dump() const;
433: #define ASSERT_STRING_INVARIANT(string) \
434: assert((string).langs.invariant((string).body.length()))
1.145 paf 435:
1.8 paf 436: public:
1.151 paf 437:
438: static const String Empty;
1.8 paf 439:
1.181 misha 440: explicit String(){};
1.182 misha 441: explicit String(const char* cstr, Language alang=L_CLEAN){
1.181 misha 442: if(cstr && *cstr){
443: body=cstr;
1.182 misha 444: langs=alang;
1.181 misha 445: }
446: }
1.182 misha 447: explicit String(const String::C cstr, Language alang=L_CLEAN){
1.181 misha 448: if(cstr.length){
449: body=cstr.str;
1.182 misha 450: langs=alang;
1.181 misha 451: }
452: }
1.185 misha 453: String(int value, char *format);
1.146 paf 454: String(Body abody, Language alang): body(abody), langs(alang) {
455: ASSERT_STRING_INVARIANT(*this);
456: }
457: String(const String& src): body(src.body), langs(src.langs) {
458: ASSERT_STRING_INVARIANT(*this);
1.145 paf 459: }
460:
461: /// for convinient hash lookup
1.183 misha 462: #ifdef HASH_CODE_CACHING
463: operator const Body&() const { return body; }
464: #else
1.146 paf 465: operator const Body() const { return body; }
1.183 misha 466: #endif
1.145 paf 467:
468: bool is_empty() const { return body.is_empty(); }
469: size_t length() const { return body.length(); }
1.171 misha 470: size_t length(Charset& charset) const;
1.145 paf 471:
472: /// convert to CORD. if 'lang' known, forcing 'lang' to it
1.146 paf 473: Body cstr_to_string_body(Language lang=L_AS_IS,
1.145 paf 474: SQL_Connection* connection=0,
475: const Request_charsets *charsets=0) const;
476:
477: /// convert to constant C string. if 'lang' known, forcing 'lang' to it
478: const char* cstr(Language lang=L_AS_IS,
479: SQL_Connection* connection=0,
480: const Request_charsets *charsets=0) const {
481: return cstr_to_string_body(lang, connection, charsets).cstr();
482: }
483: /// convert to Modifiable C string. if 'lang' known, forcing 'lang' to it
484: char *cstrm(Language lang=L_AS_IS,
485: SQL_Connection* connection=0,
486: const Request_charsets *charsets=0) const {
487: return cstr_to_string_body(lang, connection, charsets).cstrm();
1.50 paf 488: }
1.108 parser 489: /// puts pieces to buf
1.145 paf 490: Cm serialize(size_t prolog_size) const;
1.108 parser 491: /// appends pieces from buf to self
1.145 paf 492: bool deserialize(size_t prolog_size, void *buf, size_t buf_size);
1.146 paf 493: /// @see Body::append_know_length
1.145 paf 494: String& append_know_length(const char* str, size_t known_length, Language lang);
1.146 paf 495: /// @see Body::append_help_length
1.145 paf 496: String& append_help_length(const char* str, size_t helper_length, Language lang);
497: String& append_strdup(const char* str, size_t helper_length, Language lang);
498:
1.146 paf 499: bool operator == (const char* y) const { return body==Body(y); }
500: bool operator != (const char* y) const { return body!=Body(y); }
1.145 paf 501:
502: /// this starts with y
503: bool starts_with(const char* y) const {
1.146 paf 504: return body.ncmp(0/*x_begin*/, Body(y), 0/*y_begin*/, strlen(y))==0;
1.145 paf 505: }
506: /// x starts with this
507: bool this_starts(const char* x) const {
1.146 paf 508: return Body(x).ncmp(0/*x_begin*/, body, 0/*y_begin*/, length())==0;
1.26 paf 509: }
510:
1.145 paf 511: String& append_to(String& dest, Language lang, bool forced) const;
512: String& append(const String& src, Language lang, bool forced=false) {
513: return src.append_to(*this, lang, forced);
514: }
515: String& operator << (const String& src) { return append(src, L_PASS_APPENDED); }
516: String& operator << (const char* src) { return append_help_length(src, 0, L_AS_IS); }
1.147 paf 517: String& operator << (const Body src);
1.100 parser 518:
1.142 paf 519: /// extracts first char of a string, if any
520: char first_char() const {
1.145 paf 521: return is_empty()?0:body.fetch(0);
1.142 paf 522: }
1.54 paf 523:
1.145 paf 524: bool operator < (const String& src) const { return body<src.body; }
525: bool operator > (const String& src) const { return body>src.body; }
526: bool operator <= (const String& src) const { return body<=src.body; }
527: bool operator >= (const String& src) const { return body>=src.body; }
528: bool operator != (const String& src) const { return body!=src.body; }
529: bool operator == (const String& src) const { return body==src.body; }
530:
1.54 paf 531: /// extracts [start, finish) piece of string
1.145 paf 532: String& mid(size_t substr_begin, size_t substr_end) const;
1.172 misha 533: String& mid(Charset& charset, size_t from, size_t to, size_t helper_length=0) const;
1.145 paf 534:
535: /**
536: ignore lang if it's L_UNSPECIFIED
537: but when specified: look for substring that lies in ONE fragment in THAT lang
538: @return position of substr in string, -1 means "not found" [const char* version]
539: */
1.146 paf 540: size_t pos(const Body substr,
1.145 paf 541: size_t this_offset=0, Language lang=L_UNSPECIFIED) const;
542: /// String version of @see pos(const char*, int, Language)
543: size_t pos(const String& substr,
544: size_t this_offset=0, Language lang=L_UNSPECIFIED) const;
545: size_t pos(char c,
546: size_t this_offset=0) const {
547: return body.pos(c, this_offset);
548: }
1.173 misha 549: size_t pos(Charset& charset,
1.171 misha 550: const String& substr,
551: size_t this_offset=0, Language lang=L_UNSPECIFIED) const;
1.55 paf 552:
1.145 paf 553: void split(ArrayString& result,
554: size_t& pos_after,
555: const char* delim,
556: Language lang=L_UNSPECIFIED, int limit=-1) const;
557: void split(ArrayString& result,
558: size_t& pos_after,
1.62 paf 559: const String& delim,
1.145 paf 560: Language lang=L_UNSPECIFIED, int limit=-1) const;
1.62 paf 561:
1.145 paf 562: typedef void (*Row_action)(Table& table, ArrayString* row,
1.136 paf 563: int prestart, int prefinish,
564: int poststart, int postfinish,
1.68 paf 565: void *info);
1.87 parser 566: /**
1.145 paf 567: @return table of found items, if any.
1.87 parser 568: table format is defined and fixed[can be used by others]:
569: @verbatim
570: prematch/match/postmatch/1/2/3/...
571: @endverbatim
572: */
1.178 misha 573: Table* match(VRegex* vregex,
1.99 parser 574: Row_action row_action, void *info,
1.168 misha 575: int& matches_count) const;
1.87 parser 576: enum Change_case_kind {
577: CC_UPPER,
578: CC_LOWER
579: };
1.145 paf 580: String& change_case(Charset& source_charset,
1.87 parser 581: Change_case_kind kind) const;
1.145 paf 582: const String& replace(const Dictionary& dict) const;
1.157 paf 583: const String& trim(Trim_kind kind=TRIM_BOTH, const char* chars=0) const;
1.155 paf 584: double as_double() const { return pa_atod(cstr(), this); }
585: int as_int() const { return pa_atoi(cstr(), this); }
1.167 misha 586: bool as_bool() const { return as_int()!=0; }
1.174 misha 587: const String& escape(Charset& source_charset) const;
1.137 paf 588:
1.7 paf 589: private: //disabled
590:
1.12 paf 591: String& operator = (const String&) { return *this; }
1.7 paf 592:
1.1 paf 593: };
1.119 paf 594:
1.146 paf 595: template<>
596: inline size_t get_length<String::Body>(String::Body body) {
597: return body.length();
598: }
599:
1.183 misha 600: #ifndef HASH_CODE_CACHING
1.145 paf 601: /// simple hash code of string. used by Hash
1.146 paf 602: inline uint hash_code(const String::Body self) {
1.184 misha 603: return self.get_hash_code();
1.119 paf 604: }
1.183 misha 605: #endif
1.147 paf 606:
607:
608: /// now that we've declared specialization we can use it
609: inline String& String::operator << (const String::Body src) {
610: langs.append(body, L_AS_IS, src.length());
611: body<<src;
612: return *this;
613: }
614:
1.1 paf 615:
616: #endif
E-mail: