summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-04-22 12:16:31 -0700
committerTom Sepez <tsepez@chromium.org>2015-04-22 12:16:31 -0700
commitfbfcbc5e82d89585a63a77c63e782fb6768c8dc8 (patch)
tree401697a19c9ab2489b678deeeff91909715d1dd6
parent1ddf056da74de0a34631b8a719f4f02b4ec82144 (diff)
downloadpdfium-fbfcbc5e82d89585a63a77c63e782fb6768c8dc8.tar.xz
Add missing operators for CFX_WideStringC.
Part 2 of 4. R=thestig@chromium.org TBR=brucedawson@chromium.org BUG=pdfium:142 Review URL: https://codereview.chromium.org/1099193002
-rw-r--r--core/include/fxcrt/fx_string.h18
-rw-r--r--core/src/fxcrt/fx_basic_wstring_unittest.cpp40
2 files changed, 54 insertions, 4 deletions
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index c1a6ec699e..1efb814b08 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -441,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;
@@ -563,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;
diff --git a/core/src/fxcrt/fx_basic_wstring_unittest.cpp b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
index 9575dfd786..084410ad19 100644
--- a/core/src/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
@@ -66,3 +66,43 @@ TEST(fxcrt, WideStringUTF16LE_Encode) {
<< " for case number " << i;
}
}
+
+TEST(fxcrt, WideStringCOperatorSubscript) {
+ // CFX_WideStringC includes the NUL terminator for non-empty strings.
+ CFX_WideStringC abc(L"abc");
+ EXPECT_EQ(L'a', abc[0]);
+ EXPECT_EQ(L'b', abc[1]);
+ EXPECT_EQ(L'c', abc[2]);
+ EXPECT_EQ(L'\0', abc[3]);
+}
+
+TEST(fxcrt, WideStringCOperatorLT) {
+ CFX_WideStringC empty;
+ CFX_WideStringC a(L"a");
+ CFX_WideStringC abc(L"\x0110qq"); // Comes before despite endianness.
+ CFX_WideStringC def(L"\x1001qq"); // Comes after despite endianness.
+
+ EXPECT_FALSE(empty < empty);
+ EXPECT_FALSE(a < a);
+ EXPECT_FALSE(abc < abc);
+ EXPECT_FALSE(def < def);
+
+ EXPECT_TRUE(empty < a);
+ EXPECT_FALSE(a < empty);
+
+ EXPECT_TRUE(empty < abc);
+ EXPECT_FALSE(abc < empty);
+
+ EXPECT_TRUE(empty < def);
+ EXPECT_FALSE(def < empty);
+
+ EXPECT_TRUE(a < abc);
+ EXPECT_FALSE(abc < a);
+
+ EXPECT_TRUE(a < def);
+ EXPECT_FALSE(def < a);
+
+ EXPECT_TRUE(abc < def);
+ EXPECT_FALSE(def < abc);
+}
+