--- parser3/src/main/pa_string.C 2008/09/03 15:15:47 1.218 +++ 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/09/03 15:15:47 $"; +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(); } @@ -497,8 +507,10 @@ 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, @@ -539,11 +551,6 @@ 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; } @@ -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;