Annotation of parser3/src/main/pa_string.C, revision 1.190
1.45 paf 1: /** @file
1.174 paf 2: Parser: string class. @see untalength_t.C.
1.46 paf 3:
1.174 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.190 ! paf 8: static const char * const IDENT_STRING_C="$Date: 2003/11/20 17:40:06 $";
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.185 paf 18: const String String::Empty;
19:
1.176 paf 20: // cord lib extension
21:
22: #ifndef DOXYGEN
23: typedef struct {
24: ssize_t countdown;
25: char target; /* Character we're looking for */
26: } chr_data;
27: #endif
28: static int CORD_range_contains_chr_greater_then_proc(char c, size_t size, void* client_data)
29: {
30: register chr_data * d = (chr_data *)client_data;
31:
32: if (d -> countdown<=0) return(2);
33: d -> countdown -= size;
34: if (c > d -> target) return(1);
35: return(0);
36: }
37: int CORD_range_contains_chr_greater_then(CORD x, size_t i, size_t n, int c)
38: {
39: chr_data d;
40:
41: d.countdown = n;
42: d.target = c;
43: return(CORD_block_iter(x, i, CORD_range_contains_chr_greater_then_proc, &d) == 1/*alternatives: 0 normally ended, 2=struck 'n'*/);
44: }
45:
1.187 paf 46: static int CORD_block_count_proc(char /*c*/, size_t /*size*/, void* client_data)
1.178 paf 47: {
48: int* result=(int*)client_data;
49: (*result)++;
50: return(0); // 0=continue
51: }
52: size_t CORD_block_count(CORD x)
53: {
54: size_t result=0;
55: CORD_block_iter(x, 0, CORD_block_count_proc, &result);
56: return result;
57: }
58:
1.174 paf 59: // helpers
1.139 paf 60:
1.174 paf 61: /// String::match uses this as replace & global search table columns
1.139 paf 62:
1.174 paf 63: const int MAX_MATCH_GROUPS=100;
1.139 paf 64:
1.174 paf 65: class String_match_table_template_columns: public ArrayString {
66: public:
67: String_match_table_template_columns() {
68: *this+=new String("prematch");
69: *this+=new String("match");
70: *this+=new String("postmatch");
71: for(int i=0; i<MAX_MATCH_GROUPS; i++) {
1.176 paf 72: *this+=new String(String::Body::Format(1+i), String::L_CLEAN);
1.174 paf 73: }
74: }
75: };
76:
77: Table string_match_table_template(new String_match_table_template_columns);
78:
1.176 paf 79: // String::Body methods
1.140 paf 80:
1.176 paf 81: String::Body String::Body::Format(int value) {
1.174 paf 82: char local[MAX_NUMBER];
83: size_t length=snprintf(local, MAX_NUMBER, "%d", value);
1.176 paf 84: return String::Body(pa_strdup(local, length), length);
1.120 paf 85: }
86:
1.174 paf 87: static int CORD_batched_iter_fn_generic_hash_code(char c, void * client_data) {
88: uint& result=*static_cast<uint*>(client_data);
89: generic_hash_code(result, c);
90: return 0;
91: }
92: static int CORD_batched_iter_fn_generic_hash_code(const char* s, void * client_data) {
93: uint& result=*static_cast<uint*>(client_data);
94: generic_hash_code(result, s);
95: return 0;
96: };
1.176 paf 97: uint String::Body::hash_code() const {
1.174 paf 98: uint result=0;
99: CORD_iter5(body, 0,
100: CORD_batched_iter_fn_generic_hash_code,
101: CORD_batched_iter_fn_generic_hash_code, &result);
1.120 paf 102: return result;
1.94 parser 103: }
104:
1.174 paf 105: // String methods
106:
107: String::String(const char* cstr, size_t helper_length, bool tainted): body(CORD_EMPTY) {
108: append_help_length(cstr, helper_length, tainted?L_TAINTED:L_CLEAN);
1.115 paf 109: }
1.174 paf 110: String::String(const String::C cstr, bool tainted): body(CORD_EMPTY) {
111: append_know_length(cstr.str, cstr.length, tainted?L_TAINTED:L_CLEAN);
1.5 paf 112: }
1.28 paf 113:
1.174 paf 114: String& String::append_know_length(const char* str, size_t known_length, Language lang) {
115: if(!known_length)
1.9 paf 116: return *this;
1.122 paf 117:
1.176 paf 118: // first: langs
119: langs.append(body, lang, known_length);
120: // next: letters themselves
1.174 paf 121: body.append_know_length(str, known_length);
1.1 paf 122:
1.174 paf 123: ASSERT_STRING_INVARIANT(*this);
1.1 paf 124: return *this;
125: }
1.174 paf 126: String& String::append_help_length(const char* str, size_t helper_length, Language lang) {
127: if(!str)
128: return *this;
129: size_t known_length=helper_length?helper_length:strlen(str);
130: if(!known_length)
131: return *this;
1.1 paf 132:
1.174 paf 133: return append_know_length(str, known_length, lang);
1.5 paf 134: }
1.174 paf 135: String& String::append_strdup(const char* str, size_t helper_length, Language lang) {
136: size_t known_length=helper_length?helper_length:strlen(str);
137: if(!known_length)
138: return *this;
1.5 paf 139:
1.176 paf 140: // first: langs
141: langs.append(body, lang, known_length);
142: // next: letters themselves
1.174 paf 143: body.append_strdup_know_length(str, known_length);
1.33 paf 144:
1.174 paf 145: ASSERT_STRING_INVARIANT(*this);
146: return *this;
1.5 paf 147: }
1.46 paf 148:
1.174 paf 149: /// @todo check in doc: whether it documents NOW bad situation "abc".mid(-1, 3) =were?="ab"
150: String& String::mid(size_t substr_begin, size_t substr_end) const {
151: String& result=*new String;
152:
153: size_t self_length=length();
154: substr_begin=min(substr_begin, self_length);
155: substr_end=min(max(substr_end, substr_begin), self_length);
1.176 paf 156: size_t substr_length=substr_end-substr_begin;
157: if(!substr_length)
1.107 parser 158: return result;
1.53 paf 159:
1.176 paf 160: // first: their langs
161: result.langs.append(result.body, langs, substr_begin, substr_length);
162: // next: letters themselves
163: result.body=body.mid(substr_begin, substr_length);
1.174 paf 164:
165: // SAPI::log("piece of '%s' from %d to %d is '%s'",
166: //cstr(), substr_begin, substr_end, result.cstr());
167: ASSERT_STRING_INVARIANT(result);
1.53 paf 168: return result;
1.54 paf 169: }
170:
1.176 paf 171: size_t String::pos(const String::Body substr, size_t this_offset, Language lang) const {
1.183 paf 172: size_t substr_length=substr.length();
173: while(true) {
174: size_t substr_begin=body.pos(substr, this_offset);
175:
176: if(substr_begin==CORD_NOT_FOUND)
177: return STRING_NOT_FOUND;
1.174 paf 178:
1.183 paf 179: if(langs.check_lang(lang, substr_begin, substr_length))
180: return substr_begin;
181:
182: this_offset=substr_begin+substr_length;
183: }
1.58 paf 184: }
185:
1.174 paf 186: size_t String::pos(const String& substr,
187: size_t this_offset, Language lang) const {
188: return pos(substr.body, this_offset, lang);
1.60 paf 189: }
190:
1.174 paf 191: void String::split(ArrayString& result,
192: size_t& pos_after,
193: const char* delim,
194: Language lang, int limit) const {
195: size_t self_length=length();
196: if(size_t delim_length=strlen(delim)) {
1.186 paf 197: size_t pos_before;
1.60 paf 198: // while we have 'delim'...
1.174 paf 199: for(; (pos_before=pos(delim, pos_after, lang))!=STRING_NOT_FOUND && limit; limit--) {
1.69 paf 200: result+=&mid(pos_after, pos_before);
1.174 paf 201: pos_after=pos_before+delim_length;
1.60 paf 202: }
203: // last piece
1.174 paf 204: if(pos_after<self_length && limit) {
205: result+=&mid(pos_after, self_length);
206: pos_after=self_length;
1.60 paf 207: }
208: } else { // empty delim
209: result+=this;
1.174 paf 210: pos_after+=self_length;
1.60 paf 211: }
212: }
213:
1.174 paf 214: void String::split(ArrayString& result,
215: size_t& pos_after,
216: const String& delim, Language lang,
217: int limit) const {
1.140 paf 218: if(!delim.is_empty()) {
1.186 paf 219: size_t pos_before;
1.60 paf 220: // while we have 'delim'...
1.174 paf 221: for(; (pos_before=pos(delim, pos_after, lang))!=STRING_NOT_FOUND && limit; limit--) {
1.69 paf 222: result+=&mid(pos_after, pos_before);
1.174 paf 223: pos_after=pos_before+delim.length();
1.60 paf 224: }
225: // last piece
1.174 paf 226: if(pos_after<length() && limit) {
227: result+=&mid(pos_after, length());
228: pos_after=length();
1.60 paf 229: }
230: } else { // empty delim
231: result+=this;
1.174 paf 232: pos_after+=length();
1.60 paf 233: }
1.61 paf 234: }
235:
1.174 paf 236: static void regex_options(const String* options, int *result, bool& need_pre_post_match){
1.63 paf 237: struct Regex_option {
1.174 paf 238: const char* keyL;
239: const char* keyU;
1.63 paf 240: int clear, set;
241: int *result;
1.154 paf 242: bool *flag;
1.63 paf 243: } regex_option[]={
1.189 paf 244: {"i", "I", 0, PCRE_CASELESS, result, 0}, // a=A
245: {"s", "S", 0, PCRE_DOTALL, result, 0}, // \n\n$ [default]
246: {"x", "U", 0, PCRE_EXTENDED, result, 0}, // whitespace in regex ignored
247: {"m", "M", PCRE_DOTALL, PCRE_MULTILINE, result, 0}, // ^aaa\n$^bbb\n$
248: {"g", "G", 0, 1, result+1, 0}, // many rows
1.154 paf 249: {"'", 0, 0, 0, 0, &need_pre_post_match},
1.189 paf 250: {0, 0, 0, 0, 0, 0}
1.63 paf 251: };
1.171 paf 252: result[0]=PCRE_EXTRA | PCRE_DOTALL | PCRE_DOLLAR_ENDONLY;
1.63 paf 253: result[1]=0;
254:
1.174 paf 255: if(options && !options->is_empty())
1.153 paf 256: for(Regex_option *o=regex_option; o->keyL; o++)
1.174 paf 257: if(options->pos(o->keyL)!=STRING_NOT_FOUND
258: || (o->keyU && options->pos(o->keyU)!=STRING_NOT_FOUND)) {
1.154 paf 259: if(o->flag)
260: *o->flag=true;
261: else { // result
262: *o->result &= ~o->clear;
263: *o->result |= o->set;
264: }
1.63 paf 265: }
266: }
267:
1.174 paf 268: Table* String::match(Charset& source_charset,
269: const String& regexp,
270: const String* options,
271: Row_action row_action, void *info,
272: bool& just_matched) const {
1.140 paf 273: if(regexp.is_empty())
1.149 paf 274: throw Exception(0,
1.174 paf 275: 0,
1.73 paf 276: "regexp is empty");
1.154 paf 277:
1.174 paf 278: const char* pattern=regexp.cstr();
279: const char* errptr;
1.62 paf 280: int erroffset;
1.173 paf 281: bool need_pre_post_match=false;
1.174 paf 282: int option_bits[2]={0}; regex_options(options, option_bits, need_pre_post_match);
283: bool global=option_bits[1]!=0;
1.63 paf 284: pcre *code=pcre_compile(pattern, option_bits[0],
1.62 paf 285: &errptr, &erroffset,
1.174 paf 286: source_charset.pcre_tables);
1.62 paf 287:
1.67 paf 288: if(!code)
1.149 paf 289: throw Exception(0,
1.174 paf 290: ®exp.mid(erroffset, regexp.length()),
1.74 paf 291: "regular expression syntax error - %s", errptr);
1.62 paf 292:
1.174 paf 293: int subpatterns=pcre_info(code, 0, 0);
294: if(subpatterns<0) {
1.100 parser 295: pcre_free(code);
1.149 paf 296: throw Exception(0,
1.174 paf 297: ®exp,
1.76 paf 298: "pcre_info error (%d)",
1.174 paf 299: subpatterns);
1.63 paf 300: }
301:
1.174 paf 302: const char* subject=cstr();
303: size_t subject_length=strlen(subject);
304: const int oveclength=(1/*match*/+MAX_MATCH_GROUPS)*3;
305: int ovector[oveclength];
1.155 paf 306:
307: // create table
1.173 paf 308: Table::Action_options table_options;
1.174 paf 309: Table& table=*new Table(string_match_table_template, table_options);
1.63 paf 310:
1.64 paf 311: int exec_option_bits=0;
1.154 paf 312: int prestart=0;
313: int poststart=0;
1.174 paf 314: int postfinish=length();
1.63 paf 315: while(true) {
316: int exec_substrings=pcre_exec(code, 0,
1.174 paf 317: subject, subject_length, prestart,
318: exec_option_bits, ovector, oveclength);
1.63 paf 319:
320: if(exec_substrings==PCRE_ERROR_NOMATCH) {
1.100 parser 321: pcre_free(code);
1.174 paf 322: row_action(table, 0/*last time, no raw*/, 0, 0, poststart, postfinish, info);
323: if(global || subpatterns)
324: return &table; // global or with subpatterns=true+result
325: else {
326: just_matched=false; return 0; // not global=no result
327: }
1.63 paf 328: }
329:
330: if(exec_substrings<0) {
1.100 parser 331: pcre_free(code);
1.149 paf 332: throw Exception(0,
1.174 paf 333: ®exp,
1.76 paf 334: "regular expression execute error (%d)",
1.63 paf 335: exec_substrings);
336: }
337:
1.154 paf 338: int prefinish=ovector[0];
339: poststart=ovector[1];
1.174 paf 340: ArrayString* row=new ArrayString;
341: if(need_pre_post_match) {
342: *row+=&mid(0, prefinish); // .prematch column value
343: *row+=&mid(prefinish, poststart); // .match
344: *row+=&mid(poststart, postfinish); // .postmatch
345: } else {
1.185 paf 346: *row+=&Empty; // .prematch column value
347: *row+=&Empty; // .match
348: *row+=&Empty; // .postmatch
1.174 paf 349: }
1.63 paf 350:
351: for(int i=1; i<exec_substrings; i++) {
1.69 paf 352: // -1:-1 case handled peacefully by mid() itself
1.174 paf 353: *row+=&mid(ovector[i*2+0], ovector[i*2+1]); // .i column value
1.63 paf 354: }
355:
1.174 paf 356: row_action(table, row, prestart, prefinish, poststart, postfinish, info);
1.63 paf 357:
1.174 paf 358: if(!global || prestart==poststart) { // not global | going to hang
1.100 parser 359: pcre_free(code);
1.174 paf 360: row_action(table, 0/*last time, no row*/, 0, 0, poststart, postfinish, info);
361: return &table;
1.63 paf 362: }
1.154 paf 363: prestart=poststart;
1.63 paf 364:
365: /*
366: if(option_bits[0] & PCRE_MULTILINE)
1.64 paf 367: exec_option_bits|=PCRE_NOTBOL; // start of subject+startoffset not BOL
1.63 paf 368: */
369: }
1.82 parser 370: }
371:
1.174 paf 372: String& String::change_case(Charset& source_charset, Change_case_kind kind) const {
373: String& result=*new String();
374: if(is_empty())
375: return result;
376:
377: char* new_cstr=cstrm();
378: char *dest=new_cstr;
1.181 paf 379: if(source_charset.isUTF8()) {
380: switch(kind) {
381: case CC_UPPER:
382: change_case_UTF8((const XMLByte*)new_cstr, (XMLByte*)new_cstr, UTF8CaseToUpper);
383: break;
384: case CC_LOWER:
385: change_case_UTF8((const XMLByte*)new_cstr, (XMLByte*)new_cstr, UTF8CaseToLower);
386: break;
387: default:
388: assert(!"unknown change case kind");
389: break; // never
390: }
391:
392: } else {
393: const unsigned char *tables=source_charset.pcre_tables;
1.82 parser 394:
1.181 paf 395: const unsigned char *a;
396: const unsigned char *b;
397: switch(kind) {
398: case CC_UPPER:
399: a=tables+lcc_offset;
400: b=tables+fcc_offset;
401: break;
402: case CC_LOWER:
403: a=tables+lcc_offset;
404: b=0;
405: break;
406: default:
407: assert(!"unknown change case kind");
408: a=b=0; // calm, compiler
409: break; // never
410: }
411:
412: unsigned char index;
1.190 ! paf 413: for(const char* current=new_cstr; (index=(unsigned char)*current); current++) {
1.181 paf 414: unsigned char c=a[index];
415: if(b)
416: c=b[c];
417:
418: *dest++=(char)c;
419: }
1.174 paf 420: }
1.176 paf 421: result.langs=langs;
1.174 paf 422: result.body=new_cstr;
1.89 parser 423:
1.101 parser 424: return result;
425: }
426:
1.174 paf 427: const String& String::replace(const Dictionary& dict) const {
428: String& result=*new String();
429: const char* old_cstr=cstr();
430: const char* prematch_begin=old_cstr;
431:
432: const char* current=old_cstr;
433: while(*current) {
1.184 paf 434: if(Dictionary::Subst subst=dict.first_that_begins(current)) {
1.174 paf 435: // prematch
436: if(size_t prematch_length=current-prematch_begin) {
1.179 paf 437: result.langs.append(result.body, langs, prematch_begin-old_cstr, prematch_length);
1.174 paf 438: result.body.append_strdup_know_length(prematch_begin, prematch_length);
1.101 parser 439: }
440:
1.174 paf 441: // match
442: // skip 'a' in 'current'; move prematch_begin
1.184 paf 443: current+=subst.from_length; prematch_begin=current;
1.174 paf 444:
1.184 paf 445: if(const String* b=subst.to) // are there any b?
1.174 paf 446: result<<*b;
447: } else // simply advance
448: current++;
449: }
1.156 paf 450:
1.174 paf 451: // postmatch
452: if(size_t postmatch_length=current-prematch_begin) {
1.179 paf 453: result.langs.append(result.body, langs, prematch_begin-old_cstr, postmatch_length);
1.174 paf 454: result.body.append_strdup_know_length(prematch_begin, postmatch_length);
455: }
1.156 paf 456:
1.174 paf 457: ASSERT_STRING_INVARIANT(result);
1.89 parser 458: return result;
459: }
460:
1.90 parser 461: double String::as_double() const {
1.89 parser 462: double result;
1.174 paf 463: const char *str=cstr();
464:
465: while(*str && isspace(*str))
466: str++;
467: if(!*str)
1.162 paf 468: return 0;
1.161 paf 469:
1.102 parser 470: char *error_pos;
1.89 parser 471: // 0xABC
1.174 paf 472: if(str[0]=='0')
473: if(str[1]=='x' || str[1]=='X')
474: result=(double)(unsigned long)strtol(str, &error_pos, 0);
1.99 parser 475: else
1.174 paf 476: result=(double)strtod(str+1/*skip leading 0*/, &error_pos);
1.89 parser 477: else
1.174 paf 478: result=(double)strtod(str, &error_pos);
1.89 parser 479:
1.159 paf 480: while(char c=*error_pos++)
481: if(!isspace(c))
482: throw Exception("number.format",
483: this,
484: "invalid number (double)");
1.89 parser 485:
486: return result;
487: }
1.90 parser 488: int String::as_int() const {
1.89 parser 489: int result;
1.174 paf 490: const char *str=cstr();
491:
492: while(*str && isspace(*str))
493: str++;
494: if(!*str)
1.162 paf 495: return 0;
1.161 paf 496:
1.102 parser 497: char *error_pos;
1.89 parser 498: // 0xABC
1.174 paf 499: if(str[0]=='0')
500: if(str[1]=='x' || str[1]=='X')
501: result=(int)(unsigned long)strtol(str, &error_pos, 0);
1.99 parser 502: else
1.174 paf 503: result=(int)strtol(str+1/*skip leading 0*/, &error_pos, 0);
1.89 parser 504: else
1.174 paf 505: result=(int)strtol(str, &error_pos, 0);
1.89 parser 506:
1.159 paf 507: while(char c=*error_pos++)
508: if(!isspace(c))
509: throw Exception("number.format",
510: this,
511: "invalid number (int)");
1.82 parser 512:
513: return result;
1.61 paf 514: }
1.113 parser 515:
1.180 paf 516: static int serialize_body_char(char c, char** cur) {
517: *((*cur)++)=c;
518: return 0; // 0=continue
519: };
1.174 paf 520: static int serialize_body_piece(const char* s, char** cur) {
521: size_t length=strlen(s);
522: memcpy(*cur, s, length); *cur+=length;
1.178 paf 523: return 0; // 0=continue
1.174 paf 524: };
1.178 paf 525: static int serialize_lang_piece(char alang, size_t asize, char** cur) {
526: // lang
527: memcpy(*cur, &alang, sizeof(alang)); *cur+=sizeof(alang);
528: // length
529: memcpy(*cur, &asize, sizeof(asize)); *cur+=sizeof(asize);
530:
531: return 0; // 0=continue
532: }
1.174 paf 533: String::Cm String::serialize(size_t prolog_length) const {
1.178 paf 534: size_t fragments_count=langs.count();
1.174 paf 535: size_t buf_length=
1.178 paf 536: prolog_length //1
537: +sizeof(size_t) //2
538: +fragments_count*(sizeof(char)+sizeof(size_t)) //3
539: +body.length() //4
540: +1; // for zero terminator used in deserialize
1.174 paf 541: String::Cm result(new(PointerFreeGC) char[buf_length], buf_length);
542:
543: // 1: prolog
544: char *cur=result.str+prolog_length;
1.176 paf 545: // 2: langs.count
1.174 paf 546: memcpy(cur, &fragments_count, sizeof(fragments_count)); cur+=sizeof(fragments_count);
547: // 3: lang info
1.178 paf 548: langs.for_each(body, serialize_lang_piece, &cur);
1.174 paf 549: // 4: letters
1.180 paf 550: body.for_each(serialize_body_char, serialize_body_piece, &cur);
1.182 paf 551: // 5: zero terminator
552: *cur=0;
1.113 parser 553:
1.174 paf 554: return result;
1.113 parser 555: }
1.174 paf 556: bool String::deserialize(size_t prolog_length, void *buf, size_t buf_length) {
557: if(buf_length<=prolog_length)
1.148 paf 558: return false;
1.174 paf 559: buf_length-=prolog_length;
1.178 paf 560: buf_length-=1; // 5: zero terminator
1.135 paf 561:
1.174 paf 562: // 1: prolog
563: const char* cur=(const char* )buf+prolog_length;
1.113 parser 564:
1.176 paf 565: // 2: langs.count
566: if(buf_length<sizeof(size_t)) // langs.count don't fit?
1.174 paf 567: return false;
568: size_t fragments_count=*reinterpret_cast<const size_t*>(cur); cur+=sizeof(size_t);
569: buf_length-=sizeof(size_t);
570:
571: if(fragments_count) {
572: // 3: lang info
573: size_t total_length=0;
574: for(size_t f=0; f<fragments_count; f++) {
1.178 paf 575: size_t piece_length=sizeof(char)+sizeof(size_t);
1.174 paf 576: if(buf_length<piece_length) // lang+length
577: return false;
578:
1.178 paf 579: Language lang=*reinterpret_cast<const Language *>(cur); cur+=sizeof(char);
1.174 paf 580: size_t fragment_length=*reinterpret_cast<const size_t*>(cur); cur+=sizeof(size_t);
1.178 paf 581: langs.append(total_length, lang, fragment_length);
1.174 paf 582: total_length+=fragment_length;
1.148 paf 583:
1.174 paf 584: buf_length-=piece_length;
585: }
1.128 paf 586:
1.174 paf 587: // 4: letters
588: if(buf_length!=total_length)
1.148 paf 589: return false;
590:
1.178 paf 591: // serialize wrote extra zero byte there, we can rely on that
1.176 paf 592: body=String::Body(cur, buf_length);
1.174 paf 593: }
1.113 parser 594:
1.174 paf 595: ASSERT_STRING_INVARIANT(*this);
1.148 paf 596: return true;
1.176 paf 597: }
598:
599: const char* String::Body::v() const {
600: return CORD_to_const_char_star(body);
601: }
602: const char* String::Languages::v() const {
1.177 paf 603: if(opt.is_not_just_lang)
1.176 paf 604: return CORD_to_const_char_star(langs);
605: else
606: return (const char*)&langs;
607: }
608: const char* String::v() const {
609: #define LIMIT_VIEW 20
610: char* buf=(char*)malloc(MAX_STRING);
611: const char*body_view=body.v();
612: const char*langs_view=langs.v();
613: snprintf(buf, MAX_STRING,
1.178 paf 614: "%d:%.*s%s} "
1.176 paf 615: "{%d:%s",
1.178 paf 616: langs.count(), LIMIT_VIEW, langs_view, strlen(langs_view)>LIMIT_VIEW?"...":"",
1.176 paf 617: strlen(body_view), body_view
618: );
619:
620: return buf;
621: #undef LIMIT_VIEW
1.113 parser 622: }
E-mail: