--- parser3/src/include/pa_string.h 2008/07/15 12:51:20 1.170 +++ parser3/src/include/pa_string.h 2009/04/22 04:37:52 1.178 @@ -8,7 +8,7 @@ #ifndef PA_STRING_H #define PA_STRING_H -static const char * const IDENT_STRING_H="$Date: 2008/07/15 12:51:20 $"; +static const char * const IDENT_STRING_H="$Date: 2009/04/22 04:37:52 $"; // includes #include "pa_types.h" @@ -36,6 +36,7 @@ class Dictionary; class Request_charsets; class String; typedef Array ArrayString; +class VRegex; // generally useful @@ -57,6 +58,8 @@ inline size_t get_length(T current) { - whether they are tainted or not, and the lang which should be used to detaint them */ + + class String: public PA_Object { public: @@ -97,6 +100,7 @@ public: L_HTML='H', ///< HTML code L_REGEX='R', ///< RegEx expression L_HTTP_COOKIE='C', ///< cookies encoded as %uXXXX for compartibility with js functions encode/decode + L_FILE_POST='f', ///temporary escaping zero-char // READ WARNING ABOVE BEFORE ADDING ANYTHING L_OPTIMIZE_BIT = 0x80 ///< flag, requiring cstr whitespace optimization }; @@ -107,6 +111,7 @@ public: TRIM_END }; + union Languages { struct { @@ -181,20 +186,34 @@ public: append(current, CORD_chars((char)alang, asize)); } - /// MUST be called exactly prior to modification of current [uses it's length] template - void append(C current, size_t appending_length, - const Languages src) { - assert(appending_length); + void appendHelper(C current, Language alang, C asize_helper) { + assert(alang); + + if(!opt.is_not_just_lang) + if(opt.lang) { + if(opt.lang==alang) // same length? ignoring + return; + } else { + opt.lang=alang; // to uninitialized + return; + } + + append(current, CORD_chars((char)alang, asize_helper.length())); + } + + template + void appendHelper(C current, C length_helper, const Languages src) { if(!langs) langs=src.langs; // to uninitialized else if(!src.opt.is_not_just_lang) - append(current, src.opt.lang, appending_length); // simplifying when simple source + appendHelper(current, src.opt.lang, length_helper); // simplifying when simple source else - append(current, src.make_langs(appending_length)); + append(current, src.make_langs(length_helper)); } - + + /// MUST be called exactly prior to modification of current [uses it's length] template void append(C current, @@ -400,6 +419,7 @@ public: bool is_empty() const { return body.is_empty(); } size_t length() const { return body.length(); } + size_t length(Charset& charset) const; /// convert to CORD. if 'lang' known, forcing 'lang' to it Body cstr_to_string_body(Language lang=L_AS_IS, @@ -462,6 +482,7 @@ public: /// extracts [start, finish) piece of string String& mid(size_t substr_begin, size_t substr_end) const; + String& mid(Charset& charset, size_t from, size_t to, size_t helper_length=0) const; /** ignore lang if it's L_UNSPECIFIED @@ -477,6 +498,9 @@ public: 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; void split(ArrayString& result, size_t& pos_after, @@ -498,9 +522,7 @@ public: prematch/match/postmatch/1/2/3/... @endverbatim */ - Table* match(Charset& source_charset, - const String& regexp, - const String* options, + Table* match(VRegex* vregex, Row_action row_action, void *info, int& matches_count) const; enum Change_case_kind { @@ -514,6 +536,7 @@ public: double as_double() const { return pa_atod(cstr(), this); } int as_int() const { return pa_atoi(cstr(), this); } bool as_bool() const { return as_int()!=0; } + const String& escape(Charset& source_charset) const; private: //disabled