diff options
Diffstat (limited to 'intern')
-rw-r--r-- | intern/string/STR_String.h | 50 | ||||
-rw-r--r-- | intern/string/intern/STR_String.cpp | 341 |
2 files changed, 194 insertions, 197 deletions
diff --git a/intern/string/STR_String.h b/intern/string/STR_String.h index 98de5be9647..6e9f6007e0b 100644 --- a/intern/string/STR_String.h +++ b/intern/string/STR_String.h @@ -66,8 +66,8 @@ typedef const STR_String& rcSTR_String; typedef unsigned char byte; /** - * Smart String Value class. Is used by parser when an expression tree is build containing string. -*/ + * Smart String Value class. Is used by parser when an expression tree is build containing string. + */ class STR_String { @@ -85,16 +85,16 @@ public: explicit STR_String(dword val); explicit STR_String(float val); explicit STR_String(double val); - inline ~STR_String() { delete[] pData; } + inline ~STR_String() { delete[] this->m_data; } // Operations STR_String& Format(const char *fmt, ...); // Set formatted text to string STR_String& FormatAdd(const char *fmt, ...); // Add formatted text to string - inline void Clear() { Len = pData[0] = 0; } + inline void Clear() { this->m_len = this->m_data[0] = 0; } inline const STR_String & Reverse() { - for (int i1 = 0, i2 = Len - 1; i1 < i2; i1++, i2--) { - std::swap(pData[i1], pData[i2]); + for (int i1 = 0, i2 = this->m_len - 1; i1 < i2; i1++, i2--) { + std::swap(this->m_data[i1], this->m_data[i2]); } return *this; } @@ -102,28 +102,28 @@ public: // Properties bool IsUpper() const; bool IsLower() const; - inline bool IsEmpty() const { return Len == 0; } - inline int Length() const { return Len; } + inline bool IsEmpty() const { return this->m_len == 0; } + inline int Length() const { return this->m_len; } // Data access - inline STR_String& SetLength(int len) { AllocBuffer(len, true); Len=len; pData[len]=0; return *this; } - inline char GetAt(int pos) const { assertd(pos<Len); return pData[pos]; } - inline void SetAt(int pos, char c) { assertd(pos<Len); pData[pos]=c; } + inline STR_String& SetLength(int len) { AllocBuffer(len, true); this->m_len = len; this->m_data[len] = 0; return *this; } + inline char GetAt(int pos) const { assertd(pos<this->m_len); return this->m_data[pos]; } + inline void SetAt(int pos, char c) { assertd(pos<this->m_len); this->m_data[pos] = c; } inline void SetAt(int pos, rcSTR_String str); inline void SetAt(int pos, int num, rcSTR_String str); void Replace(int pos, rcSTR_String str); void Replace(int pos, int num, rcSTR_String str); // Substrings - inline STR_String Left(int num) const { num = (num < Len ? num:Len ); return STR_String(pData, num); } - inline STR_String Right(int num) const { num = (num < Len ? num:Len ); return STR_String(pData+Len-num, num); } - inline STR_String Mid(int pos, int num = INT_MAX) const { pos = (pos < Len ? pos:Len ); num = (num < (Len - pos) ? num : (Len - pos)); return STR_String(pData+pos, num); } + inline STR_String Left(int num) const { num = (num < this->m_len ? num:this->m_len ); return STR_String(this->m_data, num); } + inline STR_String Right(int num) const { num = (num < this->m_len ? num:this->m_len ); return STR_String(this->m_data + this->m_len - num, num); } + inline STR_String Mid(int pos, int num = INT_MAX) const { pos = (pos < this->m_len ? pos:this->m_len ); num = (num < (this->m_len - pos) ? num : (this->m_len - pos)); return STR_String(this->m_data + pos, num); } // Comparison int Compare(rcSTR_String rhs) const; int CompareNoCase(rcSTR_String rhs) const; - inline bool IsEqual(rcSTR_String rhs) const { return (Compare(rhs) == 0); } - inline bool IsEqualNoCase(rcSTR_String rhs) const { return (CompareNoCase(rhs) == 0); } + inline bool IsEqual(rcSTR_String rhs) const { return (Compare(rhs) == 0); } + inline bool IsEqualNoCase(rcSTR_String rhs) const { return (CompareNoCase(rhs) == 0); } // Search/replace int Find(char c, int pos = 0) const; @@ -148,12 +148,12 @@ public: STR_String& TrimQuotes(); // Conversions -// inline operator char*() { return pData; } - inline operator const char *() const { return pData; } - inline char *Ptr() { return pData; } - inline const char *ReadPtr() const { return pData; } - inline float ToFloat() const { float x=(float)(atof(pData)); return x; } - inline int ToInt() const { return atoi(pData); } +// inline operator char*() { return this->m_data; } + inline operator const char *() const { return this->m_data; } + inline char *Ptr() { return this->m_data; } + inline const char *ReadPtr() const { return this->m_data; } + inline float ToFloat() const { float x=(float)(atof(this->m_data)); return x; } + inline int ToInt() const { return atoi(this->m_data); } // Operators inline rcSTR_String operator=(const byte *rhs) { return Copy((const char *)rhs, strlen((const char *)rhs)); } @@ -198,9 +198,9 @@ protected: static bool isUpper(char c) { return (c>='A') && (c <= 'Z'); } static bool isSpace(char c) { return (c==' ') || (c=='\t'); } - char *pData; // -> STR_String data - int Len; // Data length - int Max; // Space in data buffer + char *m_data; // -> STR_String data + int m_len; //z Data length + int m_max; // Space in data buffer #ifdef WITH_CXX_GUARDEDALLOC diff --git a/intern/string/intern/STR_String.cpp b/intern/string/intern/STR_String.cpp index bea6e88cfff..4b2261e89f9 100644 --- a/intern/string/intern/STR_String.cpp +++ b/intern/string/intern/STR_String.cpp @@ -27,14 +27,9 @@ /** \file string/intern/STR_String.cpp * \ingroup string - */ - - -/** - + * * Copyright (C) 2001 NaN Technologies B.V. * This file was formerly known as: GEN_StdString.cpp. - * @date April, 25, 2001 */ #include <stdio.h> @@ -51,17 +46,18 @@ Construction / destruction -------------------------------------------------------------------------------------------------*/ - +#define STR_STRING_SIZE_DEFAULT_WORD 32 /* default size for a new word */ +#define STR_STRING_SIZE_DEFAULT_CHAR 9 /* default size for a new char */ // // Construct an empty string // STR_String::STR_String() : - pData(new char[32]), - Len(0), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_len(0), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - pData[0] = 0; + this->m_data[0] = 0; } @@ -70,12 +66,12 @@ STR_String::STR_String() : // Construct a string of one character // STR_String::STR_String(char c) : - pData(new char[9]), - Len(1), - Max(9) + m_data(new char[STR_STRING_SIZE_DEFAULT_CHAR]), + m_len(1), + m_max(STR_STRING_SIZE_DEFAULT_CHAR) { - pData[0] = c; - pData[1] = 0; + this->m_data[0] = c; + this->m_data[1] = 0; } @@ -84,13 +80,13 @@ STR_String::STR_String(char c) : // Construct a string of multiple repeating characters // STR_String::STR_String(char c, int len) : - pData(new char[len + 8]), - Len(len), - Max(len + 8) + m_data(new char[len + 8]), + m_len(len), + m_max(len + 8) { - assertd(pData != NULL); - memset(pData, c, len); - pData[len] = 0; + assertd(this->m_data != NULL); + memset(this->m_data, c, len); + this->m_data[len] = 0; } @@ -102,17 +98,17 @@ STR_String::STR_String(char c, int len) : STR_String::STR_String(const char *str) { if (str) { - Len = ::strlen(str); - Max = Len + 8; - pData = new char[Max]; - assertd(pData != NULL); - ::memcpy(pData, str, Len); - pData[Len] = 0; + this->m_len = ::strlen(str); + this->m_max = this->m_len + 8; + this->m_data = new char[this->m_max]; + assertd(this->m_data != NULL); + ::memcpy(this->m_data, str, this->m_len); + this->m_data[this->m_len] = 0; } else { - pData = 0; - Len = 0; - Max = 8; + this->m_data = 0; + this->m_len = 0; + this->m_max = 8; } } @@ -122,13 +118,13 @@ STR_String::STR_String(const char *str) // Construct a string from a pointer-to-ASCII-string and a length // STR_String::STR_String(const char *str, int len) : - pData(new char[len + 8]), - Len(len), - Max(len + 8) + m_data(new char[len + 8]), + m_len(len), + m_max(len + 8) { - assertd(pData != NULL); - memcpy(pData, str, len); - pData[len] = 0; + assertd(this->m_data != NULL); + memcpy(this->m_data, str, len); + this->m_data[len] = 0; } @@ -137,14 +133,14 @@ STR_String::STR_String(const char *str, int len) : // Construct a string from another string // STR_String::STR_String(rcSTR_String str) : - pData(new char[str.Length() + 8]), - Len(str.Length()), - Max(str.Length() + 8) + m_data(new char[str.Length() + 8]), + m_len(str.Length()), + m_max(str.Length() + 8) { - assertd(pData != NULL); - assertd(str.pData != NULL); - memcpy(pData, str.pData, str.Length()); - pData[str.Length()] = 0; + assertd(this->m_data != NULL); + assertd(str.this->m_data != NULL); + memcpy(this->m_data, str.ReadPtr(), str.Length()); + this->m_data[str.Length()] = 0; } @@ -153,14 +149,14 @@ STR_String::STR_String(rcSTR_String str) : // Construct a string from the first number of characters in another string // STR_String::STR_String(rcSTR_String str, int len) : - pData(new char[len + 8]), - Len(len), - Max(len + 8) + m_data(new char[len + 8]), + m_len(len), + m_max(len + 8) { - assertd(pData != NULL); - assertd(str.pData != NULL); - memcpy(pData, str.pData, str.Length()); - pData[str.Length()] = 0; + assertd(this->m_data != NULL); + assertd(str.this->m_data != NULL); + memcpy(this->m_data, str.ReadPtr(), str.Length()); + this->m_data[str.Length()] = 0; } @@ -169,14 +165,14 @@ STR_String::STR_String(rcSTR_String str, int len) : // Create a string by concatenating two sources // STR_String::STR_String(const char *src1, int len1, const char *src2, int len2) : - pData(new char[len1 + len2 + 8]), - Len(len1 + len2), - Max(len1 + len2 + 8) + m_data(new char[len1 + len2 + 8]), + m_len(len1 + len2), + m_max(len1 + len2 + 8) { - assertd(pData != NULL); - memcpy(pData, src1, len1); - memcpy(pData + len1, src2, len2); - pData[len1 + len2] = 0; + assertd(this->m_data != NULL); + memcpy(this->m_data, src1, len1); + memcpy(this->m_data + len1, src2, len2); + this->m_data[len1 + len2] = 0; } @@ -185,11 +181,11 @@ STR_String::STR_String(const char *src1, int len1, const char *src2, int len2) : // Create a string with an integer value // STR_String::STR_String(int val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%d", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%d", val); } @@ -199,11 +195,11 @@ STR_String::STR_String(int val) : // Create a string with a dword value // STR_String::STR_String(dword val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%lu", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%lu", val); } @@ -212,11 +208,11 @@ STR_String::STR_String(dword val) : // Create a string with a floating point value // STR_String::STR_String(float val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%g", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%g", val); } @@ -225,11 +221,11 @@ STR_String::STR_String(float val) : // Create a string with a double value // STR_String::STR_String(double val) : - pData(new char[32]), - Max(32) + m_data(new char[STR_STRING_SIZE_DEFAULT_WORD]), + m_max(STR_STRING_SIZE_DEFAULT_WORD) { - assertd(pData != NULL); - Len = sprintf(pData, "%g", val); + assertd(this->m_data != NULL); + this->m_len = sprintf(this->m_data, "%g", val); } @@ -246,17 +242,19 @@ STR_String::STR_String(double val) : void STR_String::AllocBuffer(int len, bool keep_contents) { // Check if we have enough space - if (len + 1 <= Max) return; + if (len + 1 <= this->m_max) return; // Reallocate string char *new_data = new char[len + 8]; - if (keep_contents) memcpy(new_data, pData, Len); - delete[] pData; + if (keep_contents) { + memcpy(new_data, this->m_data, this->m_len); + } + delete[] this->m_data; // Accept new data - Max = len + 8; - pData = new_data; - assertd(pData != NULL); + this->m_max = len + 8; + this->m_data = new_data; + assertd(this->m_data != NULL); } @@ -274,12 +272,12 @@ STR_String& STR_String::Format(const char *fmt, ...) { AllocBuffer(2048, false); - assertd(pData != NULL); + assertd(this->m_data != NULL); // Expand arguments and format to string va_list args; va_start(args, fmt); - Len = vsprintf(pData, fmt, args); - assertd(Len <= 2048); + this->m_len = vsprintf(this->m_data, fmt, args); + assertd(this->m_len <= 2048); va_end(args); return *this; @@ -294,12 +292,12 @@ STR_String& STR_String::FormatAdd(const char *fmt, ...) { AllocBuffer(2048, false); - assertd(pData != NULL); + assertd(this->m_data != NULL); // Expand arguments and format to string va_list args; va_start(args, fmt); - Len += vsprintf(pData + Len, fmt, args); - assertd(Len <= 2048); + this->m_len += vsprintf(this->m_data + this->m_len, fmt, args); + assertd(this->m_len <= 2048); va_end(args); return *this; @@ -318,8 +316,8 @@ STR_String& STR_String::FormatAdd(const char *fmt, ...) // bool STR_String::IsUpper() const { - for (int i = 0; i < Len; i++) - if (isLower(pData[i])) + for (int i = 0; i < this->m_len; i++) + if (isLower(this->m_data[i])) return false; return true; @@ -332,8 +330,8 @@ bool STR_String::IsUpper() const // bool STR_String::IsLower() const { - for (int i = 0; i < Len; i++) - if (isUpper(pData[i])) + for (int i = 0; i < this->m_len; i++) + if (isUpper(this->m_data[i])) return false; return true; @@ -353,10 +351,10 @@ bool STR_String::IsLower() const int STR_String::Find(char c, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strchr(pData + pos, c); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strchr(this->m_data + pos, c); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -367,10 +365,10 @@ int STR_String::Find(char c, int pos) const int STR_String::Find(const char *str, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strstr(pData + pos, str); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strstr(this->m_data + pos, str); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -381,10 +379,10 @@ int STR_String::Find(const char *str, int pos) const int STR_String::Find(rcSTR_String str, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strstr(pData + pos, str.ReadPtr()); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strstr(this->m_data + pos, str.ReadPtr()); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -394,9 +392,9 @@ int STR_String::Find(rcSTR_String str, int pos) const // int STR_String::RFind(char c) const { - assertd(pData != NULL); - char *pos = strrchr(pData, c); - return (pos) ? (pos - pData) : -1; + assertd(this->m_data != NULL); + char *pos = strrchr(this->m_data, c); + return (pos) ? (pos - this->m_data) : -1; } @@ -407,10 +405,10 @@ int STR_String::RFind(char c) const int STR_String::FindOneOf(const char *set, int pos) const { assertd(pos >= 0); - assertd(Len == 0 || pos < Len); - assertd(pData != NULL); - char *find_pos = strpbrk(pData + pos, set); - return (find_pos) ? (find_pos - pData) : -1; + assertd(this->m_len == 0 || pos < this->m_len); + assertd(this->m_data != NULL); + char *find_pos = strpbrk(this->m_data + pos, set); + return (find_pos) ? (find_pos - this->m_data) : -1; } @@ -425,16 +423,16 @@ void STR_String::Replace(int pos, rcSTR_String str) if (str.Length() < 1) { // Remove one character from the string - memcpy(pData + pos, pData + pos + 1, Len - pos); + memcpy(this->m_data + pos, this->m_data + pos + 1, this->m_len - pos); } else { // Insert zero or more characters into the string - AllocBuffer(Len + str.Length() - 1, true); - if (str.Length() != 1) memcpy(pData + pos + str.Length(), pData + pos + 1, Length() - pos); - memcpy(pData + pos, str.ReadPtr(), str.Length()); + AllocBuffer(this->m_len + str.Length() - 1, true); + if (str.Length() != 1) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + 1, Length() - pos); + memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } - Len += str.Length() - 1; + this->m_len += str.Length() - 1; } @@ -451,17 +449,17 @@ void STR_String::Replace(int pos, int num, rcSTR_String str) if (str.Length() < num) { // Remove some data from the string by replacement - memcpy(pData + pos + str.Length(), pData + pos + num, Len - pos - num + 1); - memcpy(pData + pos, str.ReadPtr(), str.Length()); + memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, this->m_len - pos - num + 1); + memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } else { // Insert zero or more characters into the string - AllocBuffer(Len + str.Length() - num, true); - if (str.Length() != num) memcpy(pData + pos + str.Length(), pData + pos + num, Length() - pos - num + 1); - memcpy(pData + pos, str.ReadPtr(), str.Length()); + AllocBuffer(this->m_len + str.Length() - num, true); + if (str.Length() != num) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, Length() - pos - num + 1); + memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } - Len += str.Length() - num; + this->m_len += str.Length() - num; } @@ -477,7 +475,7 @@ void STR_String::Replace(int pos, int num, rcSTR_String str) // int STR_String::Compare(rcSTR_String rhs) const { - return strcmp(pData, rhs.pData); + return strcmp(this->ReadPtr(), rhs.ReadPtr()); } @@ -488,9 +486,9 @@ int STR_String::Compare(rcSTR_String rhs) const int STR_String::CompareNoCase(rcSTR_String rhs) const { #ifdef WIN32 - return stricmp(pData, rhs.pData); + return stricmp(this->ReadPtr(), rhs.ReadPtr()); #else - return strcasecmp(pData, rhs.pData); + return strcasecmp(this->ReadPtr(), rhs.ReadPtr()); #endif } @@ -507,12 +505,12 @@ int STR_String::CompareNoCase(rcSTR_String rhs) const // STR_String& STR_String::Upper() { - assertd(pData != NULL); + assertd(this->m_data != NULL); #ifdef WIN32 - _strupr(pData); + _strupr(this->m_data); #else - for (int i = 0; i < Len; i++) - pData[i] = (pData[i] >= 'a' && pData[i] <= 'z') ? pData[i] + 'A' - 'a' : pData[i]; + for (int i = 0; i < this->m_len; i++) + this->m_data[i] = (this->m_data[i] >= 'a' && this->m_data[i] <= 'z') ? this->m_data[i] + 'A' - 'a' : this->m_data[i]; #endif return *this; } @@ -524,12 +522,12 @@ STR_String& STR_String::Upper() // STR_String& STR_String::Lower() { - assertd(pData != NULL); + assertd(this->m_data != NULL); #ifdef WIN32 - _strlwr(pData); + _strlwr(this->m_data); #else - for (int i = 0; i < Len; i++) - pData[i] = (pData[i] >= 'A' && pData[i] <= 'Z') ? pData[i] + 'a' - 'A' : pData[i]; + for (int i = 0; i < this->m_len; i++) + this->m_data[i] = (this->m_data[i] >= 'A' && this->m_data[i] <= 'Z') ? this->m_data[i] + 'a' - 'A' : this->m_data[i]; #endif return *this; } @@ -541,15 +539,15 @@ STR_String& STR_String::Lower() // STR_String& STR_String::Capitalize() { - assertd(pData != NULL); + assertd(this->m_data != NULL); #ifdef WIN32 - if (Len > 0) pData[0] = toupper(pData[0]); - if (Len > 1) _strlwr(pData + 1); + if (this->m_len > 0) this->m_data[0] = toupper(this->m_data[0]); + if (this->m_len > 1) _strlwr(this->m_data + 1); #else - if (Len > 0) - pData[0] = (pData[0] >= 'A' && pData[0] <= 'A') ? pData[0] + 'a' - 'A' : pData[0]; - for (int i = 1; i < Len; i++) - pData[i] = (pData[i] >= 'a' && pData[i] <= 'z') ? pData[i] + 'A' - 'a' : pData[i]; + if (this->m_len > 0) + this->m_data[0] = (this->m_data[0] >= 'A' && this->m_data[0] <= 'A') ? this->m_data[0] + 'a' - 'A' : this->m_data[0]; + for (int i = 1; i < this->m_len; i++) + this->m_data[i] = (this->m_data[i] >= 'a' && this->m_data[i] <= 'z') ? this->m_data[i] + 'A' - 'a' : this->m_data[i]; #endif return *this; } @@ -562,10 +560,10 @@ STR_String& STR_String::Capitalize() STR_String& STR_String::TrimLeft() { int skip; - assertd(pData != NULL); - for (skip = 0; isSpace(pData[skip]); skip++, Len--) + assertd(this->m_data != NULL); + for (skip = 0; isSpace(this->m_data[skip]); skip++, this->m_len--) {}; - memmove(pData, pData + skip, Len + 1); + memmove(this->m_data, this->m_data + skip, this->m_len + 1); return *this; } @@ -576,9 +574,9 @@ STR_String& STR_String::TrimLeft() // STR_String& STR_String::TrimRight() { - assertd(pData != NULL); - while (Len && isSpace(pData[Len - 1])) Len--; - pData[Len] = 0; + assertd(this->m_data != NULL); + while (this->m_len && isSpace(this->m_data[this->m_len - 1])) this->m_len--; + this->m_data[this->m_len] = 0; return *this; } @@ -602,10 +600,10 @@ STR_String& STR_String::Trim() STR_String& STR_String::TrimLeft(char *set) { int skip; - assertd(pData != NULL); - for (skip = 0; Len && strchr(set, pData[skip]); skip++, Len--) + assertd(this->m_data != NULL); + for (skip = 0; this->m_len && strchr(set, this->m_data[skip]); skip++, this->m_len--) {}; - memmove(pData, pData + skip, Len + 1); + memmove(this->m_data, this->m_data + skip, this->m_len + 1); return *this; } @@ -616,9 +614,9 @@ STR_String& STR_String::TrimLeft(char *set) // STR_String& STR_String::TrimRight(char *set) { - assertd(pData != NULL); - while (Len && strchr(set, pData[Len - 1])) Len--; - pData[Len] = 0; + assertd(this->m_data != NULL); + while (this->m_len && strchr(set, this->m_data[this->m_len - 1])) this->m_len--; + this->m_data[this->m_len] = 0; return *this; } @@ -642,11 +640,11 @@ STR_String& STR_String::Trim(char *set) STR_String& STR_String::TrimQuotes() { // Trim quotes if they are on both sides of the string - assertd(pData != NULL); - if ((Len >= 2) && (pData[0] == '\"') && (pData[Len - 1] == '\"')) + assertd(this->m_data != NULL); + if ((this->m_len >= 2) && (this->m_data[0] == '\"') && (this->m_data[this->m_len - 1] == '\"')) { - memmove(pData, pData + 1, Len - 2 + 1); - Len -= 2; + memmove(this->m_data, this->m_data + 1, this->m_len - 2 + 1); + this->m_len -= 2; } return *this; } @@ -666,12 +664,12 @@ rcSTR_String STR_String::Copy(const char *src, int len) { assertd(len >= 0); assertd(src); - assertd(pData != NULL); + assertd(this->m_data != NULL); AllocBuffer(len, false); - Len = len; - memcpy(pData, src, len); - pData[Len] = 0; + this->m_len = len; + memcpy(this->m_data, src, len); + this->m_data[this->m_len] = 0; return *this; } @@ -683,15 +681,15 @@ rcSTR_String STR_String::Copy(const char *src, int len) // rcSTR_String STR_String::Concat(const char *data, int len) { - assertd(Len >= 0); + assertd(this->m_len >= 0); assertd(len >= 0); assertd(data); - assertd(pData != NULL); + assertd(this->m_data != NULL); - AllocBuffer(Len + len, true); - memcpy(pData + Len, data, len); - Len += len; - pData[Len] = 0; + AllocBuffer(this->m_len + len, true); + memcpy(this->m_data + this->m_len, data, len); + this->m_len += len; + this->m_data[this->m_len] = 0; return *this; } @@ -702,8 +700,7 @@ std::vector<STR_String> STR_String::Explode(char c) const STR_String lcv = *this; std::vector<STR_String> uc; - while (lcv.Length()) - { + while (lcv.Length()) { int pos = lcv.Find(c); if (pos < 0) { uc.push_back(lcv); @@ -729,16 +726,16 @@ int STR_String::Serialize(pCStream stream) int ln; stream->Read(&ln, sizeof(ln)); AllocBuffer(ln, false); - stream->Read(pData, ln); - pData[ln] = '\0'; - Len = ln; + stream->Read(this->m_data, ln); + this->m_data[ln] = '\0'; + this->m_len = ln; } else { - stream->Write(&Len, sizeof(Len)); - stream->Write(pData, Len); + stream->Write(&this->m_len, sizeof(this->m_len)); + stream->Write(this->m_data, this->m_len); } - return Len + sizeof(Len); + return this->m_len + sizeof(this->m_len); } #endif |