summaryrefslogtreecommitdiff
path: root/core/include/fxcrt
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-05-04 15:29:42 -0700
committerTom Sepez <tsepez@chromium.org>2015-05-04 15:29:42 -0700
commit3d33c90cfed96a8e5ce707a025e8efd59ce1ca01 (patch)
treee0512cee06b294f61d40f5c1523cf6eb3310935e /core/include/fxcrt
parent090d139b66d11b8f9a33b930277aea8becb7f085 (diff)
downloadpdfium-3d33c90cfed96a8e5ce707a025e8efd59ce1ca01.tar.xz
Merge to XFA: Fix issues with != and == in fx_basic_wstring
Original Review URL: https://codereview.chromium.org/1127753002 TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1119753004
Diffstat (limited to 'core/include/fxcrt')
-rw-r--r--core/include/fxcrt/fx_string.h63
1 files changed, 44 insertions, 19 deletions
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index 7e9b1a15f6..c46a97166b 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -511,14 +511,17 @@ public:
CFX_WideStringC& operator = (const CFX_WideString& src);
- bool operator == (const CFX_WideStringC& str) const
- {
- return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length * sizeof(FX_WCHAR)) == 0;
+ bool operator== (const wchar_t* ptr) const {
+ return FXSYS_wcslen(ptr) == m_Length &&
+ wmemcmp(ptr, m_Ptr, m_Length) == 0;
}
-
- bool operator != (const CFX_WideStringC& str) const
- {
- return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length * sizeof(FX_WCHAR)) != 0;
+ bool operator== (const CFX_WideStringC& str) const {
+ return str.m_Length == m_Length &&
+ wmemcmp(str.m_Ptr, m_Ptr, m_Length) == 0;
+ }
+ bool operator!= (const wchar_t* ptr) const { return !(*this == ptr); }
+ bool operator!= (const CFX_WideStringC& str) const {
+ return !(*this == str);
}
FX_LPCWSTR GetPtr() const
@@ -598,8 +601,15 @@ private:
return NULL;
}
};
+inline bool operator== (const wchar_t* lhs, const CFX_WideStringC& rhs) {
+ return rhs == lhs;
+}
+inline bool operator!= (const wchar_t* lhs, const CFX_WideStringC& rhs) {
+ return rhs != lhs;
+}
typedef const CFX_WideStringC& FX_WSTR;
#define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1)
+
struct CFX_StringDataW {
intptr_t m_nRefs; // Would prefer ssize_t, but no windows support.
FX_STRSIZE m_nDataLength;
@@ -681,6 +691,18 @@ public:
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 { return !(*this == ptr); }
+ bool operator!= (const CFX_WideStringC& str) const {
+ return !(*this == str);
+ }
+ bool operator!= (const CFX_WideString& other) const {
+ return !(*this == other);
+ }
+
bool operator< (const CFX_WideString& str) const {
int result = wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.GetLength()));
return result < 0 || (result == 0 && GetLength() < str.GetLength());
@@ -704,7 +726,9 @@ public:
int CompareNoCase(FX_LPCWSTR str) const;
- bool Equal(const CFX_WideStringC& 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;
@@ -832,17 +856,18 @@ inline CFX_WideString operator + (const CFX_WideStringC& str1, const CFX_WideStr
{
return CFX_WideString(str1, str2);
}
-
-bool operator==(const CFX_WideString& s1, const CFX_WideString& s2);
-bool operator==(const CFX_WideString& s1, const CFX_WideStringC& s2);
-bool operator==(const CFX_WideStringC& s1, const CFX_WideString& s2);
-bool operator== (const CFX_WideString& s1, FX_LPCWSTR s2);
-bool operator==(FX_LPCWSTR s1, const CFX_WideString& s2);
-bool operator!=(const CFX_WideString& s1, const CFX_WideString& s2);
-bool operator!=(const CFX_WideString& s1, const CFX_WideStringC& s2);
-bool operator!=(const CFX_WideStringC& s1, const CFX_WideString& s2);
-bool operator!= (const CFX_WideString& s1, FX_LPCWSTR s2);
-bool operator!=(FX_LPCWSTR s1, const CFX_WideString& s2);
+inline bool operator== (const wchar_t* lhs, const CFX_WideString& rhs) {
+ return rhs == lhs;
+}
+inline bool operator== (const CFX_WideStringC& lhs, const CFX_WideString& rhs) {
+ return rhs == lhs;
+}
+inline bool operator!= (const wchar_t* lhs, const CFX_WideString& rhs) {
+ return rhs != lhs;
+}
+inline bool operator!= (const CFX_WideStringC& lhs, const CFX_WideString& rhs) {
+ return rhs != lhs;
+}
FX_FLOAT FX_atof(FX_BSTR str);
void FX_atonum(FX_BSTR str, FX_BOOL& bInteger, void* pData);
FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf);