diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-08-15 10:37:59 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-15 15:03:10 +0000 |
commit | 8a1758bf11c2d741e0cddc761b1dd2cdf564db93 (patch) | |
tree | 82cbafc46f574a05ae0c1d1d3d7f9ebde6cb932d /fpdfsdk | |
parent | 171cb27a720036c48ae3a6176084e880742af0a9 (diff) | |
download | pdfium-8a1758bf11c2d741e0cddc761b1dd2cdf564db93.tar.xz |
Remove GetAt from string classes
This method duplicates the behaviour of the const [] operator and
doesn't offer any additional safety. Folding them into one
implementation.
SetAt is retained, since implementing the non-const [] operator to
replace SetAt has potential performance concerns. Specifically many
non-obvious cases of reading an element using [] will cause a realloc
& copy.
BUG=pdfium:860
Change-Id: I3ef5e5e5a15376f040256b646eb0d90636e24b67
Reviewed-on: https://pdfium-review.googlesource.com/10870
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/PublicMethods.cpp | 38 |
2 files changed, 20 insertions, 20 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 77878a53ed..9b821471c2 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -1018,7 +1018,7 @@ bool Document::documentFileName(CJS_Runtime* pRuntime, CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); int32_t i = wsFilePath.GetLength() - 1; for (; i >= 0; i--) { - if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') + if (wsFilePath[i] == L'\\' || wsFilePath[i] == L'/') break; } if (i >= 0 && i < wsFilePath.GetLength() - 1) { diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index bf35a67edc..2996316d79 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -235,7 +235,7 @@ int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, if (i - nStart > 10) break; - wchar_t c = str.GetAt(i); + wchar_t c = str[i]; if (!std::iswdigit(c)) break; @@ -254,7 +254,7 @@ CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& str, CFX_WideString swRet; nSkip = 0; for (int i = nStart, sz = str.GetLength(); i < sz; i++) { - wchar_t c = str.GetAt(i); + wchar_t c = str[i]; if (!std::iswdigit(c)) break; @@ -286,7 +286,7 @@ double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value, if (nIndex > 2) break; - wchar_t c = value.GetAt(i); + wchar_t c = value[i]; if (std::iswdigit(c)) { number[nIndex++] = ParseStringInteger(value, i, nSkip, 4); i += nSkip; @@ -373,7 +373,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, if (bExit) break; - wchar_t c = format.GetAt(i); + wchar_t c = format[i]; switch (c) { case ':': case '.': @@ -396,7 +396,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, int nSkip = 0; int remaining = format.GetLength() - i - 1; - if (remaining == 0 || format.GetAt(i + 1) != c) { + if (remaining == 0 || format[i + 1] != c) { switch (c) { case 'y': i++; @@ -433,12 +433,12 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, j += nSkip; break; case 't': - bPm = (j < value.GetLength() && value.GetAt(j) == 'p'); + bPm = (j < value.GetLength() && value[j] == 'p'); i++; j++; break; } - } else if (remaining == 1 || format.GetAt(i + 2) != c) { + } else if (remaining == 1 || format[i + 2] != c) { switch (c) { case 'y': nYear = ParseStringInteger(value, j, nSkip, 4); @@ -476,13 +476,13 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, j += nSkip; break; case 't': - bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && - value.GetAt(j + 1) == 'm'); + bPm = (j + 1 < value.GetLength() && value[j] == 'p' && + value[j + 1] == 'm'); i += 2; j += 2; break; } - } else if (remaining == 2 || format.GetAt(i + 3) != c) { + } else if (remaining == 2 || format[i + 3] != c) { switch (c) { case 'm': { CFX_WideString sMonth = ParseStringString(value, j, nSkip); @@ -510,7 +510,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, j += 3; break; } - } else if (remaining == 3 || format.GetAt(i + 4) != c) { + } else if (remaining == 3 || format[i + 4] != c) { switch (c) { case 'y': nYear = ParseStringInteger(value, j, nSkip, 4); @@ -548,7 +548,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, break; } } else { - if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) { + if (j >= value.GetLength() || format[i] != value[j]) { bBadFormat = true; bExit = true; } @@ -566,7 +566,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, default: if (value.GetLength() <= j) { bExit = true; - } else if (format.GetAt(i) != value.GetAt(j)) { + } else if (format[i] != value[j]) { bBadFormat = true; bExit = true; } @@ -630,7 +630,7 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, int i = 0; while (i < format.GetLength()) { - wchar_t c = format.GetAt(i); + wchar_t c = format[i]; int remaining = format.GetLength() - i - 1; sPart = L""; switch (c) { @@ -642,7 +642,7 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, case 'M': case 's': case 't': - if (remaining == 0 || format.GetAt(i + 1) != c) { + if (remaining == 0 || format[i + 1] != c) { switch (c) { case 'y': sPart += c; @@ -670,7 +670,7 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, break; } i++; - } else if (remaining == 1 || format.GetAt(i + 2) != c) { + } else if (remaining == 1 || format[i + 2] != c) { switch (c) { case 'y': sPart.Format(L"%02d", nYear - (nYear / 100) * 100); @@ -698,7 +698,7 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, break; } i += 2; - } else if (remaining == 2 || format.GetAt(i + 3) != c) { + } else if (remaining == 2 || format[i + 3] != c) { switch (c) { case 'm': i += 3; @@ -712,7 +712,7 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, sPart += c; break; } - } else if (remaining == 3 || format.GetAt(i + 4) != c) { + } else if (remaining == 3 || format[i + 4] != c) { switch (c) { case 'y': sPart.Format(L"%04d", nYear); @@ -1762,7 +1762,7 @@ bool CJS_PublicMethods::AFExtractNums(CJS_Runtime* pRuntime, } CFX_WideString str = params[0].ToCFXWideString(pRuntime); - if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') + if (str[0] == L'.' || str[0] == L',') str = L"0" + str; CFX_WideString sPart; |