--- parser3/src/main/pa_string.C 2008/08/18 12:01:29 1.216 +++ parser3/src/main/pa_string.C 2009/04/10 11:33:16 1.219 @@ -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/18 12:01:29 $"; +static const char * const IDENT_STRING_C="$Date: 2009/04/10 11:33:16 $"; #include "pa_string.h" #include "pa_exception.h" @@ -483,7 +483,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 +497,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,19 +541,14 @@ 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, - "regular expression execute error (%d)", + print_pcre_exec_error_text(exec_substrings), exec_substrings); } @@ -576,11 +573,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;