From f7fe678a4ada859a2e4fbbeeb0b1dff5b5887227 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 11 May 2016 17:35:35 -0700 Subject: Add much-needed Find() method for CFX_*StringC BUG=pdfium:493 Review-Url: https://codereview.chromium.org/1968233002 --- core/fxcrt/include/fx_string.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/fxcrt/include/fx_string.h') 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(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(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; -- cgit v1.2.3