diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-07-27 16:28:44 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-27 21:05:23 +0000 |
commit | 33805cc811c722a0c5cd439cff419de252cd39c9 (patch) | |
tree | bb6ef4484ff62486e4cc0ea49642278b5da1b746 /core/fxcrt/cfx_string_c_template.h | |
parent | 4191b03e29ef54f37deeadf652ee11cbfb81f9df (diff) | |
download | pdfium-33805cc811c722a0c5cd439cff419de252cd39c9.tar.xz |
Remove single param Mid() method from string classes
This support is being removed from CFX_ByteString, CFX_ByteStringC,
CFX_WideString, and CFX_WideStringC. This standardizes all of these
classes to only have one Mid method that takes in 2 params, offset and
count. Count now must be positive. The old behaviour of calculating
the length for the user if -1 is passed in for the count has been
removed. This work is in preperation for converting these classes to
not accept negative lengths anywhere and thus make the underlying size
type unsigned.
BUG=pdfium:828
Change-Id: I5f15e7b7b00b264231817f143e2da88ee6f69e7b
Reviewed-on: https://pdfium-review.googlesource.com/9430
Reviewed-by: (OOO Jul 28 - Aug 8) dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_string_c_template.h')
-rw-r--r-- | core/fxcrt/cfx_string_c_template.h | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/core/fxcrt/cfx_string_c_template.h b/core/fxcrt/cfx_string_c_template.h index cd3cd27e75..77f34f638e 100644 --- a/core/fxcrt/cfx_string_c_template.h +++ b/core/fxcrt/cfx_string_c_template.h @@ -130,29 +130,32 @@ class CFX_StringCTemplate { return found ? found - m_Ptr.Get() : -1; } - CFX_StringCTemplate Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const { - index = std::max(0, index); + CFX_StringCTemplate Mid(FX_STRSIZE index, FX_STRSIZE count) const { + ASSERT(count >= 0); if (index > m_Length) return CFX_StringCTemplate(); - if (count < 0 || count > m_Length - index) - count = m_Length - index; + index = pdfium::clamp(index, 0, m_Length); + count = pdfium::clamp(count, 0, m_Length - index); + if (count == 0) + return CFX_StringCTemplate(); return CFX_StringCTemplate(m_Ptr.Get() + index, count); } CFX_StringCTemplate Left(FX_STRSIZE count) const { - if (count <= 0) + count = pdfium::clamp(count, 0, m_Length); + if (count == 0) return CFX_StringCTemplate(); - return CFX_StringCTemplate(m_Ptr.Get(), std::min(count, m_Length)); + return CFX_StringCTemplate(m_Ptr.Get(), count); } CFX_StringCTemplate Right(FX_STRSIZE count) const { - if (count <= 0) + count = pdfium::clamp(count, 0, m_Length); + if (count == 0) return CFX_StringCTemplate(); - count = std::min(count, m_Length); return CFX_StringCTemplate(m_Ptr.Get() + m_Length - count, count); } |