|
|
@@ -39,239 +39,6 @@ namespace string
|
|
|
|
|
|
const char* const EMPTY = "";
|
|
|
|
|
|
-bool is_alpha(char c);
|
|
|
-bool is_digit(char c);
|
|
|
-bool is_upper(char c);
|
|
|
-bool is_lower(char c);
|
|
|
-bool is_whitespace(char c);
|
|
|
-
|
|
|
-size_t strlen(const char* str);
|
|
|
-const char* strstr(const char* str1, const char* str2);
|
|
|
-int32_t strcmp(const char* str1, const char* str2);
|
|
|
-char* strcpy(char* dest, const char* src);
|
|
|
-char* strncpy(char* dest, const char* src, size_t len);
|
|
|
-char* strcat(char* dest, const char* src);
|
|
|
-char* strncat(char* dest, const char* src, size_t len);
|
|
|
-
|
|
|
-const char* begin(const char* str);
|
|
|
-const char* end(const char* str);
|
|
|
-
|
|
|
-const char* find_first(const char* str, char c);
|
|
|
-const char* find_last(const char* str, char c);
|
|
|
-void substring(const char* begin, const char* end, char* out, size_t len);
|
|
|
-
|
|
|
-//inline void MakeLower()
|
|
|
-//{
|
|
|
-// for (uint32_t i = 0; i < mLength; i++)
|
|
|
-// {
|
|
|
-// if (is_upper(mText[i]))
|
|
|
-// {
|
|
|
-// mText[i] += 32;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
-//inline void MakeUpper()
|
|
|
-//{
|
|
|
-// for (uint32_t i = 0; i < mLength; i++)
|
|
|
-// {
|
|
|
-// if (is_lower(mText[i]))
|
|
|
-// {
|
|
|
-// mText[i] -= 32;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
-//inline bool StartsWith(const Str& begin) const
|
|
|
-//{
|
|
|
-// if (mLength < begin.mLength)
|
|
|
-// return false;
|
|
|
-
|
|
|
-// for (uint32_t i = 0; i < begin.mLength; i++)
|
|
|
-// {
|
|
|
-// if (mText[i] != begin.mText[i])
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-
|
|
|
-// return true;
|
|
|
-//}
|
|
|
-
|
|
|
-//inline bool EndsWith(const Str& end) const
|
|
|
-//{
|
|
|
-// if (mLength < end.mLength)
|
|
|
-// return false;
|
|
|
-
|
|
|
-// uint32_t beginIndex = mLength - end.mLength;
|
|
|
-// for (uint32_t i = beginIndex; i < mLength; i++)
|
|
|
-// {
|
|
|
-// if (mText[i] != end.mText[i - beginIndex])
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-
|
|
|
-// return true;
|
|
|
-//}
|
|
|
-
|
|
|
-//inline int32_t Find(const Str& Str) const
|
|
|
-//{
|
|
|
-// bool found = true;
|
|
|
-
|
|
|
-// for (uint32_t i = 0; i < mLength; i++)
|
|
|
-// {
|
|
|
-// if (mLength - i < Str.mLength)
|
|
|
-// {
|
|
|
-// return -1;
|
|
|
-// }
|
|
|
-
|
|
|
-// for (uint32_t j = 0; j < Str.mLength; j++)
|
|
|
-// {
|
|
|
-// if (mText[i + j] != Str.mText[j])
|
|
|
-// {
|
|
|
-// found = false;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// if (found)
|
|
|
-// {
|
|
|
-// return i;
|
|
|
-// }
|
|
|
-
|
|
|
-// found = true;
|
|
|
-// }
|
|
|
-
|
|
|
-// return -1;
|
|
|
-//}
|
|
|
-
|
|
|
-//inline void Remove(uint32_t start, uint32_t end)
|
|
|
-//{
|
|
|
-// CE_ASSERT(start <= mLength);
|
|
|
-// CE_ASSERT(end <= mLength);
|
|
|
-// CE_ASSERT(start <= end);
|
|
|
-// uint32_t len = end - start;
|
|
|
-// char* tmp = new char[mLength - len + 1];
|
|
|
-
|
|
|
-// uint32_t i;
|
|
|
-// for (i = 0; i < start; i++)
|
|
|
-// {
|
|
|
-// tmp[i] = mText[i];
|
|
|
-// }
|
|
|
-// i += len;
|
|
|
-// for (; i < mLength; i++)
|
|
|
-// {
|
|
|
-// tmp[i - len] = mText[i];
|
|
|
-// }
|
|
|
-// mLength = mLength - len;
|
|
|
-// tmp[mLength] = '\0';
|
|
|
-// delete[] mText;
|
|
|
-// mText = tmp;
|
|
|
-//}
|
|
|
-
|
|
|
-////! Replaces all the occurencies of the given character with the new one
|
|
|
-//inline void Replace(char toFind, char toReplace)
|
|
|
-//{
|
|
|
-// for (uint32_t i = 0; i < mLength; i++)
|
|
|
-// {
|
|
|
-// if (mText[i] == toFind)
|
|
|
-// mText[i] = toReplace;
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
-////! Replaces all the occurencies of the given Str with the new one
|
|
|
-//inline void Replace(const Str& toFind, const Str& toReplace)
|
|
|
-//{
|
|
|
-// CE_ASSERT(toReplace.mLength > 0);
|
|
|
-// if (mLength < toReplace.mLength)
|
|
|
-// return;
|
|
|
-
|
|
|
-// List<char> tmp(get_default_allocator());
|
|
|
-
|
|
|
-// uint32_t i;
|
|
|
-// for (i = 0; i < mLength - (toFind.mLength - 1); i++)
|
|
|
-// {
|
|
|
-// bool found = true;
|
|
|
-// for(uint32_t j = 0; j < toFind.mLength; j++)
|
|
|
-// if (mText[i + j] != toFind.mText[j])
|
|
|
-// {
|
|
|
-// found = false;
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// if (found)
|
|
|
-// {
|
|
|
-// for(uint32_t j = 0; j < toReplace.mLength; j++)
|
|
|
-// tmp.push_back(toReplace.mText[j]);
|
|
|
-// i += toFind.mLength-1;
|
|
|
-// }
|
|
|
-// else
|
|
|
-// tmp.push_back(mText[i]);
|
|
|
-// }
|
|
|
-
|
|
|
-// while(i <= mLength)
|
|
|
-// {
|
|
|
-// tmp.push_back(mText[i]);
|
|
|
-// i++;
|
|
|
-// }
|
|
|
-
|
|
|
-// *this = tmp.begin();
|
|
|
-//}
|
|
|
-
|
|
|
-//inline void Split(char ch, List<Str>& split) const
|
|
|
-//{
|
|
|
-// uint32_t lastChar = 0;
|
|
|
-// uint32_t strPtr = 0;
|
|
|
-// uint32_t charCount = 0;
|
|
|
-
|
|
|
-// while (strPtr <= mLength)
|
|
|
-// {
|
|
|
-// lastChar = strPtr;
|
|
|
-
|
|
|
-// while (mText[strPtr] != ch && mText[strPtr] != '\0')
|
|
|
-// {
|
|
|
-// strPtr++;
|
|
|
-// charCount++;
|
|
|
-// }
|
|
|
-
|
|
|
-// if (charCount > 0)
|
|
|
-// {
|
|
|
-// split.push_back(this->GetSubstring(lastChar, lastChar + charCount));
|
|
|
-// }
|
|
|
-
|
|
|
-// charCount = 0;
|
|
|
-// strPtr++;
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
-//inline Str Trim()
|
|
|
-//{
|
|
|
-// int32_t beginIndex = 0;
|
|
|
-// int32_t endIndex = mLength - 1;
|
|
|
-
|
|
|
-// while (is_whitespace(mText[beginIndex]))
|
|
|
-// {
|
|
|
-// beginIndex++;
|
|
|
-// }
|
|
|
-
|
|
|
-// while (is_whitespace(mText[endIndex]))
|
|
|
-// {
|
|
|
-// endIndex--;
|
|
|
-// }
|
|
|
-
|
|
|
-// return GetSubstring(beginIndex, endIndex + 1);
|
|
|
-//}
|
|
|
-
|
|
|
-//inline int32_t GetOccurrenceCount(char ch) const
|
|
|
-//{
|
|
|
-// int32_t count = 0;
|
|
|
-
|
|
|
-// for (uint32_t i = 0; i < mLength; i++)
|
|
|
-// {
|
|
|
-// if (mText[i] == ch)
|
|
|
-// {
|
|
|
-// count++;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// return count;
|
|
|
-//}
|
|
|
-
|
|
|
//-----------------------------------------------------------------------------
|
|
|
inline bool is_alpha(char c)
|
|
|
{
|
|
|
@@ -331,16 +98,13 @@ inline int32_t strcmp(const char* str1, const char* str2)
|
|
|
return ::strcmp(str1, str2);
|
|
|
}
|
|
|
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-inline char* strcpy(char* dest, const char* src)
|
|
|
-{
|
|
|
- return ::strcpy(dest, src);
|
|
|
-}
|
|
|
-
|
|
|
//-----------------------------------------------------------------------------
|
|
|
inline char* strncpy(char* dest, const char* src, size_t len)
|
|
|
{
|
|
|
- return ::strncpy(dest, src, len);
|
|
|
+ char* ret = ::strncpy(dest, src, len);
|
|
|
+ dest[len - 1] = '\0';
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|