summaryrefslogtreecommitdiff
path: root/core/include/fxcrt/fx_string.h
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-04-22 12:29:21 -0700
committerTom Sepez <tsepez@chromium.org>2015-04-22 12:29:21 -0700
commitb208774174e102da9f218d89bf8a3af7a0e37f09 (patch)
treeb2f345fb8c42b54008af9e06bcde1cfeff380acb /core/include/fxcrt/fx_string.h
parent8f608d9c0d09ab5fc19cfb4a9d5d8ccef3de6625 (diff)
downloadpdfium-b208774174e102da9f218d89bf8a3af7a0e37f09.tar.xz
Merge to XFA: Add missing operators for CFX_xxxString combo patch.
This pulls in: Review URL: https://codereview.chromium.org/1099193002 Review URL: https://codereview.chromium.org/1090303003 Review URL: https://codereview.chromium.org/1084293003 Review URL: https://codereview.chromium.org/1099213002 Plus one fix to an XFA file to fix compilation. TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1095893005
Diffstat (limited to 'core/include/fxcrt/fx_string.h')
-rw-r--r--core/include/fxcrt/fx_string.h56
1 files changed, 42 insertions, 14 deletions
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index 70f64932c8..1efb814b08 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -7,6 +7,8 @@
#ifndef _FX_STRING_H_
#define _FX_STRING_H_
+#include <algorithm>
+
#include "fx_memory.h"
class CFX_ByteStringC;
@@ -21,7 +23,7 @@ class CFX_WideStringL;
// An immutable string with caller-provided storage which must outlive the
// string itself.
-class CFX_ByteStringC
+class CFX_ByteStringC
{
public:
typedef FX_CHAR value_type;
@@ -100,7 +102,6 @@ public:
{
return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length) != 0;
}
-#define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4))
FX_DWORD GetID(FX_STRSIZE start_pos = 0) const;
@@ -124,11 +125,6 @@ public:
return m_Length == 0;
}
- operator FX_LPCBYTE() const
- {
- return m_Ptr;
- }
-
FX_BYTE GetAt(FX_STRSIZE index) const
{
return m_Ptr[index];
@@ -147,13 +143,23 @@ public:
}
return CFX_ByteStringC(m_Ptr + index, count);
}
-protected:
- FX_LPCBYTE m_Ptr;
+ const FX_BYTE& operator[] (size_t index) const
+ {
+ return m_Ptr[index];
+ }
+
+ bool operator< (const CFX_ByteStringC& that) const
+ {
+ int result = memcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length));
+ return result < 0 || (result == 0 && m_Length < that.m_Length);
+ }
+protected:
+ FX_LPCBYTE m_Ptr;
FX_STRSIZE m_Length;
-private:
+private:
void* operator new (size_t) throw()
{
return NULL;
@@ -161,6 +167,7 @@ private:
};
typedef const CFX_ByteStringC& FX_BSTR;
#define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1)
+#define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4))
struct CFX_StringData {
long m_nRefs;
@@ -261,6 +268,12 @@ public:
return !operator==(str);
}
+ bool operator< (const CFX_ByteString& str) const
+ {
+ int result = FXSYS_memcmp32(c_str(), str.c_str(), std::min(GetLength(), str.GetLength()));
+ return result < 0 || (result == 0 && GetLength() < str.GetLength());
+ }
+
void Empty();
const CFX_ByteString& operator = (FX_LPCSTR str);
@@ -428,7 +441,7 @@ inline CFX_ByteString operator + (FX_BSTR str1, const CFX_ByteString& str2)
{
return CFX_ByteString(str1, str2);
}
-class CFX_WideStringC
+class CFX_WideStringC
{
public:
typedef FX_WCHAR value_type;
@@ -550,13 +563,23 @@ public:
}
return CFX_WideStringC(m_Ptr + m_Length - count, count);
}
-protected:
- FX_LPCWSTR m_Ptr;
+ const FX_WCHAR& operator[] (size_t index) const
+ {
+ return m_Ptr[index];
+ }
+ bool operator< (const CFX_WideStringC& that) const
+ {
+ int result = wmemcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length));
+ return result < 0 || (result == 0 && m_Length < that.m_Length);
+ }
+
+protected:
+ FX_LPCWSTR m_Ptr;
FX_STRSIZE m_Length;
-private:
+private:
void* operator new (size_t) throw()
{
return NULL;
@@ -646,6 +669,11 @@ public:
const CFX_WideString& operator += (const CFX_WideStringC& str);
+ 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());
+ }
+
FX_WCHAR GetAt(FX_STRSIZE nIndex) const
{
return m_pData ? m_pData->m_String[nIndex] : 0;