--- parser3/src/include/pa_string.h 2002/04/19 08:28:35 1.136 +++ parser3/src/include/pa_string.h 2003/01/22 15:39:07 1.144.2.1 @@ -1,15 +1,15 @@ /** @file Parser: string class decl. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - - $Id: pa_string.h,v 1.136 2002/04/19 08:28:35 paf Exp $ */ #ifndef PA_STRING_H #define PA_STRING_H +static const char* IDENT_STRING_H="$Date: 2003/01/22 15:39:07 $"; + #include "pa_pool.h" #include "pa_types.h" @@ -68,7 +68,7 @@ class Dictionary; and the language which should be used to detaint them */ #include "pa_pragma_pack_begin.h" -class String : public Pooled { +class String: public PA_Object { public: enum { @@ -106,10 +106,12 @@ public: public: - String(Pool& apool, const char *src=0, size_t src_size=0, bool tainted=false); + //static String& OnPool(Pool& apool, const char *local_src=0, size_t src_size=0, bool tainted=false); + String(const char *src=0, size_t src_size=0, bool tainted=false); String(const String& src); + ~String(); bool is_empty() const { return append_here==head.chunk.rows; } - size_t size() const; + size_t size() const; /// @todonow make it field /// convert to C string. if 'lang' known, forcing 'lang' to it char *cstr(Untaint_lang lang=UL_AS_IS, SQL_Connection *connection=0, @@ -153,6 +155,11 @@ public: */ int cmp(int& partial, const char* src_ptr, size_t src_size=0, size_t this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; + /// this starts with src + bool starts_with(const char* src_ptr, size_t src_size=0) const { + int p; cmp(p, src_ptr, src_size); + return p==0 || p==2; + } bool operator == (const char* src_ptr) const { size_t src_size=src_ptr?strlen(src_ptr):0; if(size() != src_size) @@ -172,8 +179,10 @@ public: /// simple hash code of string. used by Hash uint hash_code() const; - /// extracts first char of a string - char first_char() const; + /// extracts first char of a string, if any + char first_char() const { + return is_empty()?0:*head.chunk.rows[0].item.ptr; + } /// extracts [start, finish) piece of string String& mid(size_t start, size_t finish) const; @@ -205,7 +214,7 @@ public: prematch/match/postmatch/1/2/3/... @endverbatim */ - bool match( + bool match(Charset& source_charset, const String *aorigin, const String& regexp, const String *options, @@ -216,12 +225,14 @@ public: CC_UPPER, CC_LOWER }; - String& change_case(Pool& pool, + String& change_case(Charset& source_charset, Change_case_kind kind) const; - String& replace(Pool& pool, Dictionary& dict) const; + String& replace(Dictionary& dict) const; double as_double() const; int as_int() const; + String& join_chains(char** cstr) const; + #ifndef NO_STRING_ORIGIN /// origin of string. calculated by first row const Origin& origin() const; @@ -287,7 +298,7 @@ private: Charset *store_to_charset=0, const char *store_to_charset_name=0) const; - void join_chain(Pool& pool, + void join_chain( const Chunk*& achunk, const Chunk::Row*& arow, uint& acountdown, uchar& joined_lang, const char *& joined_ptr, size_t& joined_size) const;