summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_wstring.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-11 17:35:35 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-11 17:35:35 -0700
commitf7fe678a4ada859a2e4fbbeeb0b1dff5b5887227 (patch)
tree271f61e203bcb7026db6b4936668f51f7f5e0de8 /core/fxcrt/fx_basic_wstring.cpp
parent94dfd56acc7ceb2acfc2e5c7ae516e34b160ea15 (diff)
downloadpdfium-f7fe678a4ada859a2e4fbbeeb0b1dff5b5887227.tar.xz
Add much-needed Find() method for CFX_*StringC
BUG=pdfium:493 Review-Url: https://codereview.chromium.org/1968233002
Diffstat (limited to 'core/fxcrt/fx_basic_wstring.cpp')
-rw-r--r--core/fxcrt/fx_basic_wstring.cpp21
1 files changed, 8 insertions, 13 deletions
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;