|
|
| version 1.207, 2015/04/08 17:36:19 | version 1.211, 2015/10/08 18:29:15 |
|---|---|
| Line 22 extern "C" { // cord's author forgot to | Line 22 extern "C" { // cord's author forgot to |
| #define CORD_cat(x, y) CORD_cat_optimized(x, y) | #define CORD_cat(x, y) CORD_cat_optimized(x, y) |
| #define CORD_cat_char_star(x, y, leny) CORD_cat_char_star_optimized(x, y, leny) | #define CORD_cat_char_star(x, y, leny) CORD_cat_char_star_optimized(x, y, leny) |
| #endif | #endif |
| }; | } |
| // defines | // defines |
| Line 55 class VRegex; | Line 55 class VRegex; |
| int pa_atoi(const char* str, const String* problem_source=0); | int pa_atoi(const char* str, const String* problem_source=0); |
| double pa_atod(const char* str, const String* problem_source=0); | double pa_atod(const char* str, const String* problem_source=0); |
| unsigned int pa_atoui(const char *str, int base, const String* problem_source=0); | unsigned int pa_atoui(const char *str, int base, const String* problem_source=0); |
| unsigned long long int pa_atoul(const char *str, int base, const String* problem_source=0); | |
| /// this is result of pos functions which mean that substr were not found | /// this is result of pos functions which mean that substr were not found |
| #define STRING_NOT_FOUND ((size_t)-1) | #define STRING_NOT_FOUND ((size_t)-1) |
| /// CORD can't be empty string, thus checking it in assigment | |
| #define AS_CORD(v) ((v) && *(v) ? (CORD)(v):0) | |
| /** | /** |
| String which knows the lang of all it's langs. | String which knows the lang of all it's langs. |
| Line 185 public: | Line 189 public: |
| assert(alang); | assert(alang); |
| assert(length); | assert(length); |
| if(!opt.is_not_just_lang) | if(!opt.is_not_just_lang) { |
| if(opt.lang) { | if(opt.lang) { |
| if(opt.lang==alang) // same language? ignoring | if(opt.lang==alang) // same language? ignoring |
| return; | return; |
| Line 193 public: | Line 197 public: |
| opt.lang=alang; // to uninitialized | opt.lang=alang; // to uninitialized |
| return; | return; |
| } | } |
| } | |
| append(current, CORD_chars((char)alang, length)); | append(current, CORD_chars((char)alang, length)); |
| } | } |
| Line 201 public: | Line 206 public: |
| assert(alang); | assert(alang); |
| assert(length); | assert(length); |
| if(!opt.is_not_just_lang) | if(!opt.is_not_just_lang) { |
| if(opt.lang) { | if(opt.lang) { |
| if(opt.lang==alang) // same language? ignoring | if(opt.lang==alang) // same language? ignoring |
| return; | return; |
| Line 209 public: | Line 214 public: |
| opt.lang=alang; // to uninitialized | opt.lang=alang; // to uninitialized |
| return; | return; |
| } | } |
| } | |
| append(current, CORD_chars((char)alang, length)); | append(current, CORD_chars((char)alang, length)); |
| } | } |
| Line 216 public: | Line 222 public: |
| void appendHelper(const Body& current, Language alang, const Body &length_helper) { | void appendHelper(const Body& current, Language alang, const Body &length_helper) { |
| assert(alang); | assert(alang); |
| if(!opt.is_not_just_lang) | if(!opt.is_not_just_lang) { |
| if(opt.lang) { | if(opt.lang) { |
| if(opt.lang==alang) // same language? ignoring | if(opt.lang==alang) // same language? ignoring |
| return; | return; |
| Line 224 public: | Line 230 public: |
| opt.lang=alang; // to uninitialized | opt.lang=alang; // to uninitialized |
| return; | return; |
| } | } |
| } | |
| append(current, CORD_chars((char)alang, length_helper.length())); | append(current, CORD_chars((char)alang, length_helper.length())); |
| } | } |
| Line 332 public: | Line 339 public: |
| #ifdef HASH_CODE_CACHING | #ifdef HASH_CODE_CACHING |
| Body(): body(CORD_EMPTY), hash_code(0) INIT_LENGTH {} | Body(): body(CORD_EMPTY), hash_code(0) INIT_LENGTH {} |
| Body(CORD abody, uint ahash_code): body(abody), hash_code(ahash_code) INIT_LENGTH {} | Body(CORD abody, uint ahash_code): body(abody), hash_code(ahash_code) INIT_LENGTH {} |
| Body(CORD abody): body(abody), hash_code(0) INIT_LENGTH { | Body(const char *abody): body(AS_CORD(abody)), hash_code(0) INIT_LENGTH {} |
| explicit Body(CORD abody): body(abody), hash_code(0) INIT_LENGTH { | |
| #else | #else |
| Body(): body(CORD_EMPTY) INIT_LENGTH {} | Body(): body(CORD_EMPTY) INIT_LENGTH {} |
| Body(CORD abody): body(abody) INIT_LENGTH { | Body(const char *abody): body(AS_CORD(abody)) INIT_LENGTH {} |
| explicit Body(CORD abody): body(abody) INIT_LENGTH { | |
| #endif | #endif |
| #ifdef CORD_CAT_OPTIMIZATION | #ifdef CORD_CAT_OPTIMIZATION |
| assert(!body // no body | assert(!body // no body |
| Line 361 public: | Line 370 public: |
| bool operator! () const { return is_empty(); } | bool operator! () const { return is_empty(); } |
| CORD get_cord() const { return body; } | inline CORD get_cord() const { return body; } |
| uint get_hash_code() const; | uint get_hash_code() const; |
| const char* cstr() const { | const char* cstr() const { |
| #ifdef STRING_LENGTH_CACHING | #ifdef STRING_LENGTH_CACHING |
| string_length = length(); | string_length = length(); |
| if(string_length) | if(string_length){ |
| return const_cast<Body*>(this)->body=CORD_to_const_char_star(body, string_length); | const char *result=CORD_to_const_char_star(body, string_length); |
| const_cast<Body*>(this)->body=(CORD)result; | |
| return result; | |
| } | |
| #endif | #endif |
| return CORD_to_const_char_star(body, length()); | return CORD_to_const_char_star(body, length()); |
| } | } |
| Line 377 public: | Line 389 public: |
| #ifdef STRING_LENGTH_CACHING | #ifdef STRING_LENGTH_CACHING |
| void set_length(size_t alength){ string_length = alength; } | void set_length(size_t alength){ string_length = alength; } |
| size_t length() const { return body ? CORD_IS_STRING(body) ? string_length ? string_length : (string_length=strlen(body)) : CORD_len(body) : 0; } | size_t length() const { return body ? CORD_IS_STRING(body) ? string_length ? string_length : (string_length=strlen((const char *)body)) : CORD_len(body) : 0; } |
| #else | #else |
| size_t length() const { return CORD_len(body); } | size_t length() const { return CORD_len(body); } |
| #endif | #endif |
| Line 390 public: | Line 402 public: |
| body = CORD_cat_char_star(body, str, known_length); | body = CORD_cat_char_star(body, str, known_length); |
| ZERO_LENGTH | ZERO_LENGTH |
| } else { | } else { |
| body=str; | body=(CORD)str; |
| #ifdef STRING_LENGTH_CACHING | #ifdef STRING_LENGTH_CACHING |
| string_length=known_length; | string_length=known_length; |
| #endif | #endif |
| Line 414 public: | Line 426 public: |
| bool operator != (const Body src) const { return CORD_cmp(body, src.body)!=0; } | bool operator != (const Body src) const { return CORD_cmp(body, src.body)!=0; } |
| bool operator == (const Body src) const { return CORD_cmp(body, src.body)==0; } | bool operator == (const Body src) const { return CORD_cmp(body, src.body)==0; } |
| bool operator != (const char *src) const { return CORD_cmp(body, src)!=0; } | bool operator != (const char *src) const { return CORD_cmp(body, AS_CORD(src))!=0; } |
| bool operator == (const char *src) const { return CORD_cmp(body, src)==0; } | bool operator == (const char *src) const { return CORD_cmp(body, AS_CORD(src))==0; } |
| int ncmp(size_t x_begin, const Body y, size_t y_begin, size_t size) const { | int ncmp(size_t x_begin, const Body y, size_t y_begin, size_t size) const { |
| return CORD_ncmp(body, x_begin, y.body, y_begin, size); | return CORD_ncmp(body, x_begin, y.body, y_begin, size); |
| } | } |
| char fetch(size_t index) const { return CORD_fetch(body, index); } | char fetch(size_t index) const { return CORD_fetch(body, index); } |
| Body mid(size_t aindex, size_t alength) const { return CORD_substr(body, aindex, alength, length()); } | Body mid(size_t aindex, size_t alength) const { return Body(CORD_substr(body, aindex, alength, length())); } |
| size_t pos(const char* substr, size_t offset=0) const { return CORD_str(body, offset, substr, length()); } | size_t pos(const char* substr, size_t offset=0) const { return CORD_str(body, offset, AS_CORD(substr), length()); } |
| size_t pos(const Body substr, size_t offset=0) const { | size_t pos(const Body substr, size_t offset=0) const { |
| if(substr.is_empty()) | if(substr.is_empty()) |
| return STRING_NOT_FOUND; // in this case CORD_str returns 0 [parser users got used to -1] | return STRING_NOT_FOUND; // in this case CORD_str returns 0 [parser users got used to -1] |
| Line 462 public: | Line 474 public: |
| struct C { | struct C { |
| const char *str; | const char *str; |
| size_t length; | size_t length; |
| operator const char *() { return str; } | //operator const char *() { return str; } |
| C(): str(0), length(0) {} | C(): str(0), length(0) {} |
| C(const char *astr, size_t asize): str(astr), length(asize) {} | C(const char *astr, size_t asize): str(astr), length(asize) {} |
| }; | }; |
| Line 490 public: | Line 502 public: |
| static const String Empty; | static const String Empty; |
| explicit String(){}; | explicit String(){}; |
| explicit String(const char* cstr, Language alang=L_CLEAN){ | explicit String(const char* cstr, Language alang=L_CLEAN) : body(cstr){ |
| if(cstr && *cstr){ | if(body.get_cord()){ |
| body=cstr; | |
| langs=alang; | langs=alang; |
| } | } |
| } | } |
| explicit String(const char* cstr, Language alang, size_t alength){ | explicit String(const char* cstr, Language alang, size_t alength) : body(cstr){ |
| if(cstr && *cstr){ | if(body.get_cord()){ |
| body=cstr; | |
| #ifdef STRING_LENGTH_CACHING | #ifdef STRING_LENGTH_CACHING |
| body.set_length(alength); | body.set_length(alength); |
| #endif | #endif |
| langs=alang; | langs=alang; |
| } | } |
| } | |
| explicit String(C ac, Language alang=L_CLEAN) : body(ac.str){ | |
| if(body.get_cord()){ | |
| #ifdef STRING_LENGTH_CACHING | |
| body.set_length(ac.length); | |
| #endif | |
| langs=alang; | |
| } | |
| } | } |
| String(int value, const char *format); | String(int value, const char *format); |