--- parser3/src/main/pa_string.C 2008/08/21 15:58:12 1.217 +++ parser3/src/main/pa_string.C 2009/04/15 07:44:25 1.220 @@ -1,11 +1,11 @@ /** @file Parser: string class. @see untalength_t.C. - 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) */ -static const char * const IDENT_STRING_C="$Date: 2008/08/21 15:58:12 $"; +static const char * const IDENT_STRING_C="$Date: 2009/04/15 07:44:25 $"; #include "pa_string.h" #include "pa_exception.h" @@ -229,9 +229,13 @@ static int CORD_batched_iter_fn_generic_ }; uint String::Body::hash_code() const { uint result=0; - CORD_iter5(body, 0, - CORD_batched_iter_fn_generic_hash_code, - CORD_batched_iter_fn_generic_hash_code, &result); + if (body && CORD_IS_STRING(body)){ + generic_hash_code(result, body); + } else { + CORD_iter5(body, 0, + CORD_batched_iter_fn_generic_hash_code, + CORD_batched_iter_fn_generic_hash_code, &result); + } return result; } @@ -279,10 +283,16 @@ String& String::append_strdup(const char return *this; } +int CORD_batched_len(const char * s, size_t *len){ + (*len)+=lengthUTF8( (const XMLByte *)s, (const XMLByte *)s+strlen(s)); + return 0; +} + size_t String::length(Charset& charset) const { if(charset.isUTF8()){ - const XMLByte* srcPtr=(const XMLByte*)cstrm(); - return lengthUTF8(srcPtr, srcPtr+body.length()); + size_t len=0; + body.for_each(NULL, CORD_batched_len, &len); + return len; } else return body.length(); } @@ -483,7 +493,7 @@ Table* String::match(Charset& source_cha Row_action row_action, void *info, int& matches_count) const { if(regexp.is_empty()) - throw Exception(0, + throw Exception(PARSER_RUNTIME, 0, "regexp is empty"); @@ -497,22 +507,24 @@ Table* String::match(Charset& source_cha bool just_count_matches=(match_features & MF_JUST_COUNT_MATCHES) != 0; bool global=option_bits[1]!=0; - if(source_charset.isUTF8()) - option_bits[0]=option_bits[0] | PCRE_UTF8; + if(source_charset.isUTF8()){ + // @todo (for UTF-8): check string & pattern and use PCRE_NO_UTF8_CHECK option + option_bits[0]|=PCRE_UTF8; + } pcre *code=pcre_compile(pattern, option_bits[0], &errptr, &erroffset, source_charset.pcre_tables); if(!code) - throw Exception(0, + throw Exception(PCRE_EXCEPTION_TYPE, ®exp.mid(erroffset, regexp.length()), "regular expression syntax error - %s", errptr); int subpatterns=pcre_info(code, 0, 0); if(subpatterns<0) { pcre_free(code); - throw Exception(0, + throw Exception(PCRE_EXCEPTION_TYPE, ®exp, "pcre_info error (%d)", subpatterns); @@ -539,17 +551,12 @@ Table* String::match(Charset& source_cha if(exec_substrings==PCRE_ERROR_NOMATCH) { pcre_free(code); row_action(table, 0/*last time, no raw*/, 0, 0, poststart, postfinish, info); - // if(global || subpatterns) - // return &table; // global or with subpatterns=true+result - // else { - // just_matched=false; return 0; // not global=no result - // } return just_count_matches ? 0 : &table; } if(exec_substrings<0) { pcre_free(code); - throw Exception(0, + throw Exception(PCRE_EXCEPTION_TYPE, ®exp, print_pcre_exec_error_text(exec_substrings), exec_substrings); @@ -576,11 +583,10 @@ Table* String::match(Charset& source_cha matches_count++; row_action(table, row, prestart, prefinish, poststart, postfinish, info); - if(!global || prestart==poststart) { // not global | going to hang + if(!global || prestart==poststart) { // last step pcre_free(code); row_action(table, 0/*last time, no row*/, 0, 0, poststart, postfinish, info); return just_count_matches ? 0 : &table; - // return &table; } prestart=poststart;