Annotation of parser3/src/main/pa_string.C, revision 1.172.2.21.2.7
1.45 paf 1: /** @file
1.55 paf 2: Parser: string class. @see untasize_t.C.
1.46 paf 3:
1.172.2.11 paf 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.138 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.164 paf 6: */
1.46 paf 7:
1.172.2.21.2. (paf 8:): static const char* IDENT_STRING_C="$Date: 2003/03/20 09:41:47 $";
1.4 paf 9:
1.70 paf 10: #include "pcre.h"
11:
1.12 paf 12: #include "pa_string.h"
1.22 paf 13: #include "pa_exception.h"
1.61 paf 14: #include "pa_table.h"
1.101 parser 15: #include "pa_dictionary.h"
1.132 paf 16: #include "pa_charset.h"
1.60 paf 17:
1.172.2.2 paf 18: // helpers
1.139 paf 19:
1.172.2.2 paf 20: /// String::match uses this as replace & global search table columns
1.139 paf 21:
1.172.2.4 paf 22: const int MAX_MATCH_GROUPS=100;
23:
1.172.2.14 paf 24: class String_match_table_template_columns: public ArrayString {
1.172.2.2 paf 25: public:
1.172.2.4 paf 26: String_match_table_template_columns() {
1.172.2.21.2. (paf 27:): *this+=new String("prematch");
28:): *this+=new String("match");
29:): *this+=new String("postmatch");
1.172.2.4 paf 30: for(int i=0; i<MAX_MATCH_GROUPS; i++) {
1.172.2.21.2. (paf 31:): char *cname=new(PointerFreeGC) char[3/*strlen("100")*/+1/*terminating 0*/];
32:): *this+=new String(cname, sprintf(cname, "%d", 1+i));
1.172.2.2 paf 33: }
1.172.2.21 paf 34: }
1.172.2.4 paf 35: };
36:
1.172.2.21.2. (paf 37:): Table string_match_table_template(new String_match_table_template_columns);
1.172.2.2 paf 38:
1.172.2.21.2. (paf 39:): // String::ArrayFragment methods
40:):
41:): String::ArrayFragment& String::ArrayFragment::append(const ArrayFragment& src,
42:): size_t substr_start, size_t substr_end) {
43:): if(substr_start==substr_end)
44:): return *this;
45:):
46:): size_t fragment_start=0;
47:): size_t fragment_end;
48:): for(Array_iterator<element_type> i(src); ; fragment_start=fragment_end) {
49:): const element_type& fragment=i.next();
50:): fragment_end=fragment_start+fragment.size;
51:):
52:): if(substr_start<fragment_start) // not reached fragments which may include 'substr'?
53:): continue;
54:):
55:): // found first fragment including piece of 'substr'
56:): size_t piece_end=min(substr_end, fragment_end);
57:): *this+=Fragment(fragment.lang, piece_end-substr_start);
58:):
59:): while(substr_end>fragment_end) { // are there more fragments including pieces of 'substr'?
60:): const element_type& fragment=i.next();
61:): fragment_end=fragment_start+fragment.size;
62:):
63:): if(substr_end>fragment_end) // are there still more?
64:): simple_append(Fragment(fragment.lang, fragment.size)); // appending whole fragment
65:): else { // no, it was last
66:): simple_append(Fragment(fragment.lang, substr_end-fragment_start));
67:): goto break2;
68:): }
69:): }
70:):
71:): break;
72:): }
73:): break2:
74:):
75:): return *this;
76:): }
77:): /*
78:): void String::ArrayFragment::mid(ArrayFragment& result, size_t substr_start, size_t substr_end) {
79:): }
80:): */
81:):
82:): // String methods
1.172.2.2 paf 83:
1.172.2.21.2. (paf 84:): String::String(const char* src, size_t src_size, bool tainted): body(CORD_EMPTY) {
1.41 paf 85: if(src)
1.75 paf 86: if(tainted)
87: APPEND_TAINTED(src, src_size, 0, 0);
1.41 paf 88: else
1.75 paf 89: APPEND_CLEAN(src, src_size, 0, 0);
1.1 paf 90: }
1.140 paf 91:
1.172.2.21.2. (paf 92:): String::String(const String& src): body(src.body), fragments(src.fragments) {}
1.28 paf 93:
1.13 paf 94: String& String::real_append(STRING_APPEND_PARAMS) {
1.9 paf 95: if(!src)
96: return *this;
1.26 paf 97: if(!size)
98: size=strlen(src);
99: if(!size)
1.9 paf 100: return *this;
1.122 paf 101:
1.172.2.21.2. (paf 102:): body=CORD_cat_char_star(body, src, size);
103:): fragments+=Fragment(lang, size);
1.1 paf 104:
105: return *this;
106: }
107:
1.172.2.21.2. (paf 108:): static int CORD_batched_iter_fn_generic_hash_code(const char* s, void * client_data) {
109:): uint& result=*static_cast<uint*>(client_data);
110:): generic_hash_code(result, s);
111:): return 0;
112:): };
1.16 paf 113: uint String::hash_code() const {
1.7 paf 114: uint result=0;
1.172.2.21.2. (paf 115:): CORD_iter5(body, 0, 0, CORD_batched_iter_fn_generic_hash_code, &result);
1.5 paf 116: return result;
117: }
118:
1.172.2.21.2. (paf 119:): const String& String::mid(size_t substr_start, size_t substr_end) const {
120:): String& result=*new String;
1.33 paf 121:
1.172.2.21.2. (paf 122:): substr_start=min(substr_start, size());
123:): substr_end=max(substr_start, substr_end);
124:): if(substr_start==substr_end)
125:): return result;
1.52 paf 126:
1.172.2.21.2. (paf 127:): // first: letters themselves
128:): result.body=CORD_substr(body, substr_start, substr_end-substr_start);
1.46 paf 129:
1.172.2.21.2. (paf 130:): // next: their langs
131:): result.fragments.append(fragments, substr_start, substr_end);
1.53 paf 132:
1.60 paf 133: // SAPI::log(pool(), "piece of '%s' from %d to %d is '%s'",
1.172.2.21.2. (paf 134:): //cstr(), substr_start, substr_end, result.cstr());
1.53 paf 135: return result;
1.54 paf 136: }
137:
1.172.2.21.2. (paf 138:): size_t String::pos(CORD substr,
139:): size_t this_offset, Untaint_lang lang) const {
140:): // first: letters themselves
141:): size_t substr_start=CORD_str(body, this_offset, substr);
142:): if(substr_start==CORD_NOT_FOUND)
143:): return STRING_NOT_FOUND;
144:):
145:): // next: check the lang when specified
146:):
147:): if(lang==UL_UNSPECIFIED) // ignore lang?
148:): return substr_start;
149:):
150:): // substr must be in one fragment, and fragments' lang must = lang
151:): size_t substr_end=substr_start+CORD_len(substr);
152:): size_t fragment_start=0;
153:): size_t fragment_end;
154:): for(Array_iterator<ArrayFragment::element_type> i(fragments); i.has_next(); fragment_start=fragment_end) {
155:): const Fragment& fragment=i.next();
156:): fragment_end=fragment_start+fragment.size;
157:):
158:): if(substr_start<fragment_start) // not reached fragments which may include 'result'?
159:): continue;
160:):
161:): if(substr_end>fragment_end) // end of substr OUT of current fragment?
162:): break;
163:):
164:): return fragment.lang==lang?substr_end:STRING_NOT_FOUND;
165:): }
166:):
167:): return STRING_NOT_FOUND;
1.58 paf 168: }
169:
1.172.2.21.2. (paf 170:): size_t String::pos(const String& substr,
171:): size_t this_offset, Untaint_lang lang) const {
172:): return pos(substr.body, this_offset, lang);
1.60 paf 173: }
174:
1.172.2.14 paf 175: void String::split(ArrayString& result,
1.172.2.21.2. (paf 176:): size_t& pos_after,
177:): const char* delim,
1.172.2.10 paf 178: Untaint_lang lang, int limit) {
1.125 paf 179: size_t self_size=size();
1.172.2.21.2. (paf 180:): if(size_t delim_size=strlen(delim)) {
1.60 paf 181: int pos_before;
182: // while we have 'delim'...
1.172.2.21.2. (paf 183:): for(; (pos_before=pos(delim, pos_after, lang))>=0 && limit; limit--) {
184:): result+=&mid(pos_after, pos_before);
1.60 paf 185: pos_after=pos_before+delim_size;
186: }
187: // last piece
1.124 paf 188: if(pos_after<self_size && limit) {
1.172.2.21.2. (paf 189:): result+=&mid(pos_after, self_size);
1.124 paf 190: pos_after=self_size;
1.60 paf 191: }
192: } else { // empty delim
1.172.2.21.2. (paf 193:): result+=this;
194:): pos_after+=self_size;
1.60 paf 195: }
196: }
197:
1.172.2.14 paf 198: void String::split(ArrayString& result,
1.172.2.21.2. (paf 199:): size_t& pos_after,
1.60 paf 200: const String& delim, Untaint_lang lang,
1.172.2.21.2. (paf 201:): int limit) const {
202:): if(delim) {
1.60 paf 203: int pos_before;
204: // while we have 'delim'...
205: for(; (pos_before=pos(delim, pos_after, lang))>=0 && limit; limit--) {
1.172.2.21.2. (paf 206:): result+=&mid(pos_after, pos_before);
1.60 paf 207: pos_after=pos_before+delim.size();
208: }
209: // last piece
210: if(pos_after<size() && limit) {
1.172.2.21.2. (paf 211:): result+=&mid(pos_after, size());
1.60 paf 212: pos_after=size();
213: }
214: } else { // empty delim
1.172.2.21.2. (paf 215:): result+=this;
216:): pos_after+=size();
1.60 paf 217: }
1.61 paf 218: }
219:
1.172.2.21.2. (paf 220:): static void regex_options(const String& options, int *result, bool& need_pre_post_match){
1.63 paf 221: struct Regex_option {
1.172.2.11 paf 222: const char* keyL;
223: const char* keyU;
1.63 paf 224: int clear, set;
225: int *result;
1.154 paf 226: bool *flag;
1.63 paf 227: } regex_option[]={
1.153 paf 228: {"i", "I", 0, PCRE_CASELESS, result}, // a=A
229: {"s", "S", 0, PCRE_DOTALL, result}, // \n\n$ [default]
230: {"x", "U", 0, PCRE_EXTENDED, result}, // whitespace in regex ignored
231: {"m", "M", PCRE_DOTALL, PCRE_MULTILINE, result}, // ^aaa\n$^bbb\n$
232: {"g", "G", 0, true, result+1}, // many rows
1.154 paf 233: {"'", 0, 0, 0, 0, &need_pre_post_match},
234: {0}
1.63 paf 235: };
1.171 paf 236: result[0]=PCRE_EXTRA | PCRE_DOTALL | PCRE_DOLLAR_ENDONLY;
1.63 paf 237: result[1]=0;
238:
239: if(options)
1.153 paf 240: for(Regex_option *o=regex_option; o->keyL; o++)
1.172.2.21.2. (paf 241:): if(options.pos(o->keyL)>=0
242:): || (o->keyU && options.pos(o->keyU)>=0)) {
1.154 paf 243: if(o->flag)
244: *o->flag=true;
245: else { // result
246: *o->result &= ~o->clear;
247: *o->result |= o->set;
248: }
1.63 paf 249: }
250: }
251:
1.172.2.21.2. (paf 252:): Table* String::match(Charset& source_charset,
1.172.2.4 paf 253: const String& regexp,
1.172.2.21.2. (paf 254:): const String& options,
1.172.2.4 paf 255: Row_action row_action, void *info,
1.172.2.20 paf 256: bool& just_matched) const {
1.172.2.21.2. (paf 257:): if(!regexp)
258:): throw Exception(0,
259:): 0,
1.73 paf 260: "regexp is empty");
1.154 paf 261:
1.172.2.21.2. (paf 262:): const char* pattern=regexp.cstr();
1.172.2.11 paf 263: const char* errptr;
1.62 paf 264: int erroffset;
1.172.2.21.2. (paf 265:): bool need_pre_post_match=false;
1.154 paf 266: int option_bits[2]; regex_options(options, option_bits, need_pre_post_match);
1.172.2.20 paf 267: bool global=option_bits[1]!=0;
1.172.2.21.2. (paf 268:): pcre *code=pcre_compile(pattern, option_bits[0],
1.62 paf 269: &errptr, &erroffset,
1.172.2.1 paf 270: source_charset.pcre_tables);
1.62 paf 271:
1.67 paf 272: if(!code)
1.172.2.21.2. (paf 273:): throw Exception(0,
274:): ®exp.mid(erroffset, regexp.size()),
1.74 paf 275: "regular expression syntax error - %s", errptr);
1.62 paf 276:
1.172.2.20 paf 277: int subpatterns=pcre_info(code, 0, 0);
278: if(subpatterns<0) {
1.100 parser 279: pcre_free(code);
1.149 paf 280: throw Exception(0,
1.172.2.21.2. (paf 281:): ®exp,
1.76 paf 282: "pcre_info error (%d)",
1.172.2.20 paf 283: subpatterns);
1.63 paf 284: }
285:
1.172.2.21.2. (paf 286:): const char* subject=cstr();
287:): size_t subject_size=strlen(subject);
1.172.2.4 paf 288: const int ovecsize=(1/*match*/+MAX_MATCH_GROUPS)*3;
1.155 paf 289: int ovector[ovecsize];
290:
291: // create table
1.172.2.21.2. (paf 292:): Table* table=new Table(string_match_table_template);
1.63 paf 293:
1.64 paf 294: int exec_option_bits=0;
1.154 paf 295: int prestart=0;
296: int poststart=0;
297: int postfinish=size();
1.63 paf 298: while(true) {
299: int exec_substrings=pcre_exec(code, 0,
1.172.2.21.2. (paf 300:): subject, subject_size, prestart,
1.64 paf 301: exec_option_bits, ovector, ovecsize);
1.63 paf 302:
303: if(exec_substrings==PCRE_ERROR_NOMATCH) {
1.100 parser 304: pcre_free(code);
1.172.2.21.2. (paf 305:): row_action(table, 0/*last time, no raw*/, 0, 0, poststart, postfinish, info);
1.172.2.20 paf 306: if(global || subpatterns)
307: return table; // global or with subpatterns=true+result
308: else {
1.172.2.21.2. (paf 309:): just_matched=false; return 0; // not global=no result
1.172.2.20 paf 310: }
1.63 paf 311: }
312:
313: if(exec_substrings<0) {
1.100 parser 314: pcre_free(code);
1.172.2.21.2. (paf 315:): throw Exception(0,
316:): ®exp,
1.76 paf 317: "regular expression execute error (%d)",
1.63 paf 318: exec_substrings);
319: }
320:
1.154 paf 321: int prefinish=ovector[0];
322: poststart=ovector[1];
1.172.2.21.2. (paf 323:): ArrayString* row=new ArrayString;
1.172.2.4 paf 324: if(need_pre_post_match) {
1.172.2.21.2. (paf 325:): *row+=&mid(0, prefinish); // .prematch column value
326:): *row+=&mid(prefinish, poststart); // .match
327:): *row+=&mid(poststart, postfinish); // .postmatch
1.172.2.4 paf 328: } else {
1.172.2.21.2. (paf 329:): *row+=0; // .prematch column value
330:): *row+=0; // .match
331:): *row+=0; // .postmatch
1.172.2.4 paf 332: }
1.63 paf 333:
334: for(int i=1; i<exec_substrings; i++) {
1.69 paf 335: // -1:-1 case handled peacefully by mid() itself
1.172.2.21.2. (paf 336:): *row+=&mid(ovector[i*2+0], ovector[i*2+1]); // .i column value
1.63 paf 337: }
338:
1.172.2.20 paf 339: row_action(table, row, prestart, prefinish, poststart, postfinish, info);
1.63 paf 340:
1.172.2.20 paf 341: if(!global || prestart==poststart) { // not global | going to hang
1.100 parser 342: pcre_free(code);
1.172.2.21.2. (paf 343:): row_action(table, 0/*last time, no row*/, 0, 0, poststart, postfinish, info);
1.172.2.20 paf 344: return table;
1.63 paf 345: }
1.154 paf 346: prestart=poststart;
1.63 paf 347:
348: /*
349: if(option_bits[0] & PCRE_MULTILINE)
1.64 paf 350: exec_option_bits|=PCRE_NOTBOL; // start of subject+startoffset not BOL
1.63 paf 351: */
352: }
1.82 parser 353: }
354:
1.172.2.21.2. (paf 355:): String& String::change_case(Charset& source_charset, Change_case_kind kind) {
356:): String& result=*new String();
1.172.2.4 paf 357:
1.172.2.1 paf 358: const unsigned char *tables=source_charset.pcre_tables;
1.82 parser 359:
360: const unsigned char *a;
361: const unsigned char *b;
362: switch(kind) {
363: case CC_UPPER:
364: a=tables+lcc_offset;
365: b=tables+fcc_offset;
366: break;
367: case CC_LOWER:
368: a=tables+lcc_offset;
369: b=0;
370: break;
371: default:
1.172.2.21.2. (paf 372:): throw Exception(0,
373:): this,
1.82 parser 374: "unknown change case kind #%d",
375: static_cast<int>(kind)); // never
376: a=b=0; // calm, compiler
377: break; // never
378: }
379:
1.172.2.21.2. (paf 380:): char* new_cstr=cstrm();
381:): char *dest=new_cstr;
382:): unsigned char index;
383:): for(const char* current=new_cstr; index=(unsigned char)*current; current++) {
384:): unsigned char c=a[index];
385:): if(b)
386:): c=b[c];
1.82 parser 387:
1.172.2.21.2. (paf 388:): *dest++=(char)c;
389:): }
390:): result.body=new_cstr;
391:): result.fragments.append(fragments, 0, fragments.count());
1.89 parser 392:
1.101 parser 393: return result;
394: }
395:
1.172.2.21.2. (paf 396:): const String& String::replace(const Dictionary& dict) const {
397:): String& result=*new String();
398:): const char* old_cstr=cstr();
399:): const char* prematch_start=old_cstr;
400:):
401:): for(const char* current=old_cstr; *current; ) {
402:): if(Table::element_type row=dict.first_that_starts(current)) {
403:): // prematch
404:): if(size_t prematch_size=current-prematch_start) {
405:): result.body=CORD_cat_char_star(result.body, prematch_start, prematch_size);
406:): result.fragments.append(fragments, prematch_start-old_cstr, prematch_size);
1.101 parser 407: }
408:
1.172.2.21.2. (paf 409:): // match
410:):
411:): const String* a=row->get(0);
412:): // skip 'a' in 'current'; move prematch_start
413:): current+=a->size(); prematch_start=current;
1.170 paf 414:
1.172.2.21.2. (paf 415:): if(row->count()>1) { // are there any b?
416:): const String* b=row->get(1);
417:): if(size_t b_size=b->size()) {
418:): result.body=CORD_cat(result.body, b->cstr_to_cord());
419:): result.fragments.append(b->fragments, 0, b->fragments.count());
420:): }
421:): }
422:): } else // simply advance
423:): current++;
424:): }
1.156 paf 425:
1.172.2.21.2. (paf 426:): // postmatch
427:): if(size_t prematch_size=current-prematch_start) {
428:): result.body=CORD_cat_char_star(result.body, prematch_start, prematch_size);
429:): result.fragments.append(fragments, prematch_start-old_cstr, prematch_size);
430:): }
1.156 paf 431:
1.89 parser 432: return result;
433: }
434:
1.172.2.21.2. (paf 435:): double String::as_double() const {
1.89 parser 436: double result;
1.172.2.21.2. (paf 437:): const char *str=cstr();
438:):
439:): while(*str && isspace(*str))
440:): str++;
441:): if(!*str)
1.162 paf 442: return 0;
1.161 paf 443:
1.102 parser 444: char *error_pos;
1.89 parser 445: // 0xABC
1.172.2.21.2. (paf 446:): if(str[0]=='0')
447:): if(str[1]=='x' || str[1]=='X')
448:): result=(double)(unsigned long)strtol(str, &error_pos, 0);
1.99 parser 449: else
1.172.2.21.2. (paf 450:): result=(double)strtod(str+1/*skip leading 0*/, &error_pos);
1.89 parser 451: else
1.172.2.21.2. (paf 452:): result=(double)strtod(str, &error_pos);
1.89 parser 453:
1.159 paf 454: while(char c=*error_pos++)
455: if(!isspace(c))
456: throw Exception("number.format",
1.172.2.21.2. (paf 457:): this,
1.159 paf 458: "invalid number (double)");
1.89 parser 459:
460: return result;
461: }
1.172.2.21.2. (paf 462:): int String::as_int() const {
1.89 parser 463: int result;
1.172.2.21.2. (paf 464:): const char *str=cstr();
465:):
466:): while(*str && isspace(*str))
467:): str++;
468:): if(!*str)
1.162 paf 469: return 0;
1.161 paf 470:
1.102 parser 471: char *error_pos;
1.89 parser 472: // 0xABC
1.172.2.21.2. (paf 473:): if(str[0]=='0')
474:): if(str[1]=='x' || str[1]=='X')
475:): result=(int)(unsigned long)strtol(str, &error_pos, 0);
1.99 parser 476: else
1.172.2.21.2. (paf 477:): result=(int)strtol(str+1/*skip leading 0*/, &error_pos, 0);
1.89 parser 478: else
1.172.2.21.2. (paf 479:): result=(int)strtol(str, &error_pos, 0);
1.89 parser 480:
1.159 paf 481: while(char c=*error_pos++)
482: if(!isspace(c))
483: throw Exception("number.format",
1.172.2.21.2. (paf 484:): this,
1.159 paf 485: "invalid number (int)");
1.82 parser 486:
487: return result;
1.61 paf 488: }
1.113 parser 489:
1.172.2.4 paf 490: inline void uint2uchars(uint word, uchar *bytes) {
491: bytes[0]=word&0xFF;
492: bytes[1]=(word>>8)&0xFF;
493: bytes[2]=(word>>16)&0xFF;
494: bytes[3]=(word>>24)&0xFF;
495: }
496: inline uint uchars2uint(uchar *bytes) {
497: return bytes[3]<<24
498: | bytes[2]<<16
499: | bytes[1]<<8
500: | bytes[0];
501: }
502:
1.172.2.21.2. (paf 503:): static int CORD_batched_iter_fn_append(const char* s, void* client_data) {
504:): char*& cur=*static_cast<char**>(client_data);
505:):
506:): size_t size=strlen(s);
507:): memcpy(cur, s, size); cur+=size;
508:): return 0;
509:): };
510:): String::C String::serialize(size_t prolog_size) const {
511:): size_t buf_size=
1.113 parser 512: prolog_size
1.172.2.21.2. (paf 513:): +fragments.count()*(sizeof(Untaint_lang)+sizeof(size_t))
1.113 parser 514: +size();
1.172.2.21.2. (paf 515:): C result(new(PointerFreeGC) char[buf_size], buf_size);
516:):
517:): // 1: prolog
518:): char *cur=result.str+prolog_size;
519:):
520:):
521:): // 2: fragments.count
522:): size_t fragments_count=fragments.count();
523:): memcpy(cur, &fragments_count, sizeof(fragments_count)); cur+=sizeof(fragments_count);
1.113 parser 524:
1.172.2.21.2. (paf 525:): // 3: lang info
526:): for(Array_iterator<ArrayFragment::element_type> i(fragments); i.has_next(); ) {
527:): const Fragment& fragment=i.next();
1.123 paf 528: // lang
1.172.2.21.2. (paf 529:): memcpy(cur, &fragment.lang, sizeof(fragment.lang)); cur+=sizeof(fragment.lang);
1.123 paf 530: // size
1.172.2.21.2. (paf 531:): memcpy(cur, &fragment.size, sizeof(fragment.size)); cur+=sizeof(fragment.size);
532:): }
533:):
534:): // 4: letters
535:): CORD_iter5(body, 0, 0, CORD_batched_iter_fn_append, &cur);
536:):
537:): return result;
1.113 parser 538: }
1.172.2.11 paf 539: bool String::deserialize(size_t prolog_size, void *buf, size_t buf_size, const char* file) {
1.135 paf 540: if(buf_size<=prolog_size)
1.148 paf 541: return false;
1.113 parser 542: buf_size-=prolog_size;
543:
1.172.2.21.2. (paf 544:): // 1: prolog
545:): const char* cur=(const char* )buf+prolog_size;
1.148 paf 546:
1.172.2.21.2. (paf 547:): // 2: fragments.count
548:): if(buf_size<sizeof(size_t)) // fragments.count don't fit?
549:): return false;
550:): size_t fragments_count=*reinterpret_cast<const size_t*>(cur); cur+=sizeof(size_t);
551:): buf_size-=sizeof(size_t);
1.128 paf 552:
1.172.2.21.2. (paf 553:): // 3: lang info
554:): size_t total_size=0;
555:): for(size_t f=0; f<fragments_count; f++) {
556:): size_t piece_size=sizeof(Untaint_lang)+sizeof(size_t);
557:): if(buf_size<piece_size) // lang+size
1.148 paf 558: return false;
559:
1.172.2.21.2. (paf 560:): Untaint_lang lang=*reinterpret_cast<const Untaint_lang *>(cur); cur+=sizeof(Untaint_lang);
561:): size_t fragment_size=*reinterpret_cast<const size_t*>(cur); cur+=sizeof(size_t);
562:): fragments+=Fragment(lang, fragment_size);
563:): total_size+=fragment_size;
1.113 parser 564:
565: buf_size-=piece_size;
566: }
1.172.2.21.2. (paf 567:):
568:): // 4: letters
569:): if(buf_size!=total_size)
570:): return false;
571:):
572:): body=CORD_cat_char_star(CORD_EMPTY, cur, buf_size);
573:):
1.148 paf 574: return true;
1.113 parser 575: }
E-mail: