--- parser3/src/include/pa_string.h 2003/10/21 05:11:00 1.151 +++ parser3/src/include/pa_string.h 2004/03/02 15:54:07 1.158 @@ -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/10/21 05:11:00 $"; +static const char * const IDENT_STRING_H="$Date: 2004/03/02 15:54:07 $"; // 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) @@ -94,6 +99,12 @@ public: L_OPTIMIZE_BIT = 0x80 ///< flag, requiring cstr whitespace optimization }; + enum Trim_kind { + TRIM_BOTH, + TRIM_START, + TRIM_END + }; + union Languages { struct { @@ -115,7 +126,7 @@ public: :CORD_chars((char)opt.lang, alength); } - /// appending when 'langs' already contain something [simple cases hanled elsewhere] + /// appending when 'langs' already contain something [simple cases handled elsewhere] template void append(C current, const CORD to_nonempty_target_langs) { @@ -322,12 +333,17 @@ public: /*Body normalize() const { return Body(CORD_balance(body)); }*/ + + /// @returns this or 0 or mid. if returns this or 0 out_* are not filled + Body trim(Trim_kind kind=TRIM_BOTH, const char* chars=0, + size_t* out_start=0, size_t* out_length=0) const; }; struct C { const char *str; size_t length; operator const char *() { return str; } + C(): str(0), length(0) {} C(const char *astr, size_t asize): str(astr), length(asize) {} }; @@ -335,13 +351,14 @@ public: char *str; size_t length; //operator char *() { return str; } + Cm(): str(0), length(0) {} Cm(char *astr, size_t asize): str(astr), length(asize) {} }; private: - Languages langs; ///< string characters lang Body body; ///< all characters of string + Languages langs; ///< string characters lang const char* v() const; @@ -355,7 +372,6 @@ public: 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) { @@ -477,8 +493,9 @@ 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; + const String& trim(Trim_kind kind=TRIM_BOTH, const char* chars=0) const; + double as_double() const { return pa_atod(cstr(), this); } + int as_int() const { return pa_atoi(cstr(), this); } private: //disabled