summaryrefslogtreecommitdiff
path: root/core/src
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/src
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/src')
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp4
-rw-r--r--core/src/fxcrt/fx_basic_bstring.cpp2
-rw-r--r--core/src/fxcrt/fx_basic_bstring_unittest.cpp39
-rw-r--r--core/src/fxcrt/fx_basic_buffer.cpp10
-rw-r--r--core/src/fxcrt/fx_basic_maps.cpp12
7 files changed, 56 insertions, 17 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index f79fcda0a0..e098f66dec 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -427,7 +427,7 @@ void CPDF_GeneralStateData::SetBlendMode(FX_BSTR blend_mode)
if (blend_mode.GetLength() > 15) {
return;
}
- FXSYS_memcpy32(m_BlendMode, (FX_LPCBYTE)blend_mode, blend_mode.GetLength());
+ FXSYS_memcpy32(m_BlendMode, blend_mode.GetPtr(), blend_mode.GetLength());
m_BlendMode[blend_mode.GetLength()] = 0;
m_BlendType = ::GetBlendType(blend_mode);
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 1a49ffd6b7..2772d9825e 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2558,7 +2558,7 @@ FX_BOOL CPDF_SyntaxParser::SearchWord(FX_BSTR tag, FX_BOOL bWholeWord, FX_BOOL b
if (!bForward) {
offset = taglen - 1;
}
- FX_LPCBYTE tag_data = tag;
+ FX_LPCBYTE tag_data = tag.GetPtr();
FX_BYTE byte;
while (1) {
if (bForward) {
@@ -2595,7 +2595,7 @@ FX_BOOL CPDF_SyntaxParser::SearchWord(FX_BSTR tag, FX_BOOL bWholeWord, FX_BOOL b
}
}
FX_FILESIZE startpos = bForward ? pos - taglen + 1 : pos;
- if (!bWholeWord || IsWholeWord(startpos, limit, tag, taglen)) {
+ if (!bWholeWord || IsWholeWord(startpos, limit, tag.GetPtr(), taglen)) {
m_Pos = startpos;
return TRUE;
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index bbfd4cc680..df154eae90 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -51,7 +51,7 @@ CPDF_SimpleParser::CPDF_SimpleParser(FX_LPCBYTE pData, FX_DWORD dwSize)
}
CPDF_SimpleParser::CPDF_SimpleParser(FX_BSTR str)
{
- m_pData = str;
+ m_pData = str.GetPtr();
m_dwSize = str.GetLength();
m_dwCurPos = 0;
}
@@ -198,7 +198,7 @@ FX_BOOL CPDF_SimpleParser::SearchToken(FX_BSTR token)
{
int token_len = token.GetLength();
while (m_dwCurPos < m_dwSize - token_len) {
- if (FXSYS_memcmp32(m_pData + m_dwCurPos, token, token_len) == 0) {
+ if (FXSYS_memcmp32(m_pData + m_dwCurPos, token.GetPtr(), token_len) == 0) {
break;
}
m_dwCurPos ++;
diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp
index ea9ca85021..cda7d1fdd7 100644
--- a/core/src/fxcrt/fx_basic_bstring.cpp
+++ b/core/src/fxcrt/fx_basic_bstring.cpp
@@ -276,7 +276,7 @@ bool CFX_ByteString::EqualNoCase(FX_BSTR str) const
return false;
}
FX_LPCBYTE pThis = (FX_LPCBYTE)m_pData->m_String;
- FX_LPCBYTE pThat = (FX_LPCBYTE)str;
+ FX_LPCBYTE pThat = str.GetPtr();
for (FX_STRSIZE i = 0; i < len; i ++) {
if ((*pThis) != (*pThat)) {
FX_BYTE bThis = *pThis;
diff --git a/core/src/fxcrt/fx_basic_bstring_unittest.cpp b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
index 1ddaad420a..57cfc8047e 100644
--- a/core/src/fxcrt/fx_basic_bstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
@@ -229,3 +229,42 @@ TEST(fxcrt, ByteStringCGetAt) {
EXPECT_EQ('\0', embedded_nul_string.GetAt(2));
EXPECT_EQ('c', embedded_nul_string.GetAt(3));
}
+
+TEST(fxcrt, ByteStringCOperatorSubscript) {
+ // CFX_ByteStringC includes the NUL terminator for non-empty strings.
+ CFX_ByteStringC abc("abc");
+ EXPECT_EQ('a', abc[0]);
+ EXPECT_EQ('b', abc[1]);
+ EXPECT_EQ('c', abc[2]);
+ EXPECT_EQ(0, abc[3]);
+}
+
+TEST(fxcrt, ByteStringCOperatorLT) {
+ CFX_ByteStringC empty;
+ CFX_ByteStringC a("a");
+ CFX_ByteStringC abc("abc");
+ CFX_ByteStringC def("def");
+
+ 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);
+}
diff --git a/core/src/fxcrt/fx_basic_buffer.cpp b/core/src/fxcrt/fx_basic_buffer.cpp
index bb8466debe..eb5246acec 100644
--- a/core/src/fxcrt/fx_basic_buffer.cpp
+++ b/core/src/fxcrt/fx_basic_buffer.cpp
@@ -143,7 +143,7 @@ CFX_ByteStringC CFX_BinaryBuf::GetByteString() const
}
CFX_ByteTextBuf& CFX_ByteTextBuf::operator << (FX_BSTR lpsz)
{
- AppendBlock((FX_LPCBYTE)lpsz, lpsz.GetLength());
+ AppendBlock(lpsz.GetPtr(), lpsz.GetLength());
return *this;
}
CFX_ByteTextBuf& CFX_ByteTextBuf::operator << (int i)
@@ -174,7 +174,7 @@ CFX_ByteTextBuf& CFX_ByteTextBuf::operator << (const CFX_ByteTextBuf& buf)
}
void CFX_ByteTextBuf::operator =(const CFX_ByteStringC& str)
{
- CopyData((FX_LPCBYTE)str, str.GetLength());
+ CopyData(str.GetPtr(), str.GetLength());
}
void CFX_WideTextBuf::AppendChar(FX_WCHAR ch)
{
@@ -285,10 +285,10 @@ CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (FX_BSTR bstr)
int len = bstr.GetLength();
if (m_pStream) {
m_pStream->WriteBlock(&len, sizeof(int));
- m_pStream->WriteBlock(bstr, len);
+ m_pStream->WriteBlock(bstr.GetPtr(), len);
} else {
m_SavingBuf.AppendBlock(&len, sizeof(int));
- m_SavingBuf.AppendBlock(bstr, len);
+ m_SavingBuf.AppendBlock(bstr.GetPtr(), len);
}
return *this;
}
@@ -488,7 +488,7 @@ FX_INT32 IFX_BufferArchive::AppendDWord(FX_DWORD i)
}
FX_INT32 IFX_BufferArchive::AppendString(FX_BSTR lpsz)
{
- return AppendBlock((FX_LPCBYTE)lpsz, lpsz.GetLength());
+ return AppendBlock(lpsz.GetPtr(), lpsz.GetLength());
}
CFX_FileBufferArchive::CFX_FileBufferArchive(FX_STRSIZE size)
: IFX_BufferArchive(size)
diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp
index e85d35e4ac..8ae44ce6a0 100644
--- a/core/src/fxcrt/fx_basic_maps.cpp
+++ b/core/src/fxcrt/fx_basic_maps.cpp
@@ -352,7 +352,7 @@ inline FX_DWORD CFX_MapByteStringToPtr::HashKey(FX_BSTR key) const
{
FX_DWORD nHash = 0;
int len = key.GetLength();
- FX_LPCBYTE buf = key;
+ FX_LPCBYTE buf = key.GetPtr();
for (int i = 0; i < len; i ++) {
nHash = (nHash << 5) + nHash + buf[i];
}
@@ -518,7 +518,7 @@ void CFX_CMapByteStringToPtr::SetAt(FX_BSTR key, void* value)
int size = m_Buffer.GetSize();
for (index = 0; index < size; index ++) {
_CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) {
+ if (!_CompactStringSame(pKey, key.GetPtr(), key_len)) {
continue;
}
*(void**)(pKey + 1) = value;
@@ -529,19 +529,19 @@ void CFX_CMapByteStringToPtr::SetAt(FX_BSTR key, void* value)
if (pKey->m_CompactLen) {
continue;
}
- _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len);
+ _CompactStringStore(pKey, key.GetPtr(), key_len);
*(void**)(pKey + 1) = value;
return;
}
_CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len);
+ _CompactStringStore(pKey, key.GetPtr(), key_len);
*(void**)(pKey + 1) = value;
}
void CFX_CMapByteStringToPtr::AddValue(FX_BSTR key, void* value)
{
ASSERT(value != NULL);
_CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(pKey, (FX_LPCBYTE)key, key.GetLength());
+ _CompactStringStore(pKey, key.GetPtr(), key.GetLength());
*(void**)(pKey + 1) = value;
}
void CFX_CMapByteStringToPtr::RemoveKey(FX_BSTR key)
@@ -550,7 +550,7 @@ void CFX_CMapByteStringToPtr::RemoveKey(FX_BSTR key)
int size = m_Buffer.GetSize();
for (int index = 0; index < size; index++) {
_CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) {
+ if (!_CompactStringSame(pKey, key.GetPtr(), key_len)) {
continue;
}
_CompactStringRelease(pKey);