--- parser3/src/include/pa_string.h 2003/09/26 13:36:35 1.149 +++ parser3/src/include/pa_string.h 2004/02/11 15:33:14 1.156 @@ -1,14 +1,14 @@ /** @file Parser: string class decl. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_STRING_H #define PA_STRING_H -static const char* IDENT_STRING_H="$Date: 2003/09/26 13:36:35 $"; +static const char * const IDENT_STRING_H="$Date: 2004/02/11 15:33:14 $"; // includes @@ -36,6 +36,11 @@ class Request_charsets; class String; typedef Array ArrayString; +// generally useful + +int pa_atoi(const char* str, const String* problem_source=0); +double pa_atod(const char* str, const String* problem_source=0); + /// this is result of pos functions which mean that substr were not found #define STRING_NOT_FOUND ((size_t)-1) @@ -298,10 +303,15 @@ public: size_t pos(const Body substr, size_t offset=0) const { if(!substr.length()) return STRING_NOT_FOUND; // in this case CORD_str returns 0 [parser users got used to -1] + + // CORD_str checks for bad offset [CORD_chr does not] return CORD_str(body, offset, substr.body); } size_t pos(char c, size_t offset=0) const { + if(offset>=length()) // CORD_chr does not check that [and ABORT's in that case] + return STRING_NOT_FOUND; + return CORD_chr(body, offset, c); } @@ -335,8 +345,8 @@ public: private: - Languages langs; ///< string characters lang Body body; ///< all characters of string + Languages langs; ///< string characters lang const char* v() const; @@ -345,10 +355,11 @@ private: public: + static const String Empty; + explicit String(const char* cstr=0, size_t helper_length=0, bool tainted=false); explicit String(const C cstr, bool tainted=false); String(Body abody, Language alang): body(abody), langs(alang) { - assert(!body.is_empty()); ASSERT_STRING_INVARIANT(*this); } String(const String& src): body(src.body), langs(src.langs) { @@ -470,8 +481,8 @@ public: String& change_case(Charset& source_charset, Change_case_kind kind) const; const String& replace(const Dictionary& dict) const; - double as_double() const; - int as_int() const; + double as_double() const { return pa_atod(cstr(), this); } + int as_int() const { return pa_atoi(cstr(), this); } private: //disabled