diff options
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/fx_basic_bstring.cpp | 28 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_wstring.cpp | 28 | ||||
-rw-r--r-- | core/fxcrt/include/fx_string.h | 40 |
3 files changed, 34 insertions, 62 deletions
diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp index 10bc05bcc5..08f5dca664 100644 --- a/core/fxcrt/fx_basic_bstring.cpp +++ b/core/fxcrt/fx_basic_bstring.cpp @@ -217,30 +217,30 @@ const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteStringC& str) { ConcatInPlace(str.GetLength(), str.GetCStr()); return *this; } -bool CFX_ByteString::Equal(const char* ptr) const { - if (!m_pData) { - return !ptr || ptr[0] == '\0'; - } - if (!ptr) { +bool CFX_ByteString::operator==(const char* ptr) const { + if (!m_pData) + return !ptr || !ptr[0]; + + if (!ptr) return m_pData->m_nDataLength == 0; - } + return FXSYS_strlen(ptr) == m_pData->m_nDataLength && FXSYS_memcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; } -bool CFX_ByteString::Equal(const CFX_ByteStringC& str) const { - if (!m_pData) { +bool CFX_ByteString::operator==(const CFX_ByteStringC& str) const { + if (!m_pData) return str.IsEmpty(); - } + return m_pData->m_nDataLength == str.GetLength() && FXSYS_memcmp(m_pData->m_String, str.GetCStr(), str.GetLength()) == 0; } -bool CFX_ByteString::Equal(const CFX_ByteString& other) const { - if (IsEmpty()) { +bool CFX_ByteString::operator==(const CFX_ByteString& other) const { + if (IsEmpty()) return other.IsEmpty(); - } - if (other.IsEmpty()) { + + if (other.IsEmpty()) return false; - } + return other.m_pData->m_nDataLength == m_pData->m_nDataLength && FXSYS_memcmp(other.m_pData->m_String, m_pData->m_String, m_pData->m_nDataLength) == 0; diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp index 642b75eafe..9c17948c34 100644 --- a/core/fxcrt/fx_basic_wstring.cpp +++ b/core/fxcrt/fx_basic_wstring.cpp @@ -198,30 +198,30 @@ const CFX_WideString& CFX_WideString::operator+=(const CFX_WideStringC& str) { ConcatInPlace(str.GetLength(), str.GetPtr()); return *this; } -bool CFX_WideString::Equal(const wchar_t* ptr) const { - if (!m_pData) { - return !ptr || ptr[0] == L'\0'; - } - if (!ptr) { +bool CFX_WideString::operator==(const wchar_t* ptr) const { + if (!m_pData) + return !ptr || !ptr[0]; + + if (!ptr) return m_pData->m_nDataLength == 0; - } + return wcslen(ptr) == static_cast<size_t>(m_pData->m_nDataLength) && wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; } -bool CFX_WideString::Equal(const CFX_WideStringC& str) const { - if (!m_pData) { +bool CFX_WideString::operator==(const CFX_WideStringC& str) const { + if (!m_pData) return str.IsEmpty(); - } + return str.GetLength() == m_pData->m_nDataLength && wmemcmp(str.GetPtr(), m_pData->m_String, m_pData->m_nDataLength) == 0; } -bool CFX_WideString::Equal(const CFX_WideString& other) const { - if (IsEmpty()) { +bool CFX_WideString::operator==(const CFX_WideString& other) const { + if (IsEmpty()) return other.IsEmpty(); - } - if (other.IsEmpty()) { + + if (other.IsEmpty()) return false; - } + return other.m_pData->m_nDataLength == m_pData->m_nDataLength && wmemcmp(other.m_pData->m_String, m_pData->m_String, m_pData->m_nDataLength) == 0; diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h index 0aa34171c2..26000dd6c1 100644 --- a/core/fxcrt/include/fx_string.h +++ b/core/fxcrt/include/fx_string.h @@ -194,16 +194,11 @@ class CFX_ByteString { bool IsEmpty() const { return !GetLength(); } int Compare(const CFX_ByteStringC& str) const; - - bool Equal(const char* ptr) const; - bool Equal(const CFX_ByteStringC& str) const; - bool Equal(const CFX_ByteString& other) const; - bool EqualNoCase(const CFX_ByteStringC& str) const; - bool operator==(const char* ptr) const { return Equal(ptr); } - bool operator==(const CFX_ByteStringC& str) const { return Equal(str); } - bool operator==(const CFX_ByteString& other) const { return Equal(other); } + bool operator==(const char* ptr) const; + bool operator==(const CFX_ByteStringC& str) const; + bool operator==(const CFX_ByteString& other) const; bool operator!=(const char* ptr) const { return !(*this == ptr); } bool operator!=(const CFX_ByteStringC& str) const { return !(*this == str); } @@ -588,26 +583,20 @@ class CFX_WideString { void Empty(); bool IsEmpty() const { return !GetLength(); } - FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } const CFX_WideString& operator=(const FX_WCHAR* str); - const CFX_WideString& operator=(const CFX_WideString& stringSrc); - const CFX_WideString& operator=(const CFX_WideStringC& stringSrc); const CFX_WideString& operator+=(const FX_WCHAR* str); - const CFX_WideString& operator+=(FX_WCHAR ch); - const CFX_WideString& operator+=(const CFX_WideString& str); - const CFX_WideString& operator+=(const CFX_WideStringC& str); - bool operator==(const wchar_t* ptr) const { return Equal(ptr); } - bool operator==(const CFX_WideStringC& str) const { return Equal(str); } - bool operator==(const CFX_WideString& other) const { return Equal(other); } + bool operator==(const wchar_t* ptr) const; + bool operator==(const CFX_WideStringC& str) const; + bool operator==(const CFX_WideString& other) const; bool operator!=(const wchar_t* ptr) const { return !(*this == ptr); } bool operator!=(const CFX_WideStringC& str) const { return !(*this == str); } @@ -632,51 +621,34 @@ class CFX_WideString { void SetAt(FX_STRSIZE nIndex, FX_WCHAR ch); int Compare(const FX_WCHAR* str) const; - int Compare(const CFX_WideString& str) const; - int CompareNoCase(const FX_WCHAR* str) const; - bool Equal(const wchar_t* ptr) const; - bool Equal(const CFX_WideStringC& str) const; - bool Equal(const CFX_WideString& other) const; CFX_WideString Mid(FX_STRSIZE first) const; - CFX_WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const; - CFX_WideString Left(FX_STRSIZE count) const; - CFX_WideString Right(FX_STRSIZE count) const; FX_STRSIZE Insert(FX_STRSIZE index, FX_WCHAR ch); - FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1); void Format(const FX_WCHAR* lpszFormat, ...); - void FormatV(const FX_WCHAR* lpszFormat, va_list argList); void MakeLower(); - void MakeUpper(); void TrimRight(); - void TrimRight(FX_WCHAR chTarget); - void TrimRight(const FX_WCHAR* lpszTargets); void TrimLeft(); - void TrimLeft(FX_WCHAR chTarget); - void TrimLeft(const FX_WCHAR* lpszTargets); void Reserve(FX_STRSIZE len); - FX_WCHAR* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len = -1); int GetInteger() const; |