Diff for /parser3/src/include/pa_string.h between versions 1.174 and 1.181

version 1.174, 2008/07/21 07:37:02 version 1.181, 2009/05/13 07:35:52
Line 1 Line 1
 /** @file  /** @file
         Parser: string class decl.          Parser: string class decl.
   
         Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
Line 36  class Dictionary; Line 36  class Dictionary;
 class Request_charsets;  class Request_charsets;
 class String;  class String;
 typedef Array<const String*> ArrayString;  typedef Array<const String*> ArrayString;
   class VRegex;
   
 // generally useful  // generally useful
   
Line 57  inline size_t get_length(T current) { Line 58  inline size_t get_length(T current) {
         - whether they are tainted or not,           - whether they are tainted or not, 
           and the lang which should be used to detaint them            and the lang which should be used to detaint them
 */  */
   
   
 class String: public PA_Object {  class String: public PA_Object {
 public:  public:
   
Line 97  public: Line 100  public:
                 L_HTML='H',             ///< HTML code                  L_HTML='H',             ///< HTML code
                 L_REGEX='R',    ///< RegEx expression                  L_REGEX='R',    ///< RegEx expression
                 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
                 // 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 107  public: Line 111  public:
                 TRIM_END                  TRIM_END
         };          };
   
   
         union Languages {          union Languages {
   
                 struct {                  struct {
 #ifdef PA_LITTLE_ENDIAN  #ifdef PA_LITTLE_ENDIAN
                         Language lang:8;                          Language lang:8;
                         int is_not_just_lang:sizeof(CORD)*8-8;                          size_t is_not_just_lang:sizeof(CORD)*8-8;
 #elif defined(PA_BIG_ENDIAN)  #elif defined(PA_BIG_ENDIAN)
                         int is_not_just_lang:sizeof(CORD)*8-8;                          size_t is_not_just_lang:sizeof(CORD)*8-8;
                         Language lang:8;                          Language lang:8;
 #else  #else
 #       error word endianness not determined for some obscure reason  #       error word endianness not determined for some obscure reason
Line 171  public: Line 176  public:
   
                         if(!opt.is_not_just_lang)                          if(!opt.is_not_just_lang)
                                 if(opt.lang) {                                  if(opt.lang) {
                                         if(opt.lang==alang) // same length? ignoring                                          if(opt.lang==alang) // same language? ignoring
                                                 return;                                                  return;
                                 } else {                                  } else {
                                         opt.lang=alang; // to uninitialized                                          opt.lang=alang; // to uninitialized
Line 181  public: Line 186  public:
                         append(current, CORD_chars((char)alang, asize));                          append(current, CORD_chars((char)alang, asize));
                 }                  }
   
                 /// MUST be called exactly prior to modification of current [uses it's length]  
                 template<typename C>                  template<typename C>
                 void append(C current, size_t appending_length,                   void appendHelper(C current, Language alang, C asize_helper) {
                         const Languages src) {                          assert(alang);
                         assert(appending_length);  
                           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<typename C>
                   void appendHelper(C current, C length_helper, const Languages src) {
   
                         if(!langs)                          if(!langs)
                                 langs=src.langs; // to uninitialized                                  langs=src.langs; // to uninitialized
                         else if(!src.opt.is_not_just_lang)                          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                          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]                  /// MUST be called exactly prior to modification of current [uses it's length]
                 template<typename C>                  template<typename C>
                 void append(C current,                  void append(C current,
Line 271  public: Line 290  public:
                                 || body[1]==6 // SUBSTR_HDR                                   || body[1]==6 // SUBSTR_HDR 
                                 );                                  );
                 }                  }
                 /// WARNING: length is only HELPER length, str in ANY case should be zero-terminated  
                 Body(const char* str, size_t helper_length): body(CORD_EMPTY) {  
                         append_know_length(str, helper_length?helper_length:strlen(str));  
                 }  
                 static Body Format(int value);                  static Body Format(int value);
   
                 void clear() { body=CORD_EMPTY; }                  void clear() { body=CORD_EMPTY; }
Line 318  public: Line 334  public:
                 Body mid(size_t index, size_t length) const { return CORD_substr(body, index, length); }                  Body mid(size_t index, size_t length) const { return CORD_substr(body, index, 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); }
                 size_t pos(const Body substr, size_t offset=0) const {                   size_t pos(const Body substr, size_t offset=0) const { 
                         if(!substr.length())                          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]
Line 386  public: Line 402  public:
   
         static const String Empty;          static const String Empty;
   
         explicit String(const char* cstr=0, size_t helper_length=0, bool tainted=false);          explicit String(){};
         explicit String(const C cstr, bool tainted=false);          explicit String(const char* cstr, bool tainted=false){
                   if(cstr && *cstr){
                           body=cstr;
                           langs=tainted ? L_TAINTED:L_CLEAN;
                   }
           }
           explicit String(const String::C cstr, bool tainted=false){
                   if(cstr.length){
                           body=cstr.str;
                           langs=tainted ? L_TAINTED:L_CLEAN;
                   }
           }
         String(Body abody, Language alang): body(abody), langs(alang) {          String(Body abody, Language alang): body(abody), langs(alang) {
                 ASSERT_STRING_INVARIANT(*this);                  ASSERT_STRING_INVARIANT(*this);
         }          }
Line 503  public: Line 530  public:
                         prematch/match/postmatch/1/2/3/...                          prematch/match/postmatch/1/2/3/...
                 @endverbatim                  @endverbatim
         */          */
         Table* match(Charset& source_charset,          Table* match(VRegex* vregex,
                 const String& regexp,   
                 const String* options,  
                 Row_action row_action, void *info,                  Row_action row_action, void *info,
                 int& matches_count) const;                  int& matches_count) const;
         enum Change_case_kind {          enum Change_case_kind {

Removed from v.1.174  
changed lines
  Added in v.1.181


E-mail: