From 94afac986c9d6232b7791acff4f23d99fbd004ae Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 8 Dec 2016 15:21:40 -0800 Subject: Replace CFX_WideStringCArray with std::vector. Review-Url: https://codereview.chromium.org/2562833002 --- core/fxcrt/fx_basic.h | 1 - xfa/fxfa/fm2js/xfa_expression.cpp | 33 +++++++++++++++------------------ xfa/fxfa/fm2js/xfa_expression.h | 8 ++++---- xfa/fxfa/fm2js/xfa_fmparse.cpp | 20 +++++++------------- xfa/fxfa/fm2js/xfa_program.cpp | 3 ++- 5 files changed, 28 insertions(+), 37 deletions(-) diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h index 30673f6525..d320e7d786 100644 --- a/core/fxcrt/fx_basic.h +++ b/core/fxcrt/fx_basic.h @@ -317,7 +317,6 @@ class CFX_ArrayTemplate : public CFX_BasicArray { }; #ifdef PDF_ENABLE_XFA -typedef CFX_ArrayTemplate CFX_WideStringCArray; typedef CFX_ArrayTemplate CFX_FloatArray; typedef CFX_ArrayTemplate CFX_ByteArray; typedef CFX_ArrayTemplate CFX_Int32Array; diff --git a/xfa/fxfa/fm2js/xfa_expression.cpp b/xfa/fxfa/fm2js/xfa_expression.cpp index a668fc9089..a4d1195933 100644 --- a/xfa/fxfa/fm2js/xfa_expression.cpp +++ b/xfa/fxfa/fm2js/xfa_expression.cpp @@ -34,12 +34,12 @@ CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( uint32_t line, bool isGlobal, const CFX_WideStringC& wsName, - std::unique_ptr pArguments, - std::vector>&& pExpressions) + std::vector&& arguments, + std::vector>&& expressions) : CXFA_FMExpression(line, XFA_FM_EXPTYPE_FUNC), m_wsName(wsName), - m_pArguments(std::move(pArguments)), - m_pExpressions(std::move(pExpressions)), + m_pArguments(std::move(arguments)), + m_pExpressions(std::move(expressions)), m_isGlobal(isGlobal) {} CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {} @@ -60,21 +60,18 @@ void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << m_wsName; } javascript << FX_WSTRC(L"("); - if (m_pArguments != 0) { - CFX_WideStringC identifier = 0; - for (int i = 0; i < m_pArguments->GetSize(); ++i) { - identifier = m_pArguments->GetAt(i); - if (identifier.GetAt(0) == L'!') { - CFX_WideString tempIdentifier = - EXCLAMATION_IN_IDENTIFIER + identifier.Mid(1); - javascript << tempIdentifier; - } else { - javascript << identifier; - } - if (i + 1 < m_pArguments->GetSize()) { - javascript << FX_WSTRC(L", "); - } + bool bNeedComma = false; + for (const auto& identifier : m_pArguments) { + if (bNeedComma) + javascript << FX_WSTRC(L", "); + if (identifier.GetAt(0) == L'!') { + CFX_WideString tempIdentifier = + EXCLAMATION_IN_IDENTIFIER + identifier.Mid(1); + javascript << tempIdentifier; + } else { + javascript << identifier; } + bNeedComma = true; } javascript << FX_WSTRC(L")\n{\n"); javascript << FX_WSTRC(L"var "); diff --git a/xfa/fxfa/fm2js/xfa_expression.h b/xfa/fxfa/fm2js/xfa_expression.h index a19df268b8..6b55ea5815 100644 --- a/xfa/fxfa/fm2js/xfa_expression.h +++ b/xfa/fxfa/fm2js/xfa_expression.h @@ -40,13 +40,13 @@ class CXFA_FMExpression { class CXFA_FMFunctionDefinition : public CXFA_FMExpression { public: - // Takes ownership of |pExpressions|. + // Takes ownership of |arguments| and |expressions|. CXFA_FMFunctionDefinition( uint32_t line, bool isGlobal, const CFX_WideStringC& wsName, - std::unique_ptr pArguments, - std::vector>&& pExpressions); + std::vector&& arguments, + std::vector>&& expressions); ~CXFA_FMFunctionDefinition() override; void ToJavaScript(CFX_WideTextBuf& javascript) override; @@ -54,7 +54,7 @@ class CXFA_FMFunctionDefinition : public CXFA_FMExpression { private: CFX_WideStringC m_wsName; - std::unique_ptr m_pArguments; + std::vector m_pArguments; std::vector> m_pExpressions; bool m_isGlobal; }; diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp index 53e94666de..2dfdfdb4d2 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.cpp +++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp @@ -78,9 +78,8 @@ CXFA_FMParse::ParseTopExpression() { } std::unique_ptr CXFA_FMParse::ParseFunction() { - std::unique_ptr expr; CFX_WideStringC ident; - std::unique_ptr pArguments; + std::vector arguments; std::vector> expressions; uint32_t line = m_pToken->m_uLinenum; NextToken(); @@ -96,12 +95,9 @@ std::unique_ptr CXFA_FMParse::ParseFunction() { if (m_pToken->m_type == TOKrparen) { NextToken(); } else { - pArguments = pdfium::MakeUnique(); - CFX_WideStringC p; while (1) { if (m_pToken->m_type == TOKidentifier) { - p = m_pToken->m_wstring; - pArguments->Add(p); + arguments.push_back(m_pToken->m_wstring); NextToken(); if (m_pToken->m_type == TOKcomma) { NextToken(); @@ -129,13 +125,11 @@ std::unique_ptr CXFA_FMParse::ParseFunction() { expressions = ParseTopExpression(); Check(TOKendfunc); } - if (m_pErrorInfo->message.IsEmpty()) { - expr = pdfium::MakeUnique( - line, false, ident, std::move(pArguments), std::move(expressions)); - } else if (pArguments) { - pArguments->RemoveAll(); - } - return expr; + if (!m_pErrorInfo->message.IsEmpty()) + return nullptr; + + return pdfium::MakeUnique( + line, false, ident, std::move(arguments), std::move(expressions)); } std::unique_ptr CXFA_FMParse::ParseExpression() { diff --git a/xfa/fxfa/fm2js/xfa_program.cpp b/xfa/fxfa/fm2js/xfa_program.cpp index 4d37f74767..514b7a6a23 100644 --- a/xfa/fxfa/fm2js/xfa_program.cpp +++ b/xfa/fxfa/fm2js/xfa_program.cpp @@ -26,8 +26,9 @@ int32_t CXFA_FMProgram::ParseProgram() { if (!m_pErrorInfo.message.IsEmpty()) return -1; + std::vector arguments; m_globalFunction = pdfium::MakeUnique( - 1, true, L"", nullptr, std::move(expressions)); + 1, true, L"", std::move(arguments), std::move(expressions)); return 0; } -- cgit v1.2.3