--- parser3/src/include/pa_string.h 2020/10/14 16:51:45 1.226 +++ parser3/src/include/pa_string.h 2026/01/06 13:27:59 1.239 @@ -1,17 +1,18 @@ /** @file Parser: string class decl. - Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_STRING_H #define PA_STRING_H -#define IDENT_PA_STRING_H "$Id: pa_string.h,v 1.226 2020/10/14 16:51:45 moko Exp $" +#define IDENT_PA_STRING_H "$Id: pa_string.h,v 1.239 2026/01/06 13:27:59 moko Exp $" // includes #include "pa_types.h" +#include "pa_int.h" #include "pa_array.h" extern "C" { // cord's author forgot to do that @@ -47,15 +48,29 @@ class SQL_Connection; class Dictionary; class Request_charsets; class String; -typedef Array ArrayString; class VRegex; -// generally useful +#ifdef NDEBUG +typedef Array ArrayString; +#else +class ArrayString : public Array { +public: + inline ArrayString(size_t initial=0) : Array(initial){ + } + inline Array& operator+=(element_type src) { + assert(src != NULL); + return Array::operator+=(src); + } -double pa_atod(const char* str, const String* problem_source=0); -int pa_atoi(const char* str, int base=10, const String* problem_source=0); -unsigned int pa_atoui(const char *str, int base=10, const String* problem_source=0); -unsigned long long int pa_atoul(const char *str, int base=10, const String* problem_source=0); + inline element_type get(size_t index) const { + element_type result=Array::get(index); + assert(result != NULL); + return result; + } +}; +#endif + +// generally useful /// this is result of pos functions which mean that substr were not found #define STRING_NOT_FOUND ((size_t)-1) @@ -359,8 +374,8 @@ public: void dump() const; Body(): body(CORD_EMPTY) INIT_HASH_CODE(0) INIT_LENGTH(0) {} - Body(const char *abody): body(AS_CORD(abody)) INIT_HASH_CODE(0) INIT_LENGTH(0) {} - Body(CORD abody, uint ahash_code): body(abody) INIT_HASH_CODE(ahash_code) INIT_LENGTH(0) {} + explicit Body(const char *abody): body(AS_CORD(abody)) INIT_HASH_CODE(0) INIT_LENGTH(0) {} + explicit Body(CORD abody, uint ahash_code): body(abody) INIT_HASH_CODE(ahash_code) INIT_LENGTH(0) {} explicit Body(C ac): body(AS_CORD(ac.str)) INIT_HASH_CODE(0) INIT_LENGTH(ac.length) {} explicit Body(CORD abody): body(abody) INIT_HASH_CODE(0) INIT_LENGTH(0) { #ifdef CORD_CAT_OPTIMIZATION @@ -381,8 +396,7 @@ public: #endif } - - static Body Format(int value); + static Body uitoa(size_t aindex); void clear() { ZERO_LENGTH ZERO_HASH_CODE body=CORD_EMPTY; } @@ -633,17 +647,14 @@ public: 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 - 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; - /// 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 { - return body.pos(c, this_offset); - } + /// return position of substr in string, -1 means "not found" [const char* version] + size_t pos(const char* substr, size_t this_offset=0) const { return body.pos(substr, this_offset); } + size_t pos(const Body substr, size_t this_offset=0) const { return body.pos(substr, this_offset); } + size_t pos(const String& substr, size_t this_offset=0) const { return body.pos(substr.body, this_offset); } + size_t pos(char c, size_t this_offset=0) const { return body.pos(c, this_offset); } + /// ignore lang if it's L_UNSPECIFIED, otherwise look for substring that lies in ONE fragment in THAT lang + size_t pos(const Body substr, size_t this_offset, Language lang) const; + size_t pos(const String& substr, size_t this_offset, Language lang) 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 {