diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-04-16 21:01:58 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-16 21:01:58 +0000 |
commit | 574ee81e426a7390e5cdf28f2fe8ec03f6c2da98 (patch) | |
tree | 8e76dbf6be872f1008738b437fb6c63f6c23096b /xfa/fxfa | |
parent | c49e62e40ed87cdcab08b8975b7822727ba9dd72 (diff) | |
download | pdfium-574ee81e426a7390e5cdf28f2fe8ec03f6c2da98.tar.xz |
Split GetNumbericSymbol into individual methods
This CL removes the GetNumbericSymbol method and adds individual methods
for each symbol we retrieve.
Change-Id: Id14108e5ea43a76250e18a1aa13bdbb05e928cdc
Reviewed-on: https://pdfium-review.googlesource.com/30695
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/parser/cxfa_localevalue.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_nodelocale.cpp | 36 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_nodelocale.h | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xmllocale.cpp | 78 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xmllocale.h | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp | 14 |
7 files changed, 69 insertions, 82 deletions
diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp index b129960f7d..057eaeba2c 100644 --- a/xfa/fxfa/parser/cxfa_localevalue.cpp +++ b/xfa/fxfa/parser/cxfa_localevalue.cpp @@ -760,7 +760,7 @@ bool CXFA_LocaleValue::ValidateNumericTemp(const WideString& wsNumeric, WideString wsDecimalSymbol; if (pLocale) - wsDecimalSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); + wsDecimalSymbol = pLocale->GetDecimalSymbol(); else wsDecimalSymbol = WideString(L'.'); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index ff9475970f..10f0a40017 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -4564,8 +4564,7 @@ WideString CXFA_Node::FormatNumStr(const WideString& wsValue, return L""; WideString wsSrcNum = wsValue; - WideString wsGroupSymbol = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping); + WideString wsGroupSymbol = pLocale->GetGroupingSymbol(); bool bNeg = false; if (wsSrcNum[0] == '-') { bNeg = true; @@ -4587,11 +4586,11 @@ WideString CXFA_Node::FormatNumStr(const WideString& wsValue, wsOutput += wsSrcNum[i]; } if (dot_index.value() < wsSrcNum.GetLength()) { - wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); + wsOutput += pLocale->GetDecimalSymbol(); wsOutput += wsSrcNum.Right(wsSrcNum.GetLength() - dot_index.value() - 1); } if (bNeg) - return pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; + return pLocale->GetMinusSymbol() + wsOutput; return wsOutput; } diff --git a/xfa/fxfa/parser/cxfa_nodelocale.cpp b/xfa/fxfa/parser/cxfa_nodelocale.cpp index 71f4049b6b..4f4e3a958b 100644 --- a/xfa/fxfa/parser/cxfa_nodelocale.cpp +++ b/xfa/fxfa/parser/cxfa_nodelocale.cpp @@ -50,24 +50,24 @@ WideString CXFA_NodeLocale::GetName() const { : nullptr); } -WideString CXFA_NodeLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType) const { - switch (eType) { - case FX_LOCALENUMSYMBOL_Decimal: - return GetSymbol(XFA_Element::NumberSymbols, L"decimal"); - case FX_LOCALENUMSYMBOL_Grouping: - return GetSymbol(XFA_Element::NumberSymbols, L"grouping"); - case FX_LOCALENUMSYMBOL_Percent: - return GetSymbol(XFA_Element::NumberSymbols, L"percent"); - case FX_LOCALENUMSYMBOL_Minus: - return GetSymbol(XFA_Element::NumberSymbols, L"minus"); - case FX_LOCALENUMSYMBOL_Zero: - return GetSymbol(XFA_Element::NumberSymbols, L"zero"); - case FX_LOCALENUMSYMBOL_CurrencySymbol: - return GetSymbol(XFA_Element::CurrencySymbols, L"symbol"); - case FX_LOCALENUMSYMBOL_CurrencyName: - return GetSymbol(XFA_Element::CurrencySymbols, L"isoname"); - } - return WideString(); +WideString CXFA_NodeLocale::GetDecimalSymbol() const { + return GetSymbol(XFA_Element::NumberSymbols, L"decimal"); +} + +WideString CXFA_NodeLocale::GetGroupingSymbol() const { + return GetSymbol(XFA_Element::NumberSymbols, L"grouping"); +} + +WideString CXFA_NodeLocale::GetPercentSymbol() const { + return GetSymbol(XFA_Element::NumberSymbols, L"percent"); +} + +WideString CXFA_NodeLocale::GetMinusSymbol() const { + return GetSymbol(XFA_Element::NumberSymbols, L"minus"); +} + +WideString CXFA_NodeLocale::GetCurrencySymbol() const { + return GetSymbol(XFA_Element::CurrencySymbols, L"symbol"); } WideString CXFA_NodeLocale::GetDateTimeSymbols() const { diff --git a/xfa/fxfa/parser/cxfa_nodelocale.h b/xfa/fxfa/parser/cxfa_nodelocale.h index d1ed800846..e802cd9b34 100644 --- a/xfa/fxfa/parser/cxfa_nodelocale.h +++ b/xfa/fxfa/parser/cxfa_nodelocale.h @@ -23,8 +23,11 @@ class CXFA_NodeLocale : public LocaleIface { // LocaleIface WideString GetName() const override; - WideString GetNumbericSymbol(FX_LOCALENUMSYMBOL eType) const override; - + WideString GetDecimalSymbol() const override; + WideString GetGroupingSymbol() const override; + WideString GetPercentSymbol() const override; + WideString GetMinusSymbol() const override; + WideString GetCurrencySymbol() const override; WideString GetDateTimeSymbols() const override; WideString GetMonthName(int32_t nMonth, bool bAbbr) const override; WideString GetDayName(int32_t nWeek, bool bAbbr) const override; diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp index 93b84ca367..6720d56cba 100644 --- a/xfa/fxfa/parser/cxfa_xmllocale.cpp +++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp @@ -17,6 +17,15 @@ #include "xfa/fxfa/parser/cxfa_timezoneprovider.h" #include "xfa/fxfa/parser/xfa_utils.h" +namespace { + +constexpr wchar_t kNumberSymbols[] = L"numberSymbols"; +constexpr wchar_t kNumberSymbol[] = L"numberSymbol"; +constexpr wchar_t kCurrencySymbols[] = L"currencySymbols"; +constexpr wchar_t kCurrencySymbol[] = L"currencySymbol"; + +} // namespace + // static std::unique_ptr<CXFA_XMLLocale> CXFA_XMLLocale::Create( pdfium::span<uint8_t> data) { @@ -59,54 +68,29 @@ WideString CXFA_XMLLocale::GetName() const { return locale_->GetString(L"name"); } -WideString CXFA_XMLLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType) const { - WideStringView bsSymbols; - WideStringView bsSymbol; - WideStringView wsName; - switch (eType) { - case FX_LOCALENUMSYMBOL_Decimal: - bsSymbols = L"numberSymbols"; - bsSymbol = L"numberSymbol"; - wsName = L"decimal"; - break; - case FX_LOCALENUMSYMBOL_Grouping: - bsSymbols = L"numberSymbols"; - bsSymbol = L"numberSymbol"; - wsName = L"grouping"; - break; - case FX_LOCALENUMSYMBOL_Percent: - bsSymbols = L"numberSymbols"; - bsSymbol = L"numberSymbol"; - wsName = L"percent"; - break; - case FX_LOCALENUMSYMBOL_Minus: - bsSymbols = L"numberSymbols"; - bsSymbol = L"numberSymbol"; - wsName = L"minus"; - break; - case FX_LOCALENUMSYMBOL_Zero: - bsSymbols = L"numberSymbols"; - bsSymbol = L"numberSymbol"; - wsName = L"zero"; - break; - case FX_LOCALENUMSYMBOL_CurrencySymbol: - bsSymbols = L"currencySymbols"; - bsSymbol = L"currencySymbol"; - wsName = L"symbol"; - break; - case FX_LOCALENUMSYMBOL_CurrencyName: - bsSymbols = L"currencySymbols"; - bsSymbol = L"currencySymbol"; - wsName = L"isoname"; - break; - default: - return L""; - } - CFX_XMLElement* patterns = locale_->GetFirstChildNamed(bsSymbols); - if (!patterns) - return L""; +WideString CXFA_XMLLocale::GetDecimalSymbol() const { + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols); + return patterns ? GetPattern(patterns, kNumberSymbol, L"decimal") : L""; +} + +WideString CXFA_XMLLocale::GetGroupingSymbol() const { + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols); + return patterns ? GetPattern(patterns, kNumberSymbol, L"grouping") : L""; +} + +WideString CXFA_XMLLocale::GetPercentSymbol() const { + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols); + return patterns ? GetPattern(patterns, kNumberSymbol, L"percent") : L""; +} + +WideString CXFA_XMLLocale::GetMinusSymbol() const { + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols); + return patterns ? GetPattern(patterns, kNumberSymbol, L"minus") : L""; +} - return GetPattern(patterns, bsSymbol, wsName); +WideString CXFA_XMLLocale::GetCurrencySymbol() const { + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kCurrencySymbols); + return patterns ? GetPattern(patterns, kCurrencySymbol, L"symbol") : L""; } WideString CXFA_XMLLocale::GetDateTimeSymbols() const { diff --git a/xfa/fxfa/parser/cxfa_xmllocale.h b/xfa/fxfa/parser/cxfa_xmllocale.h index 92bd3607ec..757c5349d4 100644 --- a/xfa/fxfa/parser/cxfa_xmllocale.h +++ b/xfa/fxfa/parser/cxfa_xmllocale.h @@ -25,8 +25,11 @@ class CXFA_XMLLocale : public LocaleIface { // LocaleIface WideString GetName() const override; - WideString GetNumbericSymbol(FX_LOCALENUMSYMBOL eType) const override; - + WideString GetDecimalSymbol() const override; + WideString GetGroupingSymbol() const override; + WideString GetPercentSymbol() const override; + WideString GetMinusSymbol() const override; + WideString GetCurrencySymbol() const override; WideString GetDateTimeSymbols() const override; WideString GetMonthName(int32_t nMonth, bool bAbbr) const override; WideString GetDayName(int32_t nWeek, bool bAbbr) const override; diff --git a/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp index e2c5198eb8..32abdeb063 100644 --- a/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp +++ b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp @@ -108,20 +108,18 @@ TEST(CXFA_XMLLocaleTest, GetName) { EXPECT_EQ(L"en_US", locale->GetName()); } -TEST(CXFA_XMLLocaleTest, GetNumbericSymbol) { +TEST(CXFA_XMLLocaleTest, GetNumericSymbols) { auto span = pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)), strlen(xml_data)); auto locale = CXFA_XMLLocale::Create(span); ASSERT_TRUE(locale != nullptr); - EXPECT_EQ(L".", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal)); - EXPECT_EQ(L",", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping)); - EXPECT_EQ(L"%", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent)); - EXPECT_EQ(L"-", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus)); - EXPECT_EQ(L"0", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Zero)); - EXPECT_EQ(L"$", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol)); - EXPECT_EQ(L"USD", locale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencyName)); + EXPECT_EQ(L".", locale->GetDecimalSymbol()); + EXPECT_EQ(L",", locale->GetGroupingSymbol()); + EXPECT_EQ(L"%", locale->GetPercentSymbol()); + EXPECT_EQ(L"-", locale->GetMinusSymbol()); + EXPECT_EQ(L"$", locale->GetCurrencySymbol()); } TEST(CXFA_XMLLocaleTest, GetDateTimeSymbols) { |