summaryrefslogtreecommitdiff
path: root/core/include
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-04-22 12:04:14 -0700
committerTom Sepez <tsepez@chromium.org>2015-04-22 12:04:14 -0700
commit1ddf056da74de0a34631b8a719f4f02b4ec82144 (patch)
tree45217449a89d4286a903c76774971c1c2c6c38e4 /core/include
parentea6a069e6e593d97513e86fc761cf789a9714c22 (diff)
downloadpdfium-1ddf056da74de0a34631b8a719f4f02b4ec82144.tar.xz
Add missing operators for CFX_ByteStringC.
Removing the implicit cast operator forces a build breakage should we use ByteStringC in STL containers. Adding an operator< restores correct behaviour. Adding an operator[] avoids re-writing some code to call GetPtr() prior to array indexing. Part 1 of 4. R=thestig@chromium.org TBR=brucedawson@chromium.org BUG=pdfium:142. Review URL: https://codereview.chromium.org/1090303003
Diffstat (limited to 'core/include')
-rw-r--r--core/include/fxcrt/fx_string.h25
1 files changed, 15 insertions, 10 deletions
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index dd8752ef28..c1a6ec699e 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -23,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;
@@ -102,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;
@@ -126,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];
@@ -149,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;
@@ -163,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;