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 --- fpdfsdk/formfiller/cba_fontmap.cpp | 2 +- fpdfsdk/fpdfppo.cpp | 4 ++-- fpdfsdk/javascript/PublicMethods.cpp | 10 ++++------ 3 files changed, 7 insertions(+), 9 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index b195303800..577faf4b8f 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -221,7 +221,7 @@ CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString* sAlias) { CFX_ByteString sFontName(syntax.GetWord()); CFX_ByteString sDecodedFontName = PDF_NameDecode(sFontName); - *sAlias = sDecodedFontName.Mid(1, sDecodedFontName.GetLength() - 1); + *sAlias = sDecodedFontName.Right(sDecodedFontName.GetLength() - 1); CPDF_Dictionary* pFontDict = nullptr; if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP")) { diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp index d05fab9c0b..bc3d769574 100644 --- a/fpdfsdk/fpdfppo.cpp +++ b/fpdfsdk/fpdfppo.cpp @@ -91,7 +91,7 @@ bool ParserPageRangeString(CFX_ByteString rangstring, nStringTo = rangstring.Find(',', nStringFrom); if (nStringTo == -1) nStringTo = nLength; - cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); + cbMidRange = rangstring.Right(nStringTo - nStringFrom); int nMid = cbMidRange.Find('-'); if (nMid == -1) { long lPageNum = atol(cbMidRange.c_str()); @@ -99,7 +99,7 @@ bool ParserPageRangeString(CFX_ByteString rangstring, return false; pageArray->push_back((uint16_t)lPageNum); } else { - int nStartPageNum = atol(cbMidRange.Mid(0, nMid).c_str()); + int nStartPageNum = atol(cbMidRange.Left(nMid).c_str()); if (nStartPageNum == 0) return false; diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index bf84b9cd91..06ed64c7cc 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -980,11 +980,10 @@ bool CJS_PublicMethods::AFNumber_Keystroke(CJS_Runtime* pRuntime, } } - CFX_WideString wprefix = wstrValue.Mid(0, pEvent->SelStart()); + CFX_WideString wprefix = wstrValue.Left(pEvent->SelStart()); CFX_WideString wpostfix; if (pEvent->SelEnd() < wstrValue.GetLength()) - wpostfix = wstrValue.Mid(pEvent->SelEnd(), - wstrValue.GetLength() - pEvent->SelEnd()); + wpostfix = wstrValue.Right(wstrValue.GetLength() - pEvent->SelEnd()); val = wprefix + wstrChange + wpostfix; return true; } @@ -1532,14 +1531,13 @@ bool CJS_PublicMethods::AFMergeChange(CJS_Runtime* pRuntime, CFX_WideString prefix, postfix; if (pEventHandler->SelStart() >= 0) - prefix = swValue.Mid(0, pEventHandler->SelStart()); + prefix = swValue.Left(pEventHandler->SelStart()); else prefix = L""; if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength()) - postfix = swValue.Mid(pEventHandler->SelEnd(), - swValue.GetLength() - pEventHandler->SelEnd()); + postfix = swValue.Right(swValue.GetLength() - pEventHandler->SelEnd()); else postfix = L""; -- cgit v1.2.3