--- parser3/src/main/pa_string.C 2003/10/21 05:11:00 1.185 +++ parser3/src/main/pa_string.C 2003/12/10 14:17:45 1.192 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_STRING_C="$Date: 2003/10/21 05:11:00 $"; +static const char * const IDENT_STRING_C="$Date: 2003/12/10 14:17:45 $"; #include "pcre.h" @@ -43,7 +43,7 @@ int CORD_range_contains_chr_greater_then return(CORD_block_iter(x, i, CORD_range_contains_chr_greater_then_proc, &d) == 1/*alternatives: 0 normally ended, 2=struck 'n'*/); } -static int CORD_block_count_proc(char c, size_t size, void* client_data) +static int CORD_block_count_proc(char /*c*/, size_t /*size*/, void* client_data) { int* result=(int*)client_data; (*result)++; @@ -194,7 +194,7 @@ void String::split(ArrayString& result, Language lang, int limit) const { size_t self_length=length(); if(size_t delim_length=strlen(delim)) { - int pos_before; + size_t pos_before; // while we have 'delim'... for(; (pos_before=pos(delim, pos_after, lang))!=STRING_NOT_FOUND && limit; limit--) { result+=&mid(pos_after, pos_before); @@ -216,7 +216,7 @@ void String::split(ArrayString& result, const String& delim, Language lang, int limit) const { if(!delim.is_empty()) { - int pos_before; + size_t pos_before; // while we have 'delim'... for(; (pos_before=pos(delim, pos_after, lang))!=STRING_NOT_FOUND && limit; limit--) { result+=&mid(pos_after, pos_before); @@ -241,13 +241,13 @@ static void regex_options(const String* int *result; bool *flag; } regex_option[]={ - {"i", "I", 0, PCRE_CASELESS, result}, // a=A - {"s", "S", 0, PCRE_DOTALL, result}, // \n\n$ [default] - {"x", "U", 0, PCRE_EXTENDED, result}, // whitespace in regex ignored - {"m", "M", PCRE_DOTALL, PCRE_MULTILINE, result}, // ^aaa\n$^bbb\n$ - {"g", "G", 0, true, result+1}, // many rows + {"i", "I", 0, PCRE_CASELESS, result, 0}, // a=A + {"s", "S", 0, PCRE_DOTALL, result, 0}, // \n\n$ [default] + {"x", "U", 0, PCRE_EXTENDED, result, 0}, // whitespace in regex ignored + {"m", "M", PCRE_DOTALL, PCRE_MULTILINE, result, 0}, // ^aaa\n$^bbb\n$ + {"g", "G", 0, 1, result+1, 0}, // many rows {"'", 0, 0, 0, 0, &need_pre_post_match}, - {0} + {0, 0, 0, 0, 0, 0} }; result[0]=PCRE_EXTRA | PCRE_DOTALL | PCRE_DOLLAR_ENDONLY; result[1]=0; @@ -375,14 +375,14 @@ String& String::change_case(Charset& sou return result; char* new_cstr=cstrm(); - char *dest=new_cstr; + size_t new_cstr_len=length(); if(source_charset.isUTF8()) { switch(kind) { case CC_UPPER: - change_case_UTF8((const XMLByte*)new_cstr, (XMLByte*)new_cstr, UTF8CaseToUpper); + change_case_UTF8((const XMLByte*)new_cstr, new_cstr_len, (XMLByte*)new_cstr, new_cstr_len, UTF8CaseToUpper); break; case CC_LOWER: - change_case_UTF8((const XMLByte*)new_cstr, (XMLByte*)new_cstr, UTF8CaseToLower); + change_case_UTF8((const XMLByte*)new_cstr, new_cstr_len, (XMLByte*)new_cstr, new_cstr_len, UTF8CaseToLower); break; default: assert(!"unknown change case kind"); @@ -409,8 +409,9 @@ String& String::change_case(Charset& sou break; // never } + char *dest=new_cstr; unsigned char index; - for(const char* current=new_cstr; index=(unsigned char)*current; current++) { + for(const char* current=new_cstr; (index=(unsigned char)*current); current++) { unsigned char c=a[index]; if(b) c=b[c]; @@ -524,8 +525,8 @@ static int serialize_body_piece(const ch }; static int serialize_lang_piece(char alang, size_t asize, char** cur) { // lang - memcpy(*cur, &alang, sizeof(alang)); *cur+=sizeof(alang); - // length + **cur=alang; (*cur)++; + // length [WARNING: not cast, addresses must be %4=0 on sparc] memcpy(*cur, &asize, sizeof(asize)); *cur+=sizeof(asize); return 0; // 0=continue @@ -542,7 +543,7 @@ String::Cm String::serialize(size_t prol // 1: prolog char *cur=result.str+prolog_length; - // 2: langs.count + // 2: langs.count [WARNING: not cast, addresses must be %4=0 on sparc] memcpy(cur, &fragments_count, sizeof(fragments_count)); cur+=sizeof(fragments_count); // 3: lang info langs.for_each(body, serialize_lang_piece, &cur); @@ -563,22 +564,30 @@ bool String::deserialize(size_t prolog_l const char* cur=(const char* )buf+prolog_length; // 2: langs.count - if(buf_length(cur); cur+=sizeof(size_t); - buf_length-=sizeof(size_t); + // [WARNING: not cast, addresses must be %4=0 on sparc] + memcpy(&fragments_count, cur, sizeof(fragments_count)); cur+=sizeof(fragments_count); + buf_length-=sizeof(fragments_count); if(fragments_count) { // 3: lang info size_t total_length=0; for(size_t f=0; f(cur); cur+=sizeof(char); - size_t fragment_length=*reinterpret_cast(cur); cur+=sizeof(size_t); - langs.append(total_length, lang, fragment_length); + // lang + lang=*cur++; + // length [WARNING: not cast, addresses must be %4=0 on sparc] + memcpy(&fragment_length, cur, sizeof(fragment_length)); cur+=sizeof(fragment_length); + + // uchar needed to prevent propagating 0x80 bit to upper bytes + langs.append(total_length, (String::Language)(uchar)lang, fragment_length); total_length+=fragment_length; buf_length-=piece_length;