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 <rharrison@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index bf84b9c..06ed64c 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -980,11 +980,10 @@
}
}
- 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 @@
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"";