--- parser3/src/main/pa_common.C 2001/04/16 11:26:43 1.46.2.1 +++ parser3/src/main/pa_common.C 2001/04/23 08:52:24 1.49 @@ -1,4 +1,3 @@ - /** @file Parser: commonly functions. @@ -6,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_common.C,v 1.46.2.1 2001/04/16 11:26:43 paf Exp $ + $Id: pa_common.C,v 1.49 2001/04/23 08:52:24 paf Exp $ */ #include "pa_config_includes.h" @@ -74,6 +73,11 @@ bool file_read(Pool& pool, const String& /*if(exclusive) flock(f, LOCK_EX);*/ size_t max_size=limit?min(offset+limit, finfo.st_size)-offset:finfo.st_size; + if(!max_size) { // eof + data=0; + read_size=0; + return true; + } data=pool.malloc(max_size+(as_text?1:0)); if(offset) lseek(f, offset, SEEK_SET); @@ -286,13 +290,13 @@ static void append_attribute_subattribut Attributed_meaning_info& ami=*static_cast(info); // ...; charset=windows1251 - ami.header->APPEND_CONST("; "); + *ami.header << "; "; ami.header->append(akey, ami.lang, true); - ami.header->APPEND_CONST("="); - ami.header->append(static_cast(avalue)->as_string(), - ami.lang, true); + *ami.header << "="; + ami.header->append(static_cast(avalue)->as_string(), ami.lang, true); } -const String& attributed_meaning_to_string(Value& meaning, String::Untaint_lang lang) { +const String& attributed_meaning_to_string(Value& meaning, + String::Untaint_lang lang) { String &result=*new(meaning.pool()) String(meaning.pool()); if(Hash *hash=meaning.get_hash()) { // $value(value) $subattribute(subattribute value) @@ -345,3 +349,40 @@ bool StrEqNc(const char *s1, const char s2++; } } + +char *unquote(char*& current, char stop_at) { + char *result=current; + char *dest=current; + // skip leading WS + while(*current==' ' || *current=='\t') + current++; + if(!*current) + return current=0; + + bool quoted=*current=='"'; + if(quoted) + current++; + + for(; *current; ) { + if(quoted) + switch(*current) { + case '\\': // "...\c + if(current[1]) + current++; + break; + case '"': + current++; + goto break2; + } + else + if(*current==stop_at) + break; + + *dest++=*current++; + } +break2: + if(*current) + current++; // skip 'stop_at' + *dest=0; + return result; +}