--- parser3/src/main/pa_common.C 2001/04/10 11:24:00 1.45 +++ parser3/src/main/pa_common.C 2001/04/23 08:52:24 1.49 @@ -1,4 +1,3 @@ - /** @file Parser: commonly functions. @@ -6,18 +5,10 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_common.C,v 1.45 2001/04/10 11:24:00 paf Exp $ + $Id: pa_common.C,v 1.49 2001/04/23 08:52:24 paf Exp $ */ #include "pa_config_includes.h" - -#include -#include -#include -#include -#include -#include - #include "pa_common.h" #include "pa_types.h" #include "pa_exception.h" @@ -27,6 +18,15 @@ #include "pa_hash.h" #include "pa_string.h" +#ifndef WIN32 +# ifndef _O_TEXT +# define _O_TEXT 0 +# endif +# ifndef _O_BINARY +# define _O_BINARY 0 +# endif +#endif + #if _MSC_VER int __vsnprintf(char *b, size_t s, const char *f, va_list l) { @@ -73,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); @@ -83,7 +88,7 @@ bool file_read(Pool& pool, const String& if(read_size>=0 && read_size<=max_size) { if(as_text) - ((char *)data)[read_size]=0; + ((char*&)data)[read_size]=0; } else PTHROW(0, 0, &file_spec, @@ -285,14 +290,13 @@ static void append_attribute_subattribut Attributed_meaning_info& ami=*static_cast(info); // ...; charset=windows1251 - if(ami.header->size()) - 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; +}