From 3c3e271ea9fd19dd535a74b5546b27e3e82dcb81 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 17 Apr 2017 15:38:19 -0700 Subject: Use Byte/WideString iterators Change-Id: I85c8423c177fd7ecd5da90ef89419efc0f9cf44b Reviewed-on: https://pdfium-review.googlesource.com/4262 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fpdfsdk/cpdfsdk_widget.cpp | 6 +++--- fpdfsdk/javascript/PublicMethods.cpp | 20 +++++++------------- fpdfsdk/javascript/app.cpp | 15 +++------------ 3 files changed, 13 insertions(+), 28 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 5f0bf1dc17..a1cd8c7ce4 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -249,10 +249,10 @@ bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, if (data.nSelEnd > data.nSelStart) param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart); - for (int i = 0; i < data.sChange.GetLength(); i++) - param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); - param.m_wsPrevText = data.sValue; + for (const auto& c : data.sChange) + param.m_wsNewText.Insert(data.nSelStart, c); + param.m_wsPrevText = data.sValue; if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && GetFieldType() == FIELDTYPE_RADIOBUTTON) { if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index f479527ef6..b5d4f7ba55 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -1141,8 +1141,7 @@ bool CJS_PublicMethods::AFDate_FormatEx(CJS_Runtime* pRuntime, double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) { std::vector wsArray; CFX_WideString sTemp = L""; - for (int i = 0; i < strValue.GetLength(); ++i) { - wchar_t c = strValue.GetAt(i); + for (const auto& c : strValue) { if (c == L' ' || c == L':') { wsArray.push_back(sTemp); sTemp = L""; @@ -1775,22 +1774,17 @@ bool CJS_PublicMethods::AFExtractNums(CJS_Runtime* pRuntime, CFX_WideString sPart; CJS_Array nums; int nIndex = 0; - for (int i = 0, sz = str.GetLength(); i < sz; i++) { - wchar_t wc = str.GetAt(i); + for (const auto& wc : str) { if (FXSYS_iswdigit(wc)) { sPart += wc; - } else { - if (sPart.GetLength() > 0) { - nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); - sPart = L""; - nIndex++; - } + } else if (sPart.GetLength() > 0) { + nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); + sPart = L""; + nIndex++; } } - - if (sPart.GetLength() > 0) { + if (sPart.GetLength() > 0) nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); - } if (nums.GetLength(pRuntime) > 0) vRet = CJS_Value(pRuntime, nums); diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 400340e38d..6d31d7e2e4 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -696,19 +696,10 @@ bool app::browseForDoc(CJS_Runtime* pRuntime, CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) { CFX_WideString sRet = L"/"; - - for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) { - wchar_t c = sOldPath.GetAt(i); - if (c == L':') { - } else { - if (c == L'\\') { - sRet += L"/"; - } else { - sRet += c; - } - } + for (const wchar_t& c : sOldPath) { + if (c != L':') + sRet += (c == L'\\') ? L'/' : c; } - return sRet; } -- cgit v1.2.3