summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fgas/crt/cfgas_formatstring.cpp64
-rw-r--r--xfa/fxfa/parser/cxfa_localevalue.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_nodelocale.cpp36
-rw-r--r--xfa/fxfa/parser/cxfa_nodelocale.h7
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale.cpp78
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale.h7
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp14
8 files changed, 93 insertions, 122 deletions
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index 1edcf1e51d..0162100949 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -1151,12 +1151,10 @@ bool CFGAS_FormatString::ParseNum(const WideString& wsSrcNum,
return false;
int32_t iExponent = 0;
- WideString wsDotSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal);
- WideString wsGroupSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping);
+ WideString wsDotSymbol = pLocale->GetDecimalSymbol();
+ WideString wsGroupSymbol = pLocale->GetGroupingSymbol();
int32_t iGroupLen = wsGroupSymbol.GetLength();
- WideString wsMinus = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus);
+ WideString wsMinus = pLocale->GetMinusSymbol();
int32_t iMinusLen = wsMinus.GetLength();
const wchar_t* str = wsSrcNum.c_str();
int len = wsSrcNum.GetLength();
@@ -1259,8 +1257,7 @@ bool CFGAS_FormatString::ParseNum(const WideString& wsSrcNum,
break;
}
case '$': {
- WideString wsSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol);
+ WideString wsSymbol = pLocale->GetCurrencySymbol();
int32_t iSymbolLen = wsSymbol.GetLength();
cc -= iSymbolLen - 1;
if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen))
@@ -1301,8 +1298,7 @@ bool CFGAS_FormatString::ParseNum(const WideString& wsSrcNum,
}
break;
case '%': {
- WideString wsSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent);
+ WideString wsSymbol = pLocale->GetPercentSymbol();
int32_t iSysmbolLen = wsSymbol.GetLength();
cc -= iSysmbolLen - 1;
if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen))
@@ -1435,8 +1431,7 @@ bool CFGAS_FormatString::ParseNum(const WideString& wsSrcNum,
break;
}
case '$': {
- WideString wsSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol);
+ WideString wsSymbol = pLocale->GetCurrencySymbol();
int32_t iSymbolLen = wsSymbol.GetLength();
if (cc + iSymbolLen > len ||
wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) {
@@ -1477,8 +1472,7 @@ bool CFGAS_FormatString::ParseNum(const WideString& wsSrcNum,
case 'v':
return false;
case '%': {
- WideString wsSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent);
+ WideString wsSymbol = pLocale->GetPercentSymbol();
int32_t iSysmbolLen = wsSymbol.GetLength();
if (cc + iSysmbolLen <= len &&
!wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) {
@@ -1932,8 +1926,7 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
wsSrcNum.TrimRight(L".");
}
- WideString wsGroupSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping);
+ WideString wsGroupSymbol = pLocale->GetGroupingSymbol();
bool bNeg = false;
if (wsSrcNum[0] == '-') {
bNeg = true;
@@ -1988,8 +1981,7 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
break;
case 'S':
if (bNeg) {
- *wsOutput =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput;
+ *wsOutput = pLocale->GetMinusSymbol() + *wsOutput;
bAddNeg = true;
} else {
wsOutput->InsertAtFront(L' ');
@@ -1998,8 +1990,7 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
break;
case 's':
if (bNeg) {
- *wsOutput =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput;
+ *wsOutput = pLocale->GetMinusSymbol() + *wsOutput;
bAddNeg = true;
}
ccf--;
@@ -2010,9 +2001,7 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
break;
}
case '$': {
- *wsOutput =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol) +
- *wsOutput;
+ *wsOutput = pLocale->GetCurrencySymbol() + *wsOutput;
ccf--;
break;
}
@@ -2049,8 +2038,7 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
}
break;
case '%': {
- *wsOutput =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent) + *wsOutput;
+ *wsOutput = pLocale->GetPercentSymbol() + *wsOutput;
ccf--;
break;
}
@@ -2089,26 +2077,23 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
*wsOutput += wsSrcNum[i];
}
if (pdfium::base::checked_cast<int32_t>(dot_index.value()) < len) {
- *wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal);
+ *wsOutput += pLocale->GetDecimalSymbol();
*wsOutput += wsSrcNum.Right(len - dot_index.value() - 1);
}
- if (bNeg) {
- *wsOutput =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput;
- }
+ if (bNeg)
+ *wsOutput = pLocale->GetMinusSymbol() + *wsOutput;
+
return false;
}
if (dot_index_f ==
pdfium::base::checked_cast<int32_t>(wsNumFormat.GetLength())) {
- if (!bAddNeg && bNeg) {
- *wsOutput =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput;
- }
+ if (!bAddNeg && bNeg)
+ *wsOutput = pLocale->GetMinusSymbol() + *wsOutput;
+
return true;
}
- WideString wsDotSymbol =
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal);
+ WideString wsDotSymbol = pLocale->GetDecimalSymbol();
if (strf[dot_index_f] == 'V') {
*wsOutput += wsDotSymbol;
} else if (strf[dot_index_f] == '.') {
@@ -2166,8 +2151,7 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
break;
}
case '$':
- *wsOutput +=
- pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol);
+ *wsOutput += pLocale->GetCurrencySymbol();
ccf++;
break;
case 'c':
@@ -2203,7 +2187,7 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
}
break;
case '%':
- *wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent);
+ *wsOutput += pLocale->GetPercentSymbol();
ccf++;
break;
case '8':
@@ -2232,8 +2216,8 @@ bool CFGAS_FormatString::FormatStrNum(const WideStringView& wsInputNum,
}
}
if (!bAddNeg && bNeg) {
- *wsOutput = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) +
- (*wsOutput)[0] + wsOutput->Right(wsOutput->GetLength() - 1);
+ *wsOutput = pLocale->GetMinusSymbol() + (*wsOutput)[0] +
+ wsOutput->Right(wsOutput->GetLength() - 1);
}
return true;
}
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) {