--- parser3/src/include/pa_string.h 2009/04/15 07:47:36 1.176 +++ parser3/src/include/pa_string.h 2009/05/13 07:35:52 1.181 @@ -1,14 +1,14 @@ /** @file Parser: string class decl. - Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_STRING_H #define PA_STRING_H -static const char * const IDENT_STRING_H="$Date: 2009/04/15 07:47:36 $"; +static const char * const IDENT_STRING_H="$Date: 2009/05/13 07:35:52 $"; // includes #include "pa_types.h" @@ -36,6 +36,7 @@ class Dictionary; class Request_charsets; class String; typedef Array ArrayString; +class VRegex; // generally useful @@ -116,9 +117,9 @@ public: struct { #ifdef PA_LITTLE_ENDIAN Language lang:8; - int is_not_just_lang:sizeof(CORD)*8-8; + size_t is_not_just_lang:sizeof(CORD)*8-8; #elif defined(PA_BIG_ENDIAN) - int is_not_just_lang:sizeof(CORD)*8-8; + size_t is_not_just_lang:sizeof(CORD)*8-8; Language lang:8; #else # error word endianness not determined for some obscure reason @@ -175,7 +176,7 @@ public: if(!opt.is_not_just_lang) if(opt.lang) { - if(opt.lang==alang) // same length? ignoring + if(opt.lang==alang) // same language? ignoring return; } else { opt.lang=alang; // to uninitialized @@ -201,21 +202,6 @@ public: append(current, CORD_chars((char)alang, asize_helper.length())); } - - /// MUST be called exactly prior to modification of current [uses it's length] - template - void append(C current, size_t appending_length, const Languages src) { - assert(appending_length); - - if(!langs) - langs=src.langs; // to uninitialized - else if(!src.opt.is_not_just_lang) - append(current, src.opt.lang, appending_length); // simplifying when simple source - else - append(current, src.make_langs(appending_length)); - } - - template void appendHelper(C current, C length_helper, const Languages src) { @@ -304,10 +290,7 @@ public: || body[1]==6 // SUBSTR_HDR ); } - /// WARNING: length is only HELPER length, str in ANY case should be zero-terminated - Body(const char* str, size_t helper_length): body(CORD_EMPTY) { - append_know_length(str, helper_length?helper_length:strlen(str)); - } + static Body Format(int value); void clear() { body=CORD_EMPTY; } @@ -351,7 +334,7 @@ public: Body mid(size_t index, size_t length) const { return CORD_substr(body, index, length); } size_t pos(const char* substr, size_t offset=0) const { return CORD_str(body, offset, substr); } size_t pos(const Body substr, size_t offset=0) const { - if(!substr.length()) + if(substr.is_empty()) return STRING_NOT_FOUND; // in this case CORD_str returns 0 [parser users got used to -1] // CORD_str checks for bad offset [CORD_chr does not] @@ -419,8 +402,19 @@ public: static const String Empty; - explicit String(const char* cstr=0, size_t helper_length=0, bool tainted=false); - explicit String(const C cstr, bool tainted=false); + explicit String(){}; + explicit String(const char* cstr, bool tainted=false){ + if(cstr && *cstr){ + body=cstr; + langs=tainted ? L_TAINTED:L_CLEAN; + } + } + explicit String(const String::C cstr, bool tainted=false){ + if(cstr.length){ + body=cstr.str; + langs=tainted ? L_TAINTED:L_CLEAN; + } + } String(Body abody, Language alang): body(abody), langs(alang) { ASSERT_STRING_INVARIANT(*this); } @@ -536,9 +530,7 @@ public: prematch/match/postmatch/1/2/3/... @endverbatim */ - Table* match(Charset& source_charset, - const String& regexp, - const String* options, + Table* match(VRegex* vregex, Row_action row_action, void *info, int& matches_count) const; enum Change_case_kind {