|
|
| version 1.192, 2009/07/07 12:13:28 | version 1.201, 2012/03/16 09:24:10 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: string class decl. | Parser: string class decl. |
| Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| #ifndef PA_STRING_H | #ifndef PA_STRING_H |
| #define PA_STRING_H | #define PA_STRING_H |
| static const char * const IDENT_STRING_H="$Date$"; | #define IDENT_PA_STRING_H "$Id$" |
| // includes | // includes |
| #include "pa_types.h" | #include "pa_types.h" |
| Line 103 public: | Line 103 public: |
| L_URI='U', ///< text in uri | L_URI='U', ///< text in uri |
| L_SQL='Q', ///< ^table:sql body | L_SQL='Q', ///< ^table:sql body |
| L_JS='J', ///< JavaScript code | L_JS='J', ///< JavaScript code |
| L_XML='X', ///< ^dom:set xml | L_XML='X', ///< ^xdoc:create xml |
| L_HTML='H', ///< HTML code | L_HTML='H', ///< HTML code |
| L_REGEX='R', ///< RegEx expression | L_REGEX='R', ///< RegExp |
| L_JSON='S', ///< JSON code | |
| L_HTTP_COOKIE='C', ///< cookies encoded as %uXXXX for compartibility with js functions encode/decode | L_HTTP_COOKIE='C', ///< cookies encoded as %uXXXX for compartibility with js functions encode/decode |
| L_FILE_POST='f', ///< temporary escaping zero-char | |
| L_PARSER_CODE='p', ///< ^process body | L_PARSER_CODE='p', ///< ^process body |
| // READ WARNING ABOVE BEFORE ADDING ANYTHING | // READ WARNING ABOVE BEFORE ADDING ANYTHING |
| L_OPTIMIZE_BIT = 0x80 ///< flag, requiring cstr whitespace optimization | L_OPTIMIZE_BIT = 0x80 ///< flag, requiring cstr whitespace optimization |
| Line 142 public: | Line 142 public: |
| CORD make_langs(size_t aoffset, size_t alength) const { | CORD make_langs(size_t aoffset, size_t alength) const { |
| return opt.is_not_just_lang? | return opt.is_not_just_lang? |
| CORD_substr(langs, aoffset, alength) | CORD_substr(langs, aoffset, alength, 0) |
| :CORD_chars((char)opt.lang, alength); | :CORD_chars((char)opt.lang, alength); |
| } | } |
| Line 247 public: | Line 247 public: |
| if(!langs) // to uninitialized? | if(!langs) // to uninitialized? |
| if(src.opt.is_not_just_lang) | if(src.opt.is_not_just_lang) |
| langs=CORD_substr(src.langs, aoffset, alength); // to uninitialized complex | langs=CORD_substr(src.langs, aoffset, alength, 0); // to uninitialized complex |
| else | else |
| opt.lang=src.opt.lang; // to uninitialized simple | opt.lang=src.opt.lang; // to uninitialized simple |
| else | else |
| Line 363 public: | Line 363 public: |
| CORD get_cord() const { return body; } | CORD get_cord() const { return body; } |
| uint get_hash_code() const; | uint get_hash_code() const; |
| const char* cstr() const { return CORD_to_const_char_star(body); } | const char* cstr() const { |
| char* cstrm() const { return CORD_to_char_star(body); } | #ifdef STRING_LENGTH_CACHING |
| string_length = length(); | |
| if(string_length) | |
| return const_cast<Body*>(this)->body=CORD_to_const_char_star(body, string_length); | |
| #endif | |
| return CORD_to_const_char_star(body, length()); | |
| } | |
| char* cstrm() const { return CORD_to_char_star(body, length()); } | |
| #ifdef STRING_LENGTH_CACHING | #ifdef STRING_LENGTH_CACHING |
| void set_length(size_t alength){ string_length = alength; } | void set_length(size_t alength){ string_length = alength; } |
| Line 410 public: | Line 418 public: |
| } | } |
| char fetch(size_t index) const { return CORD_fetch(body, index); } | char fetch(size_t index) const { return CORD_fetch(body, index); } |
| Body mid(size_t index, size_t length) const { return CORD_substr(body, index, length); } | Body mid(size_t aindex, size_t alength) const { return CORD_substr(body, aindex, alength, length()); } |
| size_t pos(const char* substr, size_t offset=0) const { return CORD_str(body, offset, substr); } | size_t pos(const char* substr, size_t offset=0) const { return CORD_str(body, offset, substr, length()); } |
| size_t pos(const Body substr, size_t offset=0) const { | size_t pos(const Body substr, size_t offset=0) const { |
| if(substr.is_empty()) | if(substr.is_empty()) |
| return STRING_NOT_FOUND; // in this case CORD_str returns 0 [parser users got used to -1] | return STRING_NOT_FOUND; // in this case CORD_str returns 0 [parser users got used to -1] |
| // CORD_str checks for bad offset [CORD_chr does not] | // CORD_str checks for bad offset [CORD_chr does not] |
| return CORD_str(body, offset, substr.body); | return CORD_str(body, offset, substr.body, length()); |
| } | } |
| size_t pos(char c, | size_t pos(char c, |
| size_t offset=0) const { | size_t offset=0) const { |
| Line 543 public: | Line 551 public: |
| char *untaint_cstrm(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const { | char *untaint_cstrm(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const { |
| return cstr_to_string_body_untaint(lang, connection, charsets).cstrm(); | return cstr_to_string_body_untaint(lang, connection, charsets).cstrm(); |
| } | } |
| const char* untaint_and_transcode_cstr(Language lang, const Request_charsets *charsets) const; | |
| /// puts pieces to buf | /// puts pieces to buf |
| Cm serialize(size_t prolog_size) const; | Cm serialize(size_t prolog_size) const; |
| /// appends pieces from buf to self | /// appends pieces from buf to self |
| Line 569 public: | Line 580 public: |
| String& append(const String& src, Language lang, bool forced=false) { | String& append(const String& src, Language lang, bool forced=false) { |
| return src.append_to(*this, lang, forced); | return src.append_to(*this, lang, forced); |
| } | } |
| String& append_quoted(const String* src, Language lang=L_JSON){ | |
| *this << "\""; | |
| if(src) | |
| this->append(*src, lang, true/*forced lang*/); | |
| *this << "\""; | |
| return *this; | |
| } | |
| String& operator << (const String& src) { return append(src, L_PASS_APPENDED); } | String& operator << (const String& src) { return append(src, L_PASS_APPENDED); } |
| String& operator << (const char* src) { return append_help_length(src, 0, L_AS_IS); } | String& operator << (const char* src) { return append_help_length(src, 0, L_AS_IS); } |
| String& operator << (const Body& src){ | String& operator << (const Body& src){ |