--- parser3/src/main/pa_string.C 2003/03/20 16:57:43 1.172.2.21.2.13 +++ parser3/src/main/pa_string.C 2003/03/21 15:00:36 1.172.2.21.2.16 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_STRING_C="$Date: 2003/03/20 16:57:43 $"; +static const char* IDENT_STRING_C="$Date: 2003/03/21 15:00:36 $"; #include "pcre.h" @@ -78,18 +78,32 @@ void String::ArrayFragment::mid(ArrayFra } */ +// StringSimple methods + + +static int CORD_batched_iter_fn_generic_hash_code(const char* s, void * client_data) { + uint& result=*static_cast(client_data); + generic_hash_code(result, s); + return 0; +}; +uint StringSimple::hash_code() const { + uint result=0; + CORD_iter5(body, 0, 0, CORD_batched_iter_fn_generic_hash_code, &result); + return result; +} + // String methods String::String(const char* cstr, size_t helper_length, bool tainted): body(CORD_EMPTY) { - append(cstr, helper_length, tainted?UL_TAINTED:UL_CLEAN); + append(cstr, helper_length, tainted?L_TAINTED:L_CLEAN); } String::String(const String& src): body(src.body), fragments(src.fragments) {} -String& String::append(const char* str, size_t helper_length, Untaint_lang lang) { +String& String::append(const char* str, size_t length, Language lang) { if(!str) return *this; - size_t use_length=helper_length?helper_length:strlen(str); + size_t use_length=length?length:strlen(str); if(!use_length) return *this; @@ -99,17 +113,6 @@ String& String::append(const char* str, return *this; } -static int CORD_batched_iter_fn_generic_hash_code(const char* s, void * client_data) { - uint& result=*static_cast(client_data); - generic_hash_code(result, s); - return 0; -}; -uint String::hash_code() const { - uint result=0; - CORD_iter5(body, 0, 0, CORD_batched_iter_fn_generic_hash_code, &result); - return result; -} - /// @todo check in doc: whether it documents NOW bad situation "abc".mid(-1, 3) =were?="ab" const String& String::mid(size_t substr_begin, size_t substr_end) const { String& result=*new String; @@ -126,13 +129,13 @@ const String& String::mid(size_t substr_ // next: their langs result.fragments.append_positions(fragments, substr_begin, substr_end); -// SAPI::log(pool(), "piece of '%s' from %d to %d is '%s'", +// SAPI::log("piece of '%s' from %d to %d is '%s'", //cstr(), substr_begin, substr_end, result.cstr()); return result; } size_t String::pos(CORD substr, - size_t this_offset, Untaint_lang lang) const { + size_t this_offset, Language lang) const { // first: letters themselves size_t substr_begin=CORD_str(body, this_offset, substr); if(substr_begin==CORD_NOT_FOUND) @@ -140,7 +143,7 @@ size_t String::pos(CORD substr, // next: check the lang when specified - if(lang==UL_UNSPECIFIED) // ignore lang? + if(lang==L_UNSPECIFIED) // ignore lang? return substr_begin; // substr must be in one fragment, and fragments' lang must = lang @@ -179,14 +182,14 @@ size_t String::pos(CORD substr, } size_t String::pos(const String& substr, - size_t this_offset, Untaint_lang lang) const { + size_t this_offset, Language lang) const { return pos(substr.body, this_offset, lang); } void String::split(ArrayString& result, size_t& pos_after, const char* delim, - Untaint_lang lang, int limit) { + Language lang, int limit) { size_t self_length=length(); if(size_t delim_length=strlen(delim)) { int pos_before; @@ -208,9 +211,9 @@ void String::split(ArrayString& result, void String::split(ArrayString& result, size_t& pos_after, - const String& delim, Untaint_lang lang, + const String& delim, Language lang, int limit) const { - if(delim) { + if(!delim.is_empty()) { int pos_before; // while we have 'delim'... for(; (pos_before=pos(delim, pos_after, lang))>=0 && limit; limit--) { @@ -247,7 +250,7 @@ static void regex_options(const String& result[0]=PCRE_EXTRA | PCRE_DOTALL | PCRE_DOLLAR_ENDONLY; result[1]=0; - if(options) + if(!options.is_empty()) for(Regex_option *o=regex_option; o->keyL; o++) if(options.pos(o->keyL)>=0 || (o->keyU && options.pos(o->keyU)>=0)) { @@ -265,7 +268,7 @@ Table* String::match(Charset& source_cha const String& options, Row_action row_action, void *info, bool& just_matched) const { - if(!regexp) + if(regexp.is_empty()) throw Exception(0, 0, "regexp is empty"); @@ -414,7 +417,7 @@ const String& String::replace(const Dict // prematch if(size_t prematch_length=current-prematch_begin) { result.body=CORD_cat_char_star(result.body, prematch_begin, prematch_length); - result.fragments.append_positions(fragments, prematch_begin-old_cstr, prematch_length); + result.fragments.append_positions(fragments, prematch_begin-old_cstr, current-old_cstr); } // match @@ -437,7 +440,7 @@ const String& String::replace(const Dict // postmatch if(size_t postmatch_length=current-prematch_begin) { result.body=CORD_cat_char_star(result.body, prematch_begin, postmatch_length); - result.fragments.append_positions(fragments, prematch_begin-old_cstr, postmatch_length); + result.fragments.append_positions(fragments, prematch_begin-old_cstr, current-old_cstr); } return result; @@ -521,7 +524,7 @@ static int CORD_batched_iter_fn_append(c String::C String::serialize(size_t prolog_length) const { size_t buf_length= prolog_length - +fragments.count()*(sizeof(Untaint_lang)+sizeof(size_t)) + +fragments.count()*(sizeof(Language)+sizeof(size_t)) +length(); C result(new(PointerFreeGC) char[buf_length], buf_length); @@ -564,11 +567,11 @@ bool String::deserialize(size_t prolog_l // 3: lang info size_t total_length=0; for(size_t f=0; f(cur); cur+=sizeof(Untaint_lang); + Language lang=*reinterpret_cast(cur); cur+=sizeof(Language); size_t fragment_length=*reinterpret_cast(cur); cur+=sizeof(size_t); fragments+=Fragment(lang, fragment_length); total_length+=fragment_length;