From e7a99de4f711302d57fe22682a9a8c3cfddb458c Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 28 Jul 2017 14:07:04 -0400 Subject: Convert calls to Mid() to Left() or Right() if possible The various string/byte classes support Mid(), Left(), and Right() for extracting substrings. Mid() can handle all possible cases, but Left() and Right() are useful for common cases and more explicit about what is going on. Calls like Mid(offset, length - offset) can be converted to Right(length - offset). Calls like Mid(0, length) can be converted to Left(length). If the substring being extracted does not extend all the way to one of the edges of the string, then Mid() still needs to be used. BUG=pdfium:828 Change-Id: I2ec46ad3d71aac0f7b513e103c69cbe8c854cf62 Reviewed-on: https://pdfium-review.googlesource.com/9510 Commit-Queue: Ryan Harrison Reviewed-by: Tom Sepez --- core/fpdftext/cpdf_linkextract.cpp | 2 +- core/fpdftext/cpdf_textpage.cpp | 4 ++-- core/fpdftext/cpdf_textpagefind.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'core/fpdftext') diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp index 5179f732c9..e0bd4ae49f 100644 --- a/core/fpdftext/cpdf_linkextract.cpp +++ b/core/fpdftext/cpdf_linkextract.cpp @@ -154,7 +154,7 @@ void CPDF_LinkExtract::ParseLink() { while (strBeCheck.GetLength() > 0) { wchar_t ch = strBeCheck.GetAt(strBeCheck.GetLength() - 1); if (ch == L')' || ch == L',' || ch == L'>' || ch == L'.') { - strBeCheck = strBeCheck.Mid(0, strBeCheck.GetLength() - 1); + strBeCheck = strBeCheck.Left(strBeCheck.GetLength() - 1); nCount--; } else { break; diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 1dc03db4ff..8f0e376dbc 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -441,8 +441,8 @@ CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const { if (nCount == -1) { nCount = pdfium::CollectionSize(m_CharList) - start; - return CFX_WideString( - m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength())); + CFX_WideStringC wsTextBuf = m_TextBuf.AsStringC(); + return CFX_WideString(wsTextBuf.Right(wsTextBuf.GetLength() - start)); } if (nCount <= 0 || m_CharList.empty()) return L""; diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp index 058c293ac1..fe610abcd4 100644 --- a/core/fpdftext/cpdf_textpagefind.cpp +++ b/core/fpdftext/cpdf_textpagefind.cpp @@ -300,7 +300,7 @@ void CPDF_TextPageFind::ExtractFindWhat(const CFX_WideString& findwhat) { continue; } if (pos > 0) - m_csFindWhatArray.push_back(csWord.Mid(0, pos)); + m_csFindWhatArray.push_back(csWord.Left(pos)); m_csFindWhatArray.push_back(curStr); if (pos == csWord.GetLength() - 1) { csWord.clear(); -- cgit v1.2.3