--- parser3/src/include/pa_string.h 2001/03/25 10:14:38 1.53 +++ parser3/src/include/pa_string.h 2001/03/29 17:23:21 1.58 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_string.h,v 1.53 2001/03/25 10:14:38 paf Exp $ + $Id: pa_string.h,v 1.58 2001/03/29 17:23:21 paf Exp $ */ #ifndef PA_STRING_H @@ -31,26 +31,26 @@ const char *src, size_t size, \ String::Untaint_lang lang, \ const char *file, uint line -/// appends clean piece to String @see String::real_append -# define APPEND(src, size, file, line) \ - real_append(src, size, String::UL_NO, file, line) -/// appends tainted piece to String @see String::real_append -# define APPEND_TAINTED(src, size, file, line) \ - real_append(src, size, String::UL_YES, file, line) +/// appends piece to String @see String::real_append +# define APPEND(src, size, lang, file, line) \ + real_append(src, size, lang, file, line) #else # define STRING_APPEND_PARAMS \ const char *src, \ size_t size, \ String::Untaint_lang lang +/// appends piece to String @see String::real_append +# define APPEND(src, size, lang, file, line) \ + real_append(src, size, lang) +#endif /// appends clean piece to String @see String::real_append -# define APPEND(src, size, file, line) \ - real_append(src, size, String::UL_NO) +#define APPEND_CLEAN(src, size, file, line) \ + APPEND(src, size, String::UL_NO, file, line) /// appends tainted piece to String @see String::real_append -# define APPEND_TAINTED(src, size, file, line) \ - real_append(src, size, String::UL_YES) -#endif +#define APPEND_TAINTED(src, size, file, line) \ + APPEND(src, size, String::UL_YES, file, line) /// handy: appends const char* piece to String @see String::real_append -#define APPEND_CONST(src) APPEND(src, 0, 0, 0) +#define APPEND_CONST(src) APPEND_CLEAN(src, 0, 0, 0) /** Pooled string. @@ -115,21 +115,21 @@ public: return result; } /** append fragment - @see APPEND, APPEND_TAINTED, APPEND_CONST + @see APPEND_CLEAN, APPEND_TAINTED, APPEND_CONST */ String& real_append(STRING_APPEND_PARAMS); /// @return <0 ==0 or >0 depending on comparison result - int cmp (const String& src) const; - bool operator < (const String& src) const { return cmp(src)<0; } - bool operator > (const String& src) const { return cmp(src)>0; } - bool operator <= (const String& src) const { return cmp(src)<=0; } - bool operator >= (const String& src) const { return cmp(src)>=0; } + int cmp (int& partial, const String& src, size_t this_offset=0) const; + bool operator < (const String& src) const { int p; return cmp(p, src)<0; } + bool operator > (const String& src) const { int p; return cmp(p, src)>0; } + bool operator <= (const String& src) const { int p; return cmp(p, src)<=0; } + bool operator >= (const String& src) const { int p; return cmp(p, src)>=0; } bool operator == (const String& src) const { if(size()!=src.size()) // can speed up in trivial case return false; - return cmp(src)==0; + int p; return cmp(p, src)==0; } - bool operator != (const String& src) const { return cmp(src)!=0; } + bool operator != (const String& src) const { int p; return cmp(p, src)!=0; } /** @param partial @@ -139,13 +139,13 @@ public: - 1: means @c this starts @c src - 2: means @src starts @this */ - int cmp(const char* src_ptr, int& partial, size_t src_size=0) const; + int cmp(int& partial, const char* src_ptr, size_t src_size=0) const; bool operator == (const char* src_ptr) const { size_t src_size=src_ptr?strlen(src_ptr):0; if(size() != src_size) return false; int partial; // unused - return cmp(src_ptr, partial, src_size)==0; + return cmp(partial, src_ptr, src_size)==0; } /** @@ -159,6 +159,12 @@ public: /// simple hash code of string. used by Hash uint hash_code() const; + /// extracts [start, finish) piece of string + String& piece(size_t start, size_t finish) const; + + /// @return position of substr in string, -1 means "not found" + int pos(const String& substr, size_t this_offset=0) const; + #ifndef NO_STRING_ORIGIN /// origin of string. calculated by first row const Origin& origin() const; @@ -168,7 +174,7 @@ private: struct Chunk { // the number of rows in chunk - int count; + size_t count; union Row { // fragment struct {