diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-04-16 17:59:07 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-16 17:59:07 +0000 |
commit | bdbfc08f96f89581bea277d5ddd9755e893067d7 (patch) | |
tree | 3639bd042f64e5a93480a87e5a1d374ffe56a3e6 | |
parent | cce4d31e6e746bae72f2f31676c12f1d2851ade3 (diff) | |
download | pdfium-bdbfc08f96f89581bea277d5ddd9755e893067d7.tar.xz |
Convert CXFA_XMLLocale to CFX_XML
This CL converts CXFA_XMLLocale to use CFX_XML instead of CXML.
Change-Id: I1db617a658548ae5979f2f38d72c5b3000998663
Reviewed-on: https://pdfium-review.googlesource.com/30693
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.cpp | 22 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xmllocale.cpp | 210 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xmllocale.h | 16 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp | 224 |
5 files changed, 271 insertions, 205 deletions
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index 530752e1dd..27d136305b 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -119,3 +119,25 @@ void CFX_XMLElement::Save( } pXMLStream->WriteString(ws.AsStringView()); } + +CFX_XMLElement* CFX_XMLElement::GetFirstChildNamed( + const WideStringView& name) const { + return GetNthChildNamed(name, 0); +} + +CFX_XMLElement* CFX_XMLElement::GetNthChildNamed(const WideStringView& name, + size_t idx) const { + for (auto* child = GetFirstChild(); child; child = child->GetNextSibling()) { + if (child->GetType() != FX_XMLNODE_Element) + continue; + + CFX_XMLElement* elem = static_cast<CFX_XMLElement*>(child); + if (elem->GetName() != name) + continue; + if (idx == 0) + return elem; + + --idx; + } + return nullptr; +} diff --git a/core/fxcrt/xml/cfx_xmlelement.h b/core/fxcrt/xml/cfx_xmlelement.h index e665e24a98..f713114eb7 100644 --- a/core/fxcrt/xml/cfx_xmlelement.h +++ b/core/fxcrt/xml/cfx_xmlelement.h @@ -23,6 +23,10 @@ class CFX_XMLElement : public CFX_XMLAttributeNode { std::unique_ptr<CFX_XMLNode> Clone() override; void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override; + CFX_XMLElement* GetFirstChildNamed(const WideStringView& name) const; + CFX_XMLElement* GetNthChildNamed(const WideStringView& name, + size_t idx) const; + WideString GetLocalTagName() const; WideString GetNamespacePrefix() const; WideString GetNamespaceURI() const; diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp index ce68c71e19..93b84ca367 100644 --- a/xfa/fxfa/parser/cxfa_xmllocale.cpp +++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp @@ -8,8 +8,9 @@ #include <utility> -#include "core/fxcrt/xml/cxml_content.h" -#include "core/fxcrt/xml/cxml_element.h" +#include "core/fxcrt/fx_codepage.h" +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlparser.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_nodelocale.h" @@ -19,92 +20,110 @@ // static std::unique_ptr<CXFA_XMLLocale> CXFA_XMLLocale::Create( pdfium::span<uint8_t> data) { - std::unique_ptr<CXML_Element> pLocale = - CXML_Element::Parse(data.data(), data.size()); - return pLocale ? pdfium::MakeUnique<CXFA_XMLLocale>(std::move(pLocale)) - : nullptr; + auto root = pdfium::MakeUnique<CFX_XMLElement>(L"root"); + auto proxy = + pdfium::MakeRetain<CFX_SeekableStreamProxy>(data.data(), data.size()); + proxy->SetCodePage(FX_CODEPAGE_UTF8); + + CFX_XMLParser parser(root.get(), proxy); + if (!parser.Parse()) + return nullptr; + + CFX_XMLElement* locale = nullptr; + for (auto* child = root->GetFirstChild(); child; + child = child->GetNextSibling()) { + if (child->GetType() != FX_XMLNODE_Element) + continue; + CFX_XMLElement* elem = static_cast<CFX_XMLElement*>(child); + if (elem->GetName() == L"locale") { + locale = elem; + break; + } + } + if (!locale) + return nullptr; + + return pdfium::MakeUnique<CXFA_XMLLocale>(std::move(root), locale); } -CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData) - : m_pLocaleData(std::move(pLocaleData)) {} +CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CFX_XMLElement> root, + CFX_XMLElement* locale) + : xml_root_(std::move(root)), locale_(locale) { + ASSERT(xml_root_); + ASSERT(locale_); +} CXFA_XMLLocale::~CXFA_XMLLocale() {} WideString CXFA_XMLLocale::GetName() const { - return m_pLocaleData ? m_pLocaleData->GetAttrValue("name") : WideString(); + return locale_->GetString(L"name"); } WideString CXFA_XMLLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType) const { - ByteString bsSymbols; - WideString wsName; + WideStringView bsSymbols; + WideStringView bsSymbol; + WideStringView wsName; switch (eType) { case FX_LOCALENUMSYMBOL_Decimal: - bsSymbols = "numberSymbols"; + bsSymbols = L"numberSymbols"; + bsSymbol = L"numberSymbol"; wsName = L"decimal"; break; case FX_LOCALENUMSYMBOL_Grouping: - bsSymbols = "numberSymbols"; + bsSymbols = L"numberSymbols"; + bsSymbol = L"numberSymbol"; wsName = L"grouping"; break; case FX_LOCALENUMSYMBOL_Percent: - bsSymbols = "numberSymbols"; + bsSymbols = L"numberSymbols"; + bsSymbol = L"numberSymbol"; wsName = L"percent"; break; case FX_LOCALENUMSYMBOL_Minus: - bsSymbols = "numberSymbols"; + bsSymbols = L"numberSymbols"; + bsSymbol = L"numberSymbol"; wsName = L"minus"; break; case FX_LOCALENUMSYMBOL_Zero: - bsSymbols = "numberSymbols"; + bsSymbols = L"numberSymbols"; + bsSymbol = L"numberSymbol"; wsName = L"zero"; break; case FX_LOCALENUMSYMBOL_CurrencySymbol: - bsSymbols = "currencySymbols"; + bsSymbols = L"currencySymbols"; + bsSymbol = L"currencySymbol"; wsName = L"symbol"; break; case FX_LOCALENUMSYMBOL_CurrencyName: - bsSymbols = "currencySymbols"; + bsSymbols = L"currencySymbols"; + bsSymbol = L"currencySymbol"; wsName = L"isoname"; break; default: - return WideString(); + return L""; } - CXML_Element* pElement = - m_pLocaleData->GetElement("", bsSymbols.AsStringView(), 0); - if (!pElement) - return WideString(); - - return GetPattern( - pElement, ByteStringView(bsSymbols.c_str(), bsSymbols.GetLength() - 1), - wsName.AsStringView()); + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(bsSymbols); + if (!patterns) + return L""; + + return GetPattern(patterns, bsSymbol, wsName); } WideString CXFA_XMLLocale::GetDateTimeSymbols() const { - if (!m_pLocaleData) - return WideString(); - - CXML_Element* pNumberSymbols = - m_pLocaleData->GetElement("", "dateTimeSymbols", 0); - if (!pNumberSymbols) - return WideString(); - - CXML_Content* pContent = ToContent(pNumberSymbols->GetChild(0)); - if (!pContent) - return WideString(); - - return pContent->m_Content; + CFX_XMLElement* symbols = locale_->GetFirstChildNamed(L"dateTimeSymbols"); + return symbols ? symbols->GetTextData() : L""; } WideString CXFA_XMLLocale::GetMonthName(int32_t nMonth, bool bAbbr) const { - return GetCalendarSymbol("month", nMonth, bAbbr); + return GetCalendarSymbol(L"month", nMonth, bAbbr); } WideString CXFA_XMLLocale::GetDayName(int32_t nWeek, bool bAbbr) const { - return GetCalendarSymbol("day", nWeek, bAbbr); + return GetCalendarSymbol(L"day", nWeek, bAbbr); } WideString CXFA_XMLLocale::GetMeridiemName(bool bAM) const { - return GetCalendarSymbol("meridiem", bAM ? 0 : 1, false); + return GetCalendarSymbol(L"meridiem", bAM ? 0 : 1, false); } FX_TIMEZONE CXFA_XMLLocale::GetTimeZone() const { @@ -112,44 +131,49 @@ FX_TIMEZONE CXFA_XMLLocale::GetTimeZone() const { } WideString CXFA_XMLLocale::GetEraName(bool bAD) const { - return GetCalendarSymbol("era", bAD ? 1 : 0, false); + return GetCalendarSymbol(L"era", bAD ? 1 : 0, false); } -WideString CXFA_XMLLocale::GetCalendarSymbol(const ByteStringView& symbol, - int index, +WideString CXFA_XMLLocale::GetCalendarSymbol(const WideStringView& symbol, + size_t index, bool bAbbr) const { - if (index < 0 || !m_pLocaleData) - return WideString(); - - CXML_Element* pChild = m_pLocaleData->GetElement("", "calendarSymbols", 0); - if (!pChild) - return WideString(); - - ByteString pstrSymbolNames = symbol + "Names"; - CXML_Element* pSymbolNames = - pChild->GetElement("", pstrSymbolNames.AsStringView(), 0); - if (!pSymbolNames) - return WideString(); - - if ((!!pSymbolNames->GetAttrInteger("abbr")) != bAbbr) - pSymbolNames = pChild->GetElement("", pstrSymbolNames.AsStringView(), 1); - - if (!pSymbolNames || (!!pSymbolNames->GetAttrInteger("abbr")) != bAbbr) - return WideString(); - - CXML_Element* pSymbolName = pSymbolNames->GetElement("", symbol, index); - if (!pSymbolName) - return WideString(); + CFX_XMLElement* child = locale_->GetFirstChildNamed(L"calendarSymbols"); + if (!child) + return L""; + + WideString pstrSymbolNames = symbol + L"Names"; + CFX_XMLElement* name_child = nullptr; + for (auto* name = child->GetFirstChild(); name; + name = name->GetNextSibling()) { + if (name->GetType() != FX_XMLNODE_Element) + continue; + + auto* elem = static_cast<CFX_XMLElement*>(name); + if (elem->GetName() != pstrSymbolNames) + continue; + + WideString abbr = elem->GetString(L"abbr"); + bool abbr_value = false; + if (!abbr.IsEmpty()) + abbr_value = abbr == L"1"; + if (abbr_value != bAbbr) + continue; + + name_child = elem; + break; + } + if (!name_child) + return L""; - CXML_Content* pContent = ToContent(pSymbolName->GetChild(0)); - return pContent ? pContent->m_Content : WideString(); + CFX_XMLElement* sym_element = name_child->GetNthChildNamed(symbol, index); + return sym_element ? sym_element->GetTextData() : L""; } WideString CXFA_XMLLocale::GetDatePattern( FX_LOCALEDATETIMESUBCATEGORY eType) const { - CXML_Element* pElement = m_pLocaleData->GetElement("", "datePatterns", 0); - if (!pElement) - return WideString(); + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(L"datePatterns"); + if (!patterns) + return L""; WideString wsName; switch (eType) { @@ -167,14 +191,14 @@ WideString CXFA_XMLLocale::GetDatePattern( wsName = L"long"; break; } - return GetPattern(pElement, "datePattern", wsName.AsStringView()); + return GetPattern(patterns, L"datePattern", wsName.AsStringView()); } WideString CXFA_XMLLocale::GetTimePattern( FX_LOCALEDATETIMESUBCATEGORY eType) const { - CXML_Element* pElement = m_pLocaleData->GetElement("", "timePatterns", 0); - if (!pElement) - return WideString(); + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(L"timePatterns"); + if (!patterns) + return L""; WideString wsName; switch (eType) { @@ -192,25 +216,29 @@ WideString CXFA_XMLLocale::GetTimePattern( wsName = L"long"; break; } - return GetPattern(pElement, "timePattern", wsName.AsStringView()); + return GetPattern(patterns, L"timePattern", wsName.AsStringView()); } WideString CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType) const { - return m_pLocaleData->GetElement("", "numberPatterns", 0) - ? XFA_PatternToString(eType) - : WideString(); + CFX_XMLElement* patterns = locale_->GetFirstChildNamed(L"numberPatterns"); + return patterns ? XFA_PatternToString(eType) : L""; } -WideString CXFA_XMLLocale::GetPattern(CXML_Element* pElement, - const ByteStringView& bsTag, +WideString CXFA_XMLLocale::GetPattern(CFX_XMLElement* patterns, + const WideStringView& bsTag, const WideStringView& wsName) const { - size_t iCount = pElement->CountElements("", bsTag); - for (size_t i = 0; i < iCount; i++) { - CXML_Element* pChild = pElement->GetElement("", bsTag, i); - if (pChild->GetAttrValue("name") == wsName) { - CXML_Content* pContent = ToContent(pChild->GetChild(0)); - return pContent ? pContent->m_Content : WideString(); - } + for (auto* child = patterns->GetFirstChild(); child; + child = child->GetNextSibling()) { + if (child->GetType() != FX_XMLNODE_Element) + continue; + + CFX_XMLElement* pattern = static_cast<CFX_XMLElement*>(child); + if (pattern->GetName() != bsTag) + continue; + if (pattern->GetString(L"name") != wsName) + continue; + + return pattern->GetTextData(); } - return WideString(); + return L""; } diff --git a/xfa/fxfa/parser/cxfa_xmllocale.h b/xfa/fxfa/parser/cxfa_xmllocale.h index d1d21e83f1..92bd3607ec 100644 --- a/xfa/fxfa/parser/cxfa_xmllocale.h +++ b/xfa/fxfa/parser/cxfa_xmllocale.h @@ -13,13 +13,14 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/span.h" -class CXML_Element; +class CFX_XMLElement; class CXFA_XMLLocale : public LocaleIface { public: static std::unique_ptr<CXFA_XMLLocale> Create(pdfium::span<uint8_t> data); - explicit CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData); + explicit CXFA_XMLLocale(std::unique_ptr<CFX_XMLElement> root, + CFX_XMLElement* locale); ~CXFA_XMLLocale() override; // LocaleIface @@ -38,14 +39,15 @@ class CXFA_XMLLocale : public LocaleIface { WideString GetNumPattern(FX_LOCALENUMSUBCATEGORY eType) const override; private: - WideString GetPattern(CXML_Element* pElement, - const ByteStringView& bsTag, + WideString GetPattern(CFX_XMLElement* pElement, + const WideStringView& bsTag, const WideStringView& wsName) const; - WideString GetCalendarSymbol(const ByteStringView& symbol, - int index, + WideString GetCalendarSymbol(const WideStringView& symbol, + size_t index, bool bAbbr) const; - std::unique_ptr<CXML_Element> m_pLocaleData; + std::unique_ptr<CFX_XMLElement> xml_root_; + UnownedPtr<CFX_XMLElement> locale_; }; #endif // XFA_FXFA_PARSER_CXFA_XMLLOCALE_H_ diff --git a/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp index a9bda60085..e2c5198eb8 100644 --- a/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp +++ b/xfa/fxfa/parser/cxfa_xmllocale_unittest.cpp @@ -7,109 +7,89 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" -namespace { - -const char* xml_data = +static const char* xml_data = "<locale name=\"en_US\" desc=\"English(America)\">" - " <calendarSymbols name=\"gregorian\">" - " <monthNames>" - " <month>January</month>" - " <month>February</month>" - " <month>March</month>" - " <month>April</month>" - " <month>May</month>" - " <month>June</month>" - " <month>July</month>" - " <month>August</month>" - " <month>September</month>" - " <month>October</month>" - " <month>November</month>" - " <month>December</month>" - " </monthNames>" - " <monthNames abbr=\"1\">" - " <month>Jan</month>" - " <month>Feb</month>" - " <month>Mar</month>" - " <month>Apr</month>" - " <month>May</month>" - " <month>Jun</month>" - " <month>Jul</month>" - " <month>Aug</month>" - " <month>Sep</month>" - " <month>Oct</month>" - " <month>Nov</month>" - " <month>Dec</month>" - " </monthNames>" - " <dayNames>" - " <day>Sunday</day>" - " <day>Monday</day>" - " <day>Tuesday</day>" - " <day>Wednesday</day>" - " <day>Thursday</day>" - " <day>Friday</day>" - " <day>Saturday</day>" - " </dayNames>" - " <dayNames abbr=\"1\">" - " <day>Sun</day>" - " <day>Mon</day>" - " <day>Tue</day>" - " <day>Wed</day>" - " <day>Thu</day>" - " <day>Fri</day>" - " <day>Sat</day>" - " </dayNames>" - " <meridiemNames>" - " <meridiem>AM</meridiem>" - " <meridiem>PM</meridiem>" - " </meridiemNames>" - " <eraNames>" - " <era>BC</era>" - " <era>AD</era>" - " </eraNames>" - " </calendarSymbols>" - " <datePatterns>" - " <datePattern name=\"full\">EEEE, MMMM D, YYYY</datePattern>" - " <datePattern name=\"long\">MMMM D, YYYY</datePattern>" - " <datePattern name=\"med\">MMM D, YYYY</datePattern>" - " <datePattern name=\"short\">M/D/YY</datePattern>" - " </datePatterns>" - " <timePatterns>" - " <timePattern name=\"full\">h:MM:SS A Z</timePattern>" - " <timePattern name=\"long\">h:MM:SS A Z</timePattern>" - " <timePattern name=\"med\">h:MM:SS A</timePattern>" - " <timePattern name=\"short\">h:MM A</timePattern>" - " </timePatterns>" - " <dateTimeSymbols>GyMdkHmsSEDFwWahKzZ</dateTimeSymbols>" - " <numberPatterns>" - " <numberPattern name=\"numeric\">z,zz9.zzz</numberPattern>" - " <numberPattern name=\"currency\">$z,zz9.99|($z,zz9.99)</numberPattern>" - " <numberPattern name=\"percent\">z,zz9%</numberPattern>" - " </numberPatterns>" - " <numberSymbols>" - " <numberSymbol name=\"decimal\">.</numberSymbol>" - " <numberSymbol name=\"grouping\">,</numberSymbol>" - " <numberSymbol name=\"percent\">%</numberSymbol>" - " <numberSymbol name=\"minus\">-</numberSymbol>" - " <numberSymbol name=\"zero\">0</numberSymbol>" - " </numberSymbols>" - " <currencySymbols>" - " <currencySymbol name=\"symbol\">$</currencySymbol>" - " <currencySymbol name=\"isoname\">USD</currencySymbol>" - " <currencySymbol name=\"decimal\">.</currencySymbol>" - " </currencySymbols>" + "<calendarSymbols name=\"gregorian\"><monthNames><month>January</month>" + "<month>February</month>" + "<month>March</month>" + "<month>April</month>" + "<month>May</month>" + "<month>June</month>" + "<month>July</month>" + "<month>August</month>" + "<month>September</month>" + "<month>October</month>" + "<month>November</month>" + "<month>December</month>" + "</monthNames>" + "<monthNames abbr=\"1\"><month>Jan</month>" + "<month>Feb</month>" + "<month>Mar</month>" + "<month>Apr</month>" + "<month>May</month>" + "<month>Jun</month>" + "<month>Jul</month>" + "<month>Aug</month>" + "<month>Sep</month>" + "<month>Oct</month>" + "<month>Nov</month>" + "<month>Dec</month>" + "</monthNames>" + "<dayNames><day>Sunday</day>" + "<day>Monday</day>" + "<day>Tuesday</day>" + "<day>Wednesday</day>" + "<day>Thursday</day>" + "<day>Friday</day>" + "<day>Saturday</day>" + "</dayNames>" + "<dayNames abbr=\"1\"><day>Sun</day>" + "<day>Mon</day>" + "<day>Tue</day>" + "<day>Wed</day>" + "<day>Thu</day>" + "<day>Fri</day>" + "<day>Sat</day>" + "</dayNames>" + "<meridiemNames><meridiem>AM</meridiem>" + "<meridiem>PM</meridiem>" + "</meridiemNames>" + "<eraNames><era>BC</era>" + "<era>AD</era>" + "</eraNames>" + "</calendarSymbols>" + "<datePatterns><datePattern name=\"full\">EEEE, MMMM D, YYYY</datePattern>" + "<datePattern name=\"long\">MMMM D, YYYY</datePattern>" + "<datePattern name=\"med\">MMM D, YYYY</datePattern>" + "<datePattern name=\"short\">M/D/YY</datePattern>" + "</datePatterns>" + "<timePatterns><timePattern name=\"full\">h:MM:SS A Z</timePattern>" + "<timePattern name=\"long\">h:MM:SS A Z</timePattern>" + "<timePattern name=\"med\">h:MM:SS A</timePattern>" + "<timePattern name=\"short\">h:MM A</timePattern>" + "</timePatterns>" + "<dateTimeSymbols>GyMdkHmsSEDFwWahKzZ</dateTimeSymbols>" + "<numberPatterns><numberPattern name=\"numeric\">z,zz9.zzz</numberPattern>" + "<numberPattern name=\"currency\">$z,zz9.99|($z,zz9.99)</numberPattern>" + "<numberPattern name=\"percent\">z,zz9%</numberPattern>" + "</numberPatterns>" + "<numberSymbols><numberSymbol name=\"decimal\">.</numberSymbol>" + "<numberSymbol name=\"grouping\">,</numberSymbol>" + "<numberSymbol name=\"percent\">%</numberSymbol>" + "<numberSymbol name=\"minus\">-</numberSymbol>" + "<numberSymbol name=\"zero\">0</numberSymbol>" + "</numberSymbols>" + "<currencySymbols><currencySymbol name=\"symbol\">$</currencySymbol>" + "<currencySymbol name=\"isoname\">USD</currencySymbol>" + "<currencySymbol name=\"decimal\">.</currencySymbol>" + "</currencySymbols>" "</locale>"; -std::unique_ptr<CXFA_XMLLocale> LoadLocale() { +TEST(CXFA_XMLLocaleTest, Create) { auto span = pdfium::make_span(reinterpret_cast<uint8_t*>(const_cast<char*>(xml_data)), strlen(xml_data)); - return CXFA_XMLLocale::Create(span); -} - -} // namespace - -TEST(CXFA_XMLLocaleTest, Create) { - auto locale = LoadLocale(); + auto locale = CXFA_XMLLocale::Create(span); EXPECT_TRUE(locale != nullptr); } @@ -119,14 +99,20 @@ TEST(CXFA_XMLLocaleTest, CreateBadXML) { } TEST(CXFA_XMLLocaleTest, GetName) { - auto locale = LoadLocale(); + 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"en_US", locale->GetName()); } TEST(CXFA_XMLLocaleTest, GetNumbericSymbol) { - auto locale = LoadLocale(); + 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)); @@ -139,14 +125,20 @@ TEST(CXFA_XMLLocaleTest, GetNumbericSymbol) { } TEST(CXFA_XMLLocaleTest, GetDateTimeSymbols) { - auto locale = LoadLocale(); + 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"GyMdkHmsSEDFwWahKzZ", locale->GetDateTimeSymbols()); } TEST(CXFA_XMLLocaleTest, GetMonthName) { - auto locale = LoadLocale(); + 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->GetMonthName(24, false)); @@ -156,7 +148,10 @@ TEST(CXFA_XMLLocaleTest, GetMonthName) { } TEST(CXFA_XMLLocaleTest, GetDayName) { - auto locale = LoadLocale(); + 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->GetDayName(24, false)); @@ -166,7 +161,10 @@ TEST(CXFA_XMLLocaleTest, GetDayName) { } TEST(CXFA_XMLLocaleTest, GetMeridiemName) { - auto locale = LoadLocale(); + 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"AM", locale->GetMeridiemName(true)); @@ -174,7 +172,10 @@ TEST(CXFA_XMLLocaleTest, GetMeridiemName) { } TEST(CXFA_XMLLocaleTest, GetEraName) { - auto locale = LoadLocale(); + 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"AD", locale->GetEraName(true)); @@ -182,7 +183,10 @@ TEST(CXFA_XMLLocaleTest, GetEraName) { } TEST(CXFA_XMLLocaleTest, GetDatePattern) { - auto locale = LoadLocale(); + 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"M/D/YY", @@ -198,7 +202,10 @@ TEST(CXFA_XMLLocaleTest, GetDatePattern) { } TEST(CXFA_XMLLocaleTest, GetTimePattern) { - auto locale = LoadLocale(); + 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"h:MM A", @@ -214,7 +221,10 @@ TEST(CXFA_XMLLocaleTest, GetTimePattern) { } TEST(CXFA_XMLLocaleTest, GetNumPattern) { - auto locale = LoadLocale(); + 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"z,zzz,zzz,zzz,zzz,zzz%", |