--- parser3/src/include/pa_string.h 2001/07/20 09:40:46 1.99 +++ parser3/src/include/pa_string.h 2001/10/29 16:29:07 1.112 @@ -2,10 +2,9 @@ Parser: string class decl. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_string.h,v 1.99 2001/07/20 09:40:46 parser Exp $ + $Id: pa_string.h,v 1.112 2001/10/29 16:29:07 paf Exp $ */ #ifndef PA_STRING_H @@ -57,6 +56,7 @@ class Table; class Array; class SQL_Connection; +class Dictionary; /** Pooled string. @@ -86,7 +86,9 @@ public: CR_GROW_COUNT=2 ///< each time the String chunk_is_full() string expanded() }; - /// piece is tainted or not. the language to use when detaint + /** piece is tainted or not. the language to use when detaint + remember to change String_Untaint_lang_name @ untaint.C along + */ enum Untaint_lang { UL_UNSPECIFIED=0, ///< zero value handy for hash lookup @see untaint_lang_name2enum UL_CLEAN, ///< clean @@ -98,13 +100,14 @@ public: just a flag, that value not stored */ UL_AS_IS, ///< leave all characters intact - UL_FILE_NAME, ///< filename + UL_FILE_SPEC, ///< file specification UL_HTTP_HEADER, ///< text in HTTP response header UL_MAIL_HEADER, ///< text in mail header UL_URI, ///< text in uri UL_TABLE, ///< ^table:set body UL_SQL, ///< ^table:sql body UL_JS, ///< JavaScript code + UL_XML, ///< ^dom:set xml UL_HTML, ///< HTML code (for editing) UL_USER_HTML ///< HTML code with USER chars }; @@ -117,7 +120,7 @@ public: /// makes store_to produce origin:text\n output void set_origins_mode(bool aorigins_mode) const { forigins_mode=aorigins_mode; } /// convert to C string. if 'lang' known, forcing 'lang' to it - char *cstr(Untaint_lang lang=UL_UNSPECIFIED, + char *cstr(Untaint_lang lang=UL_AS_IS, SQL_Connection *connection=0, const char *charset=0) const { @@ -126,6 +129,10 @@ public: *eol=0; return result; } + /// puts pieces to buf + void serialize(size_t prolog_size, void *& buf, size_t& buf_size) const; + /// appends pieces from buf to self + void deserialize(size_t prolog_size, void *buf, size_t buf_size, const char *file); /** append fragment @see APPEND_AS_IS, APPEND_CLEAN, APPEND_TAINTED, APPEND_CONST */ @@ -180,15 +187,18 @@ public: /// simple hash code of string. used by Hash uint hash_code() const; + /// extracts first char of a string + char first_char() const; + /// extracts [start, finish) piece of string String& mid(size_t start, size_t finish) const; /// @return position of substr in string, -1 means "not found" [String version] int pos(const String& substr, - size_t this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; + int this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; /// @return position of substr in string, -1 means "not found" [const char* version] int pos(const char *substr, size_t substr_size=0, - size_t this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; + int this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; void split(Array& result, size_t *pos_after_ref, @@ -221,6 +231,7 @@ public: }; String& change_case(Pool& pool, const unsigned char *pcre_tables, Change_case_kind kind) const; + String& replace(Pool& pool, Dictionary& dict) const; double as_double() const; int as_int() const; @@ -233,7 +244,7 @@ private: /// several String fragments struct Chunk { - size_t count; ///< the number of rows in chunk + uint count; ///< the number of rows in chunk /// string fragment or a link to next chunk union union Row { /// fragment @@ -260,15 +271,12 @@ private: Chunk::Row *link_row; private: - // last chunk + /// last chunk Chunk *last_chunk; - // string size + /// string size size_t fsize; - // used rows in all chunks - int fused_rows; - /// origins_mode changes behaviour of store_to[cstr()] mutable bool forigins_mode; @@ -277,6 +285,7 @@ private: bool chunk_is_full() { return append_here == link_row; } + uint used_rows() const; void expand(); size_t cstr_bufsize(Untaint_lang lang) const; @@ -285,6 +294,12 @@ private: SQL_Connection *connection=0, const char *charset=0) const; + String& reconstruct(Pool& pool) const; + void join_chain(Pool& pool, + uint& ai, const Chunk*& achunk, const Chunk::Row*& arow, + Untaint_lang& joined_lang, const char *& joined_ptr, size_t& joined_size) const; + String& replace_in_reconstructed(Pool& pool, Dictionary& dict) const; + private: //disabled String& operator = (const String&) { return *this; }