--- parser3/src/main/pa_string.C 2003/04/08 12:47:31 1.172.2.21.2.37 +++ parser3/src/main/pa_string.C 2003/04/21 07:07:45 1.172.2.21.2.41 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_STRING_C="$Date: 2003/04/08 12:47:31 $"; +static const char* IDENT_STRING_C="$Date: 2003/04/21 07:07:45 $"; #include "pcre.h" @@ -42,17 +42,17 @@ void String::ArrayFragment::append_posit if(substr_begin==substr_end) return; - FILE *err=fopen("append.log", "wt"); +// FILE *err=fopen("append.log", "wt"); size_t fragment_begin=0; size_t fragment_end; for(Array_iterator i(src); ; fragment_begin=fragment_end) { const Fragment fragment=i.next(); fragment_end=fragment_begin+fragment.length; - fprintf(err, "1end=%u\n", fragment_end);fflush(err); + //fprintf(err, "1end=%u\n", fragment_end);fflush(err); // not reached fragments which may include 'substr'? - if(!(substr_begin>=fragment_begin && substr_begin<=fragment_end)) + if(!(substr_begin>=fragment_begin && substr_beginfragment_end) // are there still more? append(Fragment(fragment.lang, fragment.length)); // appending whole fragment else { // no, it was last append(Fragment(fragment.lang, substr_end-fragment_begin)); - fclose(err); + //fclose(err); return; } } @@ -77,7 +77,7 @@ void String::ArrayFragment::append_posit break; } - fclose(err); + //fclose(err); } // StringBody methods @@ -111,24 +111,23 @@ uint StringBody::hash_code() const { String::String(const char* cstr, size_t helper_length, bool tainted): body(CORD_EMPTY) { append_help_length(cstr, helper_length, tainted?L_TAINTED:L_CLEAN); } -String::String(String::C cstr, bool tainted): body(CORD_EMPTY) { - append_know_length(cstr, cstr.length, tainted?L_TAINTED:L_CLEAN); +String::String(const String::C cstr, bool tainted): body(CORD_EMPTY) { + append_know_length(cstr.str, cstr.length, tainted?L_TAINTED:L_CLEAN); } String::String(const String& src): body(src.body) { fragments.append(src.fragments); -#ifndef NDEBUG - invariant(); -#endif + ASSERT_STRING_INVARIANT(*this); } String& String::append_know_length(const char* str, size_t known_length, Language lang) { + if(!known_length || !*str) + return *this; + body.append_know_length(str, known_length); fragments+=Fragment(lang, known_length); -#ifndef NDEBUG - invariant(); -#endif + ASSERT_STRING_INVARIANT(*this); return *this; } String& String::append_help_length(const char* str, size_t helper_length, Language lang) { @@ -148,9 +147,7 @@ String& String::append_strdup(const char body.append_strdup_know_length(str, known_length); fragments+=Fragment(lang, known_length); -#ifndef NDEBUG - invariant(); -#endif + ASSERT_STRING_INVARIANT(*this); return *this; } @@ -172,10 +169,7 @@ String& String::mid(size_t substr_begin, // SAPI::log("piece of '%s' from %d to %d is '%s'", //cstr(), substr_begin, substr_end, result.cstr()); -#ifndef NDEBUG - result.invariant(); -#endif - + ASSERT_STRING_INVARIANT(result); return result; } @@ -232,9 +226,9 @@ size_t String::pos(const String& substr, } void String::split(ArrayString& result, - size_t& pos_after, - const char* delim, - Language lang, int limit) const { + size_t& pos_after, + const char* delim, + Language lang, int limit) const { size_t self_length=length(); if(size_t delim_length=strlen(delim)) { int pos_before; @@ -255,9 +249,9 @@ void String::split(ArrayString& result, } void String::split(ArrayString& result, - size_t& pos_after, - const String& delim, Language lang, - int limit) const { + size_t& pos_after, + const String& delim, Language lang, + int limit) const { if(!delim.is_empty()) { int pos_before; // while we have 'delim'... @@ -309,10 +303,10 @@ static void regex_options(const String* } Table* String::match(Charset& source_charset, - const String& regexp, - const String* options, - Row_action row_action, void *info, - bool& just_matched) const { + const String& regexp, + const String* options, + Row_action row_action, void *info, + bool& just_matched) const { if(regexp.is_empty()) throw Exception(0, 0, @@ -348,7 +342,8 @@ Table* String::match(Charset& source_cha int ovector[oveclength]; // create table - Table& table=*new Table(string_match_table_template); + Table::Action_options table_options; + Table& table=*new Table(string_match_table_template, table_options); int exec_option_bits=0; int prestart=0; @@ -488,9 +483,7 @@ const String& String::replace(const Dict result.fragments.append_positions(fragments, prematch_begin-old_cstr, current-old_cstr); } -#ifndef NDEBUG - result.invariant(); -#endif + ASSERT_STRING_INVARIANT(result); return result; } @@ -633,8 +626,6 @@ bool String::deserialize(size_t prolog_l body=StringBody(cur, buf_length); } -#ifndef NDEBUG - invariant(); -#endif + ASSERT_STRING_INVARIANT(*this); return true; }