7#include "xfa/fxfa/parser/cxfa_xmllocale.h"
11#include "core/fxcrt/cfx_read_only_span_stream.h"
12#include "core/fxcrt/fx_codepage.h"
13#include "core/fxcrt/xml/cfx_xmldocument.h"
14#include "core/fxcrt/xml/cfx_xmlelement.h"
15#include "core/fxcrt/xml/cfx_xmlparser.h"
16#include "third_party/base/check.h"
17#include "xfa/fxfa/parser/cxfa_document.h"
18#include "xfa/fxfa/parser/cxfa_localemgr.h"
19#include "xfa/fxfa/parser/cxfa_nodelocale.h"
20#include "xfa/fxfa/parser/cxfa_timezoneprovider.h"
21#include "xfa/fxfa/parser/xfa_utils.h"
25constexpr wchar_t kNumberSymbols[] = L"numberSymbols";
26constexpr wchar_t kNumberSymbol[] = L"numberSymbol";
27constexpr wchar_t kCurrencySymbols[] = L"currencySymbols";
28constexpr wchar_t kCurrencySymbol[] = L"currencySymbol";
34 pdfium::span<uint8_t> data) {
35 auto stream = pdfium::MakeRetain<CFX_ReadOnlySpanStream>(data);
36 CFX_XMLParser parser(stream);
37 auto doc = parser.Parse();
41 for (
auto* child = doc->GetRoot()->GetFirstChild(); child;
42 child = child->GetNextSibling()) {
43 CFX_XMLElement* elem = ToXMLElement(child);
45 return cppgc::MakeGarbageCollected<CXFA_XMLLocale>(
46 heap->GetAllocationHandle(), std::move(doc), elem);
52CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CFX_XMLDocument> doc,
53 const CFX_XMLElement* locale)
54 : xml_doc_(std::move(doc)), locale_(locale) {
61void CXFA_XMLLocale::
Trace(
cppgc::Visitor* visitor)
const {
62 GCedLocaleIface::Trace(visitor);
65WideString CXFA_XMLLocale::
GetName()
const {
66 return locale_->GetAttribute(L"name");
70 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols);
71 return patterns ? GetPattern(patterns, kNumberSymbol, L"decimal")
76 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols);
77 return patterns ? GetPattern(patterns, kNumberSymbol, L"grouping")
82 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols);
83 return patterns ? GetPattern(patterns, kNumberSymbol, L"percent")
88 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kNumberSymbols);
89 return patterns ? GetPattern(patterns, kNumberSymbol, L"minus")
94 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(kCurrencySymbols);
95 return patterns ? GetPattern(patterns, kCurrencySymbol, L"symbol")
100 CFX_XMLElement* symbols = locale_->GetFirstChildNamed(L"dateTimeSymbols");
104WideString CXFA_XMLLocale::
GetMonthName(int32_t nMonth,
bool bAbbr)
const {
105 return GetCalendarSymbol(L"month", nMonth, bAbbr);
108WideString CXFA_XMLLocale::
GetDayName(int32_t nWeek,
bool bAbbr)
const {
109 return GetCalendarSymbol(L"day", nWeek, bAbbr);
113 return GetCalendarSymbol(L"meridiem", bAM ? 0 : 1,
false);
121 return GetCalendarSymbol(L"era", bAD ? 1 : 0,
false);
124WideString CXFA_XMLLocale::GetCalendarSymbol(WideStringView symbol,
127 CFX_XMLElement* child = locale_->GetFirstChildNamed(L"calendarSymbols");
131 WideString pstrSymbolNames = symbol + L"Names";
132 CFX_XMLElement* name_child =
nullptr;
133 for (
auto* name = child->GetFirstChild(); name;
134 name = name->GetNextSibling()) {
135 CFX_XMLElement* elem = ToXMLElement(name);
140 bool abbr_value =
false;
143 if (abbr_value != bAbbr)
152 CFX_XMLElement* sym_element = name_child->GetNthChildNamed(symbol, index);
157 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(L"datePatterns");
177 return GetPattern(patterns, L"datePattern", wsName.AsStringView());
181 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(L"timePatterns");
201 return GetPattern(patterns, L"timePattern", wsName.AsStringView());
205 CFX_XMLElement* patterns = locale_->GetFirstChildNamed(L"numberPatterns");
209WideString CXFA_XMLLocale::GetPattern(CFX_XMLElement* patterns,
210 WideStringView bsTag,
211 WideStringView wsName)
const {
212 for (
auto* child = patterns->GetFirstChild(); child;
213 child = child->GetNextSibling()) {
214 CFX_XMLElement* pattern = ToXMLElement(child);
WideString GetTextData() const
const WideString & GetName() const
WideString GetAttribute(const WideString &name) const
int GetTimeZoneInMinutes() const
WideString GetPercentSymbol() const override
WideString GetMinusSymbol() const override
void Trace(cppgc::Visitor *visitor) const override
WideString GetGroupingSymbol() const override
static CXFA_XMLLocale * Create(cppgc::Heap *heap, pdfium::span< uint8_t > data)
WideString GetTimePattern(DateTimeSubcategory eType) const override
WideString GetName() const override
WideString GetDayName(int32_t nWeek, bool bAbbr) const override
WideString GetMonthName(int32_t nMonth, bool bAbbr) const override
WideString GetDatePattern(DateTimeSubcategory eType) const override
WideString GetNumPattern(NumSubcategory eType) const override
WideString GetDateTimeSymbols() const override
~CXFA_XMLLocale() override
int GetTimeZoneInMinutes() const override
WideString GetEraName(bool bAD) const override
WideString GetCurrencySymbol() const override
WideString GetMeridiemName(bool bAM) const override
WideString GetDecimalSymbol() const override
bool operator!=(const WideString &other) const
WideString & operator=(const wchar_t *str)
bool EqualsASCII(ByteStringView that) const
WideString XFA_PatternToString(LocaleIface::NumSubcategory category)