diff options
author | tsepez <tsepez@chromium.org> | 2016-03-31 14:40:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-31 14:40:29 -0700 |
commit | de0d852ed91973deda41f949e132b12a2efff1ef (patch) | |
tree | 82f69490153b686dd6ae789917605f95e0a1863c /core/fxcrt/fx_basic_bstring.cpp | |
parent | b33dfdf68bafa30e90a65fb71ff6b343202e0561 (diff) | |
download | pdfium-de0d852ed91973deda41f949e132b12a2efff1ef.tar.xz |
Beef up unit test for CFX_ByteString and CFX_WideString.
Needed to validate refactoring which was reverted.
Review URL: https://codereview.chromium.org/1847193002
Diffstat (limited to 'core/fxcrt/fx_basic_bstring.cpp')
-rw-r--r-- | core/fxcrt/fx_basic_bstring.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp index ab9299694e..10bc05bcc5 100644 --- a/core/fxcrt/fx_basic_bstring.cpp +++ b/core/fxcrt/fx_basic_bstring.cpp @@ -420,27 +420,20 @@ void CFX_ByteString::ConcatCopy(FX_STRSIZE nSrc1Len, pOldData->Release(); } CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst) const { - if (!m_pData) { + if (!m_pData) return CFX_ByteString(); - } + return Mid(nFirst, m_pData->m_nDataLength - nFirst); } CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { - if (nFirst < 0) { - nFirst = 0; - } - if (nCount < 0) { - nCount = 0; - } - if (nFirst + nCount > m_pData->m_nDataLength) { - nCount = m_pData->m_nDataLength - nFirst; - } - if (nFirst > m_pData->m_nDataLength) { - nCount = 0; - } - if (nFirst == 0 && nFirst + nCount == m_pData->m_nDataLength) { + if (!m_pData) + return CFX_ByteString(); + + nFirst = std::min(std::max(0, nFirst), m_pData->m_nDataLength); + nCount = std::min(std::max(0, nCount), m_pData->m_nDataLength - nFirst); + if (nFirst == 0 && nCount == m_pData->m_nDataLength) return *this; - } + CFX_ByteString dest; AllocCopy(dest, nCount, nFirst); return dest; |