diff options
-rw-r--r-- | core/fxcrt/fx_bidi.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/fx_extension.cpp | 16 | ||||
-rw-r--r-- | core/fxge/ge/cfx_fontmapper.cpp | 12 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/javascript/PublicMethods.cpp | 20 | ||||
-rw-r--r-- | fpdfsdk/javascript/app.cpp | 15 | ||||
-rw-r--r-- | fxbarcode/BC_UtilCodingConvert.cpp | 4 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_Base256Encoder.cpp | 5 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_HighLevelEncoder.cpp | 3 | ||||
-rw-r--r-- | fxbarcode/oned/BC_OnedCodaBarWriter.cpp | 15 | ||||
-rw-r--r-- | fxbarcode/oned/BC_OnedCode128Writer.cpp | 16 | ||||
-rw-r--r-- | fxbarcode/oned/BC_OnedCode39Writer.cpp | 6 | ||||
-rw-r--r-- | fxbarcode/oned/BC_OnedEAN13Writer.cpp | 12 | ||||
-rw-r--r-- | fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp | 5 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_rtfbreak_unittest.cpp | 8 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 7 |
16 files changed, 53 insertions, 101 deletions
diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp index 5ad6439e07..49333f6a76 100644 --- a/core/fxcrt/fx_bidi.cpp +++ b/core/fxcrt/fx_bidi.cpp @@ -52,8 +52,8 @@ CFX_BidiString::CFX_BidiString(const CFX_WideString& str) : m_Str(str), m_pBidiChar(new CFX_BidiChar), m_eOverallDirection(CFX_BidiChar::LEFT) { - for (int i = 0; i < m_Str.GetLength(); ++i) { - if (m_pBidiChar->AppendChar(m_Str.GetAt(i))) + for (const auto& c : m_Str) { + if (m_pBidiChar->AppendChar(c)) m_Order.push_back(m_pBidiChar->GetSegmentInfo()); } if (m_pBidiChar->EndChar()) diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index acdce048e0..f3e72fd6df 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -509,11 +509,11 @@ int32_t FXSYS_strnicmp(const char* s1, const char* s2, size_t count) { uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase) { uint32_t dwHashCode = 0; if (bIgnoreCase) { - for (FX_STRSIZE i = 0; i < str.GetLength(); ++i) - dwHashCode = 31 * dwHashCode + FXSYS_tolower(str.CharAt(i)); + for (const auto& c : str) + dwHashCode = 31 * dwHashCode + FXSYS_tolower(c); } else { - for (FX_STRSIZE i = 0; i < str.GetLength(); ++i) - dwHashCode = 31 * dwHashCode + str.CharAt(i); + for (const auto& c : str) + dwHashCode = 31 * dwHashCode + c; } return dwHashCode; } @@ -521,11 +521,11 @@ uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase) { uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase) { uint32_t dwHashCode = 0; if (bIgnoreCase) { - for (FX_STRSIZE i = 0; i < str.GetLength(); ++i) - dwHashCode = 1313 * dwHashCode + FXSYS_tolower(str.CharAt(i)); + for (const auto& c : str) + dwHashCode = 1313 * dwHashCode + FXSYS_tolower(c); } else { - for (FX_STRSIZE i = 0; i < str.GetLength(); ++i) - dwHashCode = 1313 * dwHashCode + str.CharAt(i); + for (const auto& c : str) + dwHashCode = 1313 * dwHashCode + c; } return dwHashCode; } diff --git a/core/fxge/ge/cfx_fontmapper.cpp b/core/fxge/ge/cfx_fontmapper.cpp index 0cff344599..ff80685d96 100644 --- a/core/fxge/ge/cfx_fontmapper.cpp +++ b/core/fxge/ge/cfx_fontmapper.cpp @@ -6,6 +6,7 @@ #include "core/fxge/cfx_fontmapper.h" +#include <algorithm> #include <memory> #include <utility> #include <vector> @@ -326,14 +327,9 @@ void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) { if (name == m_LastFamily) return; - const uint8_t* ptr = name.raw_str(); - bool bLocalized = false; - for (int i = 0; i < name.GetLength(); i++) { - if (ptr[i] > 0x80) { - bLocalized = true; - break; - } - } + bool bLocalized = std::any_of(name.begin(), name.end(), [](const char& c) { + return static_cast<uint8_t>(c) > 0x80; + }); if (bLocalized) { void* hFont = m_pFontInfo->GetFont(name.c_str()); 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<CFX_WideString> 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; } diff --git a/fxbarcode/BC_UtilCodingConvert.cpp b/fxbarcode/BC_UtilCodingConvert.cpp index f1dea885c3..f0f497a07b 100644 --- a/fxbarcode/BC_UtilCodingConvert.cpp +++ b/fxbarcode/BC_UtilCodingConvert.cpp @@ -25,9 +25,7 @@ void CBC_UtilCodingConvert::LocaleToUtf8(const CFX_ByteString& src, std::vector<uint8_t>& dst) { CFX_WideString unicode = CFX_WideString::FromLocal(src.AsStringC()); CFX_ByteString utf8 = unicode.UTF8Encode(); - for (int32_t i = 0; i < utf8.GetLength(); i++) { - dst.push_back(utf8[i]); - } + dst = std::vector<uint8_t>(utf8.begin(), utf8.end()); } void CBC_UtilCodingConvert::Utf8ToLocale(const std::vector<uint8_t>& src, diff --git a/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/fxbarcode/datamatrix/BC_Base256Encoder.cpp index 1b8db85bdd..dd49c8e0f5 100644 --- a/fxbarcode/datamatrix/BC_Base256Encoder.cpp +++ b/fxbarcode/datamatrix/BC_Base256Encoder.cpp @@ -70,9 +70,8 @@ void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { return; } } - for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) { - context.writeCodeword( - randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1)); + for (const auto& c : buffer) { + context.writeCodeword(randomize255State(c, context.getCodewordCount() + 1)); } } wchar_t CBC_Base256Encoder::randomize255State(wchar_t ch, diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index 041272ef8c..cce9749749 100644 --- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -63,8 +63,7 @@ std::vector<uint8_t>& CBC_HighLevelEncoder::getBytesForMessage( CFX_WideString msg) { CFX_ByteString bytestr; CBC_UtilCodingConvert::UnicodeToUTF8(msg, bytestr); - for (int32_t i = 0; i < bytestr.GetLength(); i++) - m_bytearray.push_back(bytestr.GetAt(i)); + m_bytearray.insert(m_bytearray.end(), bytestr.begin(), bytestr.end()); return m_bytearray; } CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp index 6c04cafe7b..d3706ab96d 100644 --- a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp +++ b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp @@ -108,18 +108,11 @@ bool CBC_OnedCodaBarWriter::FindChar(wchar_t ch, bool isContent) { } bool CBC_OnedCodaBarWriter::CheckContentValidity( const CFX_WideStringC& contents) { - wchar_t ch; - int32_t index = 0; - for (index = 0; index < contents.GetLength(); index++) { - ch = contents.GetAt(index); - if (FindChar(ch, false)) { - continue; - } else { - return false; - } - } - return true; + return std::all_of( + contents.begin(), contents.end(), + [this](const wchar_t& ch) { return this->FindChar(ch, false); }); } + CFX_WideString CBC_OnedCodaBarWriter::FilterContents( const CFX_WideStringC& contents) { CFX_WideString filtercontents; diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp index 53f4d01449..e2b6823414 100644 --- a/fxbarcode/oned/BC_OnedCode128Writer.cpp +++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp @@ -113,22 +113,14 @@ CFX_WideString CBC_OnedCode128Writer::FilterContents( } CFX_WideString filtercontents; if (m_codeFormat == BC_CODE128_B) { - for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) { - ch = filterChineseChar.GetAt(i); - if (ch >= 32 && ch <= 126) { + for (const auto& ch : filterChineseChar) { + if (ch >= 32 && ch <= 126) filtercontents += ch; - } else { - continue; - } } } else if (m_codeFormat == BC_CODE128_C) { - for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) { - ch = filterChineseChar.GetAt(i); - if (ch >= 32 && ch <= 106) { + for (const auto& ch : filterChineseChar) { + if (ch >= 32 && ch <= 106) filtercontents += ch; - } else { - continue; - } } } else { filtercontents = contents; diff --git a/fxbarcode/oned/BC_OnedCode39Writer.cpp b/fxbarcode/oned/BC_OnedCode39Writer.cpp index bcc64d83bd..b1a56cad40 100644 --- a/fxbarcode/oned/BC_OnedCode39Writer.cpp +++ b/fxbarcode/oned/BC_OnedCode39Writer.cpp @@ -163,11 +163,11 @@ char CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents, } int32_t checksum = 0; int32_t len = (int32_t)strlen(ALPHABET_STRING); - for (int32_t i = 0; i < contents.GetLength(); i++) { + for (const auto& c : contents) { int32_t j = 0; for (; j < len; j++) { - if (ALPHABET_STRING[j] == contents[i]) { - if (contents[i] != '*') + if (ALPHABET_STRING[j] == c) { + if (c != '*') checksum += j; break; } diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp index a11938a4d9..96b51b0570 100644 --- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp @@ -48,17 +48,13 @@ CBC_OnedEAN13Writer::CBC_OnedEAN13Writer() { m_codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3; } CBC_OnedEAN13Writer::~CBC_OnedEAN13Writer() {} + bool CBC_OnedEAN13Writer::CheckContentValidity( const CFX_WideStringC& contents) { - for (int32_t i = 0; i < contents.GetLength(); i++) { - if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') { - continue; - } else { - return false; - } - } - return true; + return std::all_of(contents.begin(), contents.end(), + [](const wchar_t& w) { return w >= L'0' && w <= L'9'; }); } + CFX_WideString CBC_OnedEAN13Writer::FilterContents( const CFX_WideStringC& contents) { CFX_WideString filtercontents; diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp index ac8b0186f6..f65cfe46ae 100644 --- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp +++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp @@ -71,10 +71,7 @@ CFX_WideString CBC_PDF417HighLevelEncoder::encodeHighLevel( } msg += ch; } - std::vector<uint8_t> byteArr; - for (int32_t k = 0; k < bytes.GetLength(); k++) { - byteArr.push_back(bytes.GetAt(k)); - } + std::vector<uint8_t> byteArr(bytes.begin(), bytes.end()); CFX_WideString sb; len = msg.GetLength(); int32_t p = 0; diff --git a/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp b/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp index d84621a595..cc3c86cadb 100644 --- a/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp @@ -53,8 +53,8 @@ TEST_F(RTFBreakTest, AddChars) { auto b = CreateBreak(FX_LAYOUTSTYLE_ExpandTab); CFX_WideString str(L"Input String."); - for (int32_t i = 0; i < str.GetLength(); i++) - EXPECT_EQ(CFX_BreakType::None, b->AppendChar(str.GetAt(i))); + for (const auto& c : str) + EXPECT_EQ(CFX_BreakType::None, b->AppendChar(c)); EXPECT_EQ(CFX_BreakType::Paragraph, b->AppendChar(L'\n')); ASSERT_EQ(1, b->CountBreakPieces()); @@ -65,8 +65,8 @@ TEST_F(RTFBreakTest, AddChars) { EXPECT_EQ(0, b->GetCurrentLineForTesting()->GetLineEnd()); str = L"Second str."; - for (int32_t i = 0; i < str.GetLength(); i++) - EXPECT_EQ(CFX_BreakType::None, b->AppendChar(str.GetAt(i))); + for (const auto& c : str) + EXPECT_EQ(CFX_BreakType::None, b->AppendChar(c)); // Force the end of the break at the end of the string. b->EndBreak(CFX_BreakType::Paragraph); diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index ead2a7dbe3..4621dfe134 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -3472,8 +3472,7 @@ void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString, wchar_t strReserved[] = {';', '/', '?', ':', '@', '=', '&'}; wchar_t strSpecial[] = {'$', '-', '+', '!', '*', '\'', '(', ')', ','}; const wchar_t* strCode = L"0123456789abcdef"; - for (int32_t u = 0; u < wsURLString.GetLength(); ++u) { - wchar_t ch = wsURLString.GetAt(u); + for (auto ch : wsURLString) { int32_t i = 0; int32_t iCount = FX_ArraySize(strUnsafe); while (i < iCount) { @@ -3624,9 +3623,7 @@ void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString, strEncode[7] = ';'; strEncode[8] = 0; const wchar_t* strCode = L"0123456789abcdef"; - const wchar_t* pData = wsXMLString.c_str(); - for (int32_t u = 0; u < wsXMLString.GetLength(); ++u) { - wchar_t ch = pData[u]; + for (const auto& ch : wsXMLString) { switch (ch) { case '"': wsResultBuf.AppendChar('&'); |