--- parser3/src/include/pa_string.h 2015/10/09 11:42:38 1.213 +++ parser3/src/include/pa_string.h 2016/09/07 14:40:07 1.217 @@ -1,14 +1,14 @@ /** @file Parser: string class decl. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_STRING_H #define PA_STRING_H -#define IDENT_PA_STRING_H "$Id: pa_string.h,v 1.213 2015/10/09 11:42:38 moko Exp $" +#define IDENT_PA_STRING_H "$Id: pa_string.h,v 1.217 2016/09/07 14:40:07 moko Exp $" // includes #include "pa_types.h" @@ -334,8 +334,10 @@ public: // that string body does not change after it is stored as a hash key mutable uint hash_code; #define INIT_HASH_CODE(c) ,hash_code(c) +#define ZERO_HASH_CODE hash_code=0; #else #define INIT_HASH_CODE(c) +#define ZERO_HASH_CODE #endif #ifdef STRING_LENGTH_CACHING @@ -379,7 +381,7 @@ public: static Body Format(int value); - void clear() { ZERO_LENGTH body=CORD_EMPTY; } + void clear() { ZERO_LENGTH ZERO_HASH_CODE body=CORD_EMPTY; } bool operator! () const { return is_empty(); } @@ -484,7 +486,7 @@ public: size_t* out_start=0, size_t* out_length=0, Charset* source_charset=0) const; }; -private: +protected: Body body; ///< all characters of string Languages langs; ///< string characters lang @@ -629,18 +631,13 @@ public: but when specified: look for substring that lies in ONE fragment in THAT lang @return position of substr in string, -1 means "not found" [const char* version] */ - size_t pos(const Body substr, - size_t this_offset=0, Language lang=L_UNSPECIFIED) const; + size_t pos(const Body substr, size_t this_offset=0, Language lang=L_UNSPECIFIED) const; /// String version of @see pos(const char*, int, Language) - size_t pos(const String& substr, - size_t this_offset=0, Language lang=L_UNSPECIFIED) const; - size_t pos(char c, - size_t this_offset=0) const { + size_t pos(const String& substr, size_t this_offset=0, Language lang=L_UNSPECIFIED) const; + size_t pos(char c, size_t this_offset=0) const { return body.pos(c, this_offset); } - size_t pos(Charset& charset, - const String& substr, - size_t this_offset=0, Language lang=L_UNSPECIFIED) const; + size_t pos(Charset& charset, const String& substr, size_t this_offset=0, Language lang=L_UNSPECIFIED) const; size_t strrpbrk(const char* chars, size_t left=0) const { return (length()) ? body.strrpbrk(chars, left, length()-1) : STRING_NOT_FOUND; @@ -656,19 +653,11 @@ public: return body.rskipchars(chars, left, right); } - void split(ArrayString& result, - size_t& pos_after, - const char* delim, - Language lang=L_UNSPECIFIED, int limit=-1) const; - void split(ArrayString& result, - size_t& pos_after, - const String& delim, - Language lang=L_UNSPECIFIED, int limit=-1) const; - - typedef void (*Row_action)(Table& table, ArrayString* row, - int prestart, int prefinish, - int poststart, int postfinish, - void *info); + void split(ArrayString& result, size_t& pos_after, const char* delim, Language lang=L_UNSPECIFIED, int limit=-1) const; + void split(ArrayString& result, size_t& pos_after, const String& delim, Language lang=L_UNSPECIFIED, int limit=-1) const; + + typedef void (*Row_action)(Table& table, ArrayString* row, int prestart, int prefinish, int poststart, int postfinish, void *info); + /** @return table of found items, if any. table format is defined and fixed[can be used by others]: @@ -676,15 +665,14 @@ public: prematch/match/postmatch/1/2/3/... @endverbatim */ - Table* match(VRegex* vregex, - Row_action row_action, void *info, - int& matches_count) const; + Table* match(VRegex* vregex, Row_action row_action, void *info, int& matches_count) const; + enum Change_case_kind { CC_UPPER, CC_LOWER }; - String& change_case(Charset& source_charset, - Change_case_kind kind) const; + String& change_case(Charset& source_charset, Change_case_kind kind) const; + const String& replace(const Dictionary& dict) const; const String& trim(Trim_kind kind=TRIM_BOTH, const char* chars=0, Charset* source_charset=0) const; double as_double() const { return pa_atod(cstr(), this); }