summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp8
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp7
-rw-r--r--core/fpdftext/fpdf_text_int.cpp4
-rw-r--r--core/fxcrt/fx_basic_bstring.cpp7
-rw-r--r--core/fxcrt/fx_basic_bstring_unittest.cpp25
-rw-r--r--core/fxcrt/fx_basic_util.cpp2
-rw-r--r--core/fxcrt/fx_basic_wstring.cpp21
-rw-r--r--core/fxcrt/fx_basic_wstring_unittest.cpp25
-rw-r--r--core/fxcrt/include/fx_string.h12
-rw-r--r--core/fxcrt/include/fx_system.h3
10 files changed, 84 insertions, 30 deletions
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index a13fb5021d..da1355724f 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -271,18 +271,18 @@ int CPDF_StreamContentParser::GetNextParamPos() {
}
void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) {
+ CFX_ByteStringC bsName(name, len);
int index = GetNextParamPos();
if (len > 32) {
m_ParamBuf[index].m_Type = ContentParam::OBJECT;
- m_ParamBuf[index].m_pObject =
- new CPDF_Name(PDF_NameDecode(CFX_ByteStringC(name, len)));
+ m_ParamBuf[index].m_pObject = new CPDF_Name(PDF_NameDecode(bsName));
} else {
m_ParamBuf[index].m_Type = ContentParam::NAME;
- if (!FXSYS_memchr(name, '#', len)) {
+ if (bsName.Find('#') == -1) {
FXSYS_memcpy(m_ParamBuf[index].m_Name.m_Buffer, name, len);
m_ParamBuf[index].m_Name.m_Len = len;
} else {
- CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len));
+ CFX_ByteString str = PDF_NameDecode(bsName);
FXSYS_memcpy(m_ParamBuf[index].m_Name.m_Buffer, str.c_str(),
str.GetLength());
m_ParamBuf[index].m_Name.m_Len = str.GetLength();
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index 466ccaffa5..03975149b0 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -89,9 +89,9 @@ int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) {
CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
int size = bstr.GetLength();
const FX_CHAR* pSrc = bstr.c_str();
- if (!FXSYS_memchr(pSrc, '#', size)) {
+ if (bstr.Find('#') == -1)
return bstr;
- }
+
CFX_ByteString result;
FX_CHAR* pDestStart = result.GetBuffer(size);
FX_CHAR* pDest = pDestStart;
@@ -109,9 +109,8 @@ CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
}
CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig) {
- if (!FXSYS_memchr(orig.c_str(), '#', orig.GetLength())) {
+ if (orig.Find('#') == -1)
return orig;
- }
return PDF_NameDecode(orig.AsStringC());
}
diff --git a/core/fpdftext/fpdf_text_int.cpp b/core/fpdftext/fpdf_text_int.cpp
index 8e5e75853e..f843da3061 100644
--- a/core/fpdftext/fpdf_text_int.cpp
+++ b/core/fpdftext/fpdf_text_int.cpp
@@ -2147,7 +2147,7 @@ FX_BOOL CPDF_TextPageFind::ExtractSubString(CFX_WideString& rString,
return FALSE;
}
while (iSubString--) {
- lpszFullString = FXSYS_wcschr(lpszFullString, chSep);
+ lpszFullString = wcschr(lpszFullString, chSep);
if (!lpszFullString) {
rString.clear();
return FALSE;
@@ -2157,7 +2157,7 @@ FX_BOOL CPDF_TextPageFind::ExtractSubString(CFX_WideString& rString,
lpszFullString++;
}
}
- const FX_WCHAR* lpchEnd = FXSYS_wcschr(lpszFullString, chSep);
+ const FX_WCHAR* lpchEnd = wcschr(lpszFullString, chSep);
int nLen = lpchEnd ? (int)(lpchEnd - lpszFullString)
: (int)FXSYS_wcslen(lpszFullString);
ASSERT(nLen >= 0);
diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp
index cd7b616fbe..18e240bc84 100644
--- a/core/fxcrt/fx_basic_bstring.cpp
+++ b/core/fxcrt/fx_basic_bstring.cpp
@@ -673,11 +673,12 @@ FX_STRSIZE CFX_ByteString::Find(FX_CHAR ch, FX_STRSIZE nStart) const {
if (!m_pData)
return -1;
- if (nStart >= m_pData->m_nDataLength)
+ if (nStart < 0 || nStart >= m_pData->m_nDataLength)
return -1;
- const FX_CHAR* pStr = FXSYS_strchr(m_pData->m_String + nStart, ch);
- return pStr ? (int)(pStr - m_pData->m_String) : -1;
+ const FX_CHAR* pStr = static_cast<const FX_CHAR*>(
+ memchr(m_pData->m_String + nStart, ch, m_pData->m_nDataLength - nStart));
+ return pStr ? pStr - m_pData->m_String : -1;
}
FX_STRSIZE CFX_ByteString::ReverseFind(FX_CHAR ch) const {
diff --git a/core/fxcrt/fx_basic_bstring_unittest.cpp b/core/fxcrt/fx_basic_bstring_unittest.cpp
index 087c264940..fe98b53b45 100644
--- a/core/fxcrt/fx_basic_bstring_unittest.cpp
+++ b/core/fxcrt/fx_basic_bstring_unittest.cpp
@@ -802,6 +802,31 @@ TEST(fxcrt, ByteStringCGetID) {
EXPECT_EQ(0u, longer_string.GetID(-1000000));
}
+TEST(fxcrt, ByteStringCFind) {
+ CFX_ByteStringC null_string;
+ EXPECT_EQ(-1, null_string.Find('a'));
+ EXPECT_EQ(-1, null_string.Find(0));
+
+ CFX_ByteStringC empty_string("");
+ EXPECT_EQ(-1, empty_string.Find('a'));
+ EXPECT_EQ(-1, empty_string.Find(0));
+
+ CFX_ByteStringC single_string("a");
+ EXPECT_EQ(0, single_string.Find('a'));
+ EXPECT_EQ(-1, single_string.Find('b'));
+ EXPECT_EQ(-1, single_string.Find(0));
+
+ CFX_ByteStringC longer_string("abccc");
+ EXPECT_EQ(0, longer_string.Find('a'));
+ EXPECT_EQ(2, longer_string.Find('c'));
+ EXPECT_EQ(-1, longer_string.Find(0));
+
+ CFX_ByteStringC hibyte_string(
+ "ab\x8c"
+ "def");
+ EXPECT_EQ(2, hibyte_string.Find('\x8c'));
+}
+
TEST(fxcrt, ByteStringCMid) {
CFX_ByteStringC null_string;
EXPECT_EQ(null_string, null_string.Mid(0, 1));
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index 1cf966589d..f69185653f 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -95,7 +95,7 @@ void CFX_PrivateData::ClearAll() {
m_DataList.RemoveAll();
}
void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
- if (!FXSYS_memchr(strc.raw_str(), '.', strc.GetLength())) {
+ if (strc.Find('.') == -1) {
bInteger = TRUE;
int cc = 0, integer = 0;
const FX_CHAR* str = strc.c_str();
diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp
index 354bb5014a..03cb0599d5 100644
--- a/core/fxcrt/fx_basic_wstring.cpp
+++ b/core/fxcrt/fx_basic_wstring.cpp
@@ -638,11 +638,12 @@ FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const {
if (!m_pData)
return -1;
- if (nStart >= m_pData->m_nDataLength)
+ if (nStart < 0 || nStart >= m_pData->m_nDataLength)
return -1;
- const FX_WCHAR* pStr = FXSYS_wcschr(m_pData->m_String + nStart, ch);
- return pStr ? (int)(pStr - m_pData->m_String) : -1;
+ const FX_WCHAR* pStr =
+ wmemchr(m_pData->m_String + nStart, ch, m_pData->m_nDataLength - nStart);
+ return pStr ? pStr - m_pData->m_String : -1;
}
FX_STRSIZE CFX_WideString::Find(const CFX_WideStringC& pSub,
@@ -858,19 +859,13 @@ FX_STRSIZE CFX_WideString::WStringLength(const unsigned short* str) {
}
void CFX_WideString::TrimRight(const CFX_WideStringC& pTargets) {
- if (!m_pData || pTargets.IsEmpty()) {
+ if (IsEmpty() || pTargets.IsEmpty())
return;
- }
+
FX_STRSIZE pos = GetLength();
- if (pos < 1) {
- return;
- }
- while (pos) {
- if (!FXSYS_wcschr(pTargets.c_str(), m_pData->m_String[pos - 1])) {
- break;
- }
+ while (pos && pTargets.Find(m_pData->m_String[pos - 1]) != -1)
pos--;
- }
+
if (pos < m_pData->m_nDataLength) {
ReallocBeforeWrite(m_pData->m_nDataLength);
m_pData->m_String[pos] = 0;
diff --git a/core/fxcrt/fx_basic_wstring_unittest.cpp b/core/fxcrt/fx_basic_wstring_unittest.cpp
index 02281afd36..4b6f4a5800 100644
--- a/core/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/fxcrt/fx_basic_wstring_unittest.cpp
@@ -831,6 +831,31 @@ TEST(fxcrt, WideStringCOperatorNE) {
EXPECT_TRUE(c_string3 != wide_string_c);
}
+TEST(fxcrt, WideStringCFind) {
+ CFX_WideStringC null_string;
+ EXPECT_EQ(-1, null_string.Find(L'a'));
+ EXPECT_EQ(-1, null_string.Find(0));
+
+ CFX_WideStringC empty_string(L"");
+ EXPECT_EQ(-1, empty_string.Find(L'a'));
+ EXPECT_EQ(-1, empty_string.Find(0));
+
+ CFX_WideStringC single_string(L"a");
+ EXPECT_EQ(0, single_string.Find(L'a'));
+ EXPECT_EQ(-1, single_string.Find(L'b'));
+ EXPECT_EQ(-1, single_string.Find(0));
+
+ CFX_WideStringC longer_string(L"abccc");
+ EXPECT_EQ(0, longer_string.Find(L'a'));
+ EXPECT_EQ(2, longer_string.Find(L'c'));
+ EXPECT_EQ(-1, longer_string.Find(0));
+
+ CFX_WideStringC hibyte_string(
+ L"ab\xff08"
+ L"def");
+ EXPECT_EQ(2, hibyte_string.Find(L'\xff08'));
+}
+
TEST(fxcrt, WideStringFormatWidth) {
{
CFX_WideString str;
diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h
index 66a8039a8d..fbfb91f759 100644
--- a/core/fxcrt/include/fx_string.h
+++ b/core/fxcrt/include/fx_string.h
@@ -100,6 +100,12 @@ class CFX_ByteStringC {
uint8_t GetAt(FX_STRSIZE index) const { return m_Ptr[index]; }
+ FX_STRSIZE Find(FX_CHAR ch) const {
+ const uint8_t* found =
+ static_cast<const uint8_t*>(memchr(m_Ptr, ch, m_Length));
+ return found ? found - m_Ptr : -1;
+ }
+
CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const {
if (index < 0) {
index = 0;
@@ -417,6 +423,12 @@ class CFX_WideStringC {
return CFX_WideStringC(m_Ptr, count);
}
+ FX_STRSIZE Find(FX_WCHAR ch) const {
+ const FX_WCHAR* found =
+ static_cast<const FX_WCHAR*>(wmemchr(m_Ptr, ch, m_Length));
+ return found ? found - m_Ptr : -1;
+ }
+
CFX_WideStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const {
if (index < 0) {
index = 0;
diff --git a/core/fxcrt/include/fx_system.h b/core/fxcrt/include/fx_system.h
index 795a0c2794..b4659d14e4 100644
--- a/core/fxcrt/include/fx_system.h
+++ b/core/fxcrt/include/fx_system.h
@@ -123,7 +123,6 @@ void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap);
#define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE
#define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE
-#define FXSYS_strchr strchr
#define FXSYS_strncmp strncmp
#define FXSYS_strcmp strcmp
#define FXSYS_strcpy strcpy
@@ -166,7 +165,6 @@ extern "C" {
#endif
#define FXSYS_wcscmp wcscmp
-#define FXSYS_wcschr wcschr
#define FXSYS_wcsstr wcsstr
#define FXSYS_wcsncmp wcsncmp
#define FXSYS_vswprintf vswprintf
@@ -176,7 +174,6 @@ extern "C" {
#define FXSYS_memcpy memcpy
#define FXSYS_memmove memmove
#define FXSYS_memset memset
-#define FXSYS_memchr memchr
#define FXSYS_qsort qsort
#define FXSYS_bsearch bsearch