Make CFGAS_StringFormatter::SplitOnBars() static. Avoid needless creation of some formatter objects. Change-Id: I28fb8cd115c3a6b5d00043bddf76c60e47c05043 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/51871 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fgas/crt/cfgas_stringformatter.cpp b/xfa/fgas/crt/cfgas_stringformatter.cpp index ee8321f..5ce7d12 100644 --- a/xfa/fgas/crt/cfgas_stringformatter.cpp +++ b/xfa/fgas/crt/cfgas_stringformatter.cpp
@@ -829,6 +829,7 @@ CFGAS_StringFormatter::~CFGAS_StringFormatter() {} +// static std::vector<WideString> CFGAS_StringFormatter::SplitOnBars( const WideString& wsFormatString) { std::vector<WideString> wsPatterns;
diff --git a/xfa/fgas/crt/cfgas_stringformatter.h b/xfa/fgas/crt/cfgas_stringformatter.h index 9583724..ed18828 100644 --- a/xfa/fgas/crt/cfgas_stringformatter.h +++ b/xfa/fgas/crt/cfgas_stringformatter.h
@@ -25,7 +25,8 @@ explicit CFGAS_StringFormatter(LocaleMgrIface* pLocaleMgr); ~CFGAS_StringFormatter(); - std::vector<WideString> SplitOnBars(const WideString& wsFormatString); + static std::vector<WideString> SplitOnBars(const WideString& wsFormatString); + FX_LOCALECATEGORY GetCategory(const WideString& wsPattern) const; bool ParseText(const WideString& wsSrcText,
diff --git a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp index c3e7c39..b0acfaf 100644 --- a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp +++ b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
@@ -288,16 +288,16 @@ // } TEST_F(CFGAS_StringFormatterTest, SplitFormatString) { - std::vector<WideString> results = fmt(L"en")->SplitOnBars(L""); + std::vector<WideString> results = CFGAS_StringFormatter::SplitOnBars(L""); EXPECT_EQ(1UL, results.size()); EXPECT_TRUE(results[0].IsEmpty()); - results = fmt(L"en")->SplitOnBars(L"|"); + results = CFGAS_StringFormatter::SplitOnBars(L"|"); EXPECT_EQ(2UL, results.size()); EXPECT_TRUE(results[0].IsEmpty()); EXPECT_TRUE(results[1].IsEmpty()); - results = fmt(L"en")->SplitOnBars( + results = CFGAS_StringFormatter::SplitOnBars( L"null{'No|data'} | null{} | text{999*9999} | text{999*999*9999}"); EXPECT_EQ(4UL, results.size());
diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp index d9515e7..04f70ec 100644 --- a/xfa/fxfa/parser/cxfa_localevalue.cpp +++ b/xfa/fxfa/parser/cxfa_localevalue.cpp
@@ -127,11 +127,12 @@ if (!m_pLocaleMgr) return false; + std::vector<WideString> wsPatterns = + CFGAS_StringFormatter::SplitOnBars(wsPattern); + WideString wsOutput; ScopedLocale scoped_locale(m_pLocaleMgr.Get(), pLocale); - auto pFormat = pdfium::MakeUnique<CFGAS_StringFormatter>(m_pLocaleMgr.Get()); - std::vector<WideString> wsPatterns = pFormat->SplitOnBars(wsPattern); bool bRet = false; size_t i = 0; for (; !bRet && i < wsPatterns.size(); i++) { @@ -261,8 +262,7 @@ LocaleIface* pLocale, XFA_VALUEPICTURE eValueType) const { wsResult.clear(); - auto pFormat = pdfium::MakeUnique<CFGAS_StringFormatter>(m_pLocaleMgr.Get()); - for (const auto& pattern : pFormat->SplitOnBars(wsFormat)) { + for (const auto& pattern : CFGAS_StringFormatter::SplitOnBars(wsFormat)) { if (FormatSinglePattern(wsResult, pattern, pLocale, eValueType)) return true; } @@ -542,9 +542,11 @@ if (!m_pLocaleMgr) return false; + std::vector<WideString> wsPatterns = + CFGAS_StringFormatter::SplitOnBars(wsPattern); + ScopedLocale scoped_locale(m_pLocaleMgr.Get(), pLocale); auto pFormat = pdfium::MakeUnique<CFGAS_StringFormatter>(m_pLocaleMgr.Get()); - std::vector<WideString> wsPatterns = pFormat->SplitOnBars(wsPattern); bool bRet = false; for (size_t i = 0; !bRet && i < wsPatterns.size(); i++) { const WideString& wsFormat = wsPatterns[i];