| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_locale.h" | 7 #include "xfa/fxfa/parser/xfa_locale.h" |
| 8 | 8 |
| 9 #include <utility> |
| 10 |
| 9 #include "core/fxcrt/include/fx_xml.h" | 11 #include "core/fxcrt/include/fx_xml.h" |
| 10 #include "xfa/fxfa/parser/cxfa_document.h" | 12 #include "xfa/fxfa/parser/cxfa_document.h" |
| 11 #include "xfa/fxfa/parser/xfa_localemgr.h" | 13 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 12 #include "xfa/fxfa/parser/xfa_object.h" | 14 #include "xfa/fxfa/parser/xfa_object.h" |
| 13 #include "xfa/fxfa/parser/xfa_utils.h" | 15 #include "xfa/fxfa/parser/xfa_utils.h" |
| 14 | 16 |
| 15 static const FX_WCHAR g_FX_Percent[] = L"z,zzz,zzz,zzz,zzz,zzz%"; | 17 static const FX_WCHAR g_FX_Percent[] = L"z,zzz,zzz,zzz,zzz,zzz%"; |
| 16 static const FX_WCHAR g_FX_Currency[] = L"$z,zzz,zzz,zzz,zzz,zz9.99"; | 18 static const FX_WCHAR g_FX_Currency[] = L"$z,zzz,zzz,zzz,zzz,zz9.99"; |
| 17 static const FX_WCHAR g_FX_Decimal[] = L"z,zzz,zzz,zzz,zzz,zz9.zzz"; | 19 static const FX_WCHAR g_FX_Decimal[] = L"z,zzz,zzz,zzz,zzz,zz9.zzz"; |
| 18 static const FX_WCHAR g_FX_Integer[] = L"z,zzz,zzz,zzz,zzz,zzz"; | 20 static const FX_WCHAR g_FX_Integer[] = L"z,zzz,zzz,zzz,zzz,zzz"; |
| 19 | 21 |
| 20 CXFA_XMLLocale::CXFA_XMLLocale(CXML_Element* pLocaleData) | 22 CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData) |
| 21 : m_pLocaleData(pLocaleData) {} | 23 : m_pLocaleData(std::move(pLocaleData)) {} |
| 22 | 24 |
| 23 CXFA_XMLLocale::~CXFA_XMLLocale() { | 25 CXFA_XMLLocale::~CXFA_XMLLocale() {} |
| 24 delete m_pLocaleData; | |
| 25 } | |
| 26 | 26 |
| 27 void CXFA_XMLLocale::Release() { | 27 void CXFA_XMLLocale::Release() { |
| 28 delete this; | 28 delete this; |
| 29 } | 29 } |
| 30 |
| 30 CFX_WideString CXFA_XMLLocale::GetName() { | 31 CFX_WideString CXFA_XMLLocale::GetName() { |
| 31 return m_pLocaleData ? m_pLocaleData->GetAttrValue("name") : CFX_WideString(); | 32 return m_pLocaleData ? m_pLocaleData->GetAttrValue("name") : CFX_WideString(); |
| 32 } | 33 } |
| 34 |
| 33 void CXFA_XMLLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, | 35 void CXFA_XMLLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, |
| 34 CFX_WideString& wsNumSymbol) const { | 36 CFX_WideString& wsNumSymbol) const { |
| 35 CFX_ByteString bsSymbols; | 37 CFX_ByteString bsSymbols; |
| 36 CFX_WideString wsName; | 38 CFX_WideString wsName; |
| 37 switch (eType) { | 39 switch (eType) { |
| 38 case FX_LOCALENUMSYMBOL_Decimal: | 40 case FX_LOCALENUMSYMBOL_Decimal: |
| 39 bsSymbols = "numberSymbols"; | 41 bsSymbols = "numberSymbols"; |
| 40 wsName = FX_WSTRC(L"decimal"); | 42 wsName = FX_WSTRC(L"decimal"); |
| 41 break; | 43 break; |
| 42 case FX_LOCALENUMSYMBOL_Grouping: | 44 case FX_LOCALENUMSYMBOL_Grouping: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 67 return; | 69 return; |
| 68 } | 70 } |
| 69 CXML_Element* pElement = m_pLocaleData->GetElement("", bsSymbols.AsStringC()); | 71 CXML_Element* pElement = m_pLocaleData->GetElement("", bsSymbols.AsStringC()); |
| 70 if (!pElement) { | 72 if (!pElement) { |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 GetPattern(pElement, | 75 GetPattern(pElement, |
| 74 CFX_ByteStringC(bsSymbols.c_str(), bsSymbols.GetLength() - 1), | 76 CFX_ByteStringC(bsSymbols.c_str(), bsSymbols.GetLength() - 1), |
| 75 wsName.AsStringC(), wsNumSymbol); | 77 wsName.AsStringC(), wsNumSymbol); |
| 76 } | 78 } |
| 79 |
| 77 void CXFA_XMLLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { | 80 void CXFA_XMLLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { |
| 78 if (!m_pLocaleData) { | 81 if (!m_pLocaleData) { |
| 79 return; | 82 return; |
| 80 } | 83 } |
| 81 CFX_ByteString bsSpace; | 84 CFX_ByteString bsSpace; |
| 82 CXML_Element* pNumberSymbols = | 85 CXML_Element* pNumberSymbols = |
| 83 m_pLocaleData->GetElement(bsSpace.AsStringC(), "dateTimeSymbols"); | 86 m_pLocaleData->GetElement(bsSpace.AsStringC(), "dateTimeSymbols"); |
| 84 if (!pNumberSymbols) { | 87 if (!pNumberSymbols) { |
| 85 return; | 88 return; |
| 86 } | 89 } |
| 87 wsDtSymbol = pNumberSymbols->GetContent(0); | 90 wsDtSymbol = pNumberSymbols->GetContent(0); |
| 88 } | 91 } |
| 92 |
| 89 void CXFA_XMLLocale::GetMonthName(int32_t nMonth, | 93 void CXFA_XMLLocale::GetMonthName(int32_t nMonth, |
| 90 CFX_WideString& wsMonthName, | 94 CFX_WideString& wsMonthName, |
| 91 FX_BOOL bAbbr) const { | 95 FX_BOOL bAbbr) const { |
| 92 wsMonthName = GetCalendarSymbol("month", nMonth, bAbbr); | 96 wsMonthName = GetCalendarSymbol("month", nMonth, bAbbr); |
| 93 } | 97 } |
| 98 |
| 94 void CXFA_XMLLocale::GetDayName(int32_t nWeek, | 99 void CXFA_XMLLocale::GetDayName(int32_t nWeek, |
| 95 CFX_WideString& wsDayName, | 100 CFX_WideString& wsDayName, |
| 96 FX_BOOL bAbbr) const { | 101 FX_BOOL bAbbr) const { |
| 97 wsDayName = GetCalendarSymbol("day", nWeek, bAbbr); | 102 wsDayName = GetCalendarSymbol("day", nWeek, bAbbr); |
| 98 } | 103 } |
| 104 |
| 99 void CXFA_XMLLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, | 105 void CXFA_XMLLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, |
| 100 FX_BOOL bAM) const { | 106 FX_BOOL bAM) const { |
| 101 wsMeridiemName = GetCalendarSymbol("meridiem", bAM ? 0 : 1, FALSE); | 107 wsMeridiemName = GetCalendarSymbol("meridiem", bAM ? 0 : 1, FALSE); |
| 102 } | 108 } |
| 109 |
| 103 void CXFA_XMLLocale::GetTimeZone(FX_TIMEZONE& tz) const { | 110 void CXFA_XMLLocale::GetTimeZone(FX_TIMEZONE& tz) const { |
| 104 CXFA_TimeZoneProvider::Get()->GetTimeZone(tz); | 111 CXFA_TimeZoneProvider::Get()->GetTimeZone(tz); |
| 105 } | 112 } |
| 113 |
| 106 void CXFA_XMLLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { | 114 void CXFA_XMLLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { |
| 107 wsEraName = GetCalendarSymbol("era", bAD ? 1 : 0, FALSE); | 115 wsEraName = GetCalendarSymbol("era", bAD ? 1 : 0, FALSE); |
| 108 } | 116 } |
| 117 |
| 109 CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, | 118 CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, |
| 110 int index, | 119 int index, |
| 111 FX_BOOL bAbbr) const { | 120 FX_BOOL bAbbr) const { |
| 112 CFX_ByteString pstrSymbolNames = symbol + "Names"; | 121 CFX_ByteString pstrSymbolNames = symbol + "Names"; |
| 113 CFX_WideString wsSymbolName = L""; | 122 CFX_WideString wsSymbolName = L""; |
| 114 if (m_pLocaleData) { | 123 if (m_pLocaleData) { |
| 115 CXML_Element* pChild = m_pLocaleData->GetElement("", "calendarSymbols"); | 124 CXML_Element* pChild = m_pLocaleData->GetElement("", "calendarSymbols"); |
| 116 if (pChild) { | 125 if (pChild) { |
| 117 CXML_Element* pSymbolNames = | 126 CXML_Element* pSymbolNames = |
| 118 pChild->GetElement("", pstrSymbolNames.AsStringC()); | 127 pChild->GetElement("", pstrSymbolNames.AsStringC()); |
| 119 if (pSymbolNames) { | 128 if (pSymbolNames) { |
| 120 if (pSymbolNames->GetAttrInteger("abbr") != bAbbr) { | 129 if (pSymbolNames->GetAttrInteger("abbr") != bAbbr) { |
| 121 pSymbolNames = pChild->GetElement("", pstrSymbolNames.AsStringC(), 1); | 130 pSymbolNames = pChild->GetElement("", pstrSymbolNames.AsStringC(), 1); |
| 122 } | 131 } |
| 123 if (pSymbolNames && pSymbolNames->GetAttrInteger("abbr") == bAbbr) { | 132 if (pSymbolNames && pSymbolNames->GetAttrInteger("abbr") == bAbbr) { |
| 124 CXML_Element* pSymbolName = | 133 CXML_Element* pSymbolName = |
| 125 pSymbolNames->GetElement("", symbol, index); | 134 pSymbolNames->GetElement("", symbol, index); |
| 126 if (pSymbolName) { | 135 if (pSymbolName) { |
| 127 wsSymbolName = pSymbolName->GetContent(0); | 136 wsSymbolName = pSymbolName->GetContent(0); |
| 128 } | 137 } |
| 129 } | 138 } |
| 130 } | 139 } |
| 131 } | 140 } |
| 132 } | 141 } |
| 133 return wsSymbolName; | 142 return wsSymbolName; |
| 134 } | 143 } |
| 144 |
| 135 void CXFA_XMLLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | 145 void CXFA_XMLLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, |
| 136 CFX_WideString& wsPattern) const { | 146 CFX_WideString& wsPattern) const { |
| 137 CXML_Element* pElement = m_pLocaleData->GetElement("", "datePatterns"); | 147 CXML_Element* pElement = m_pLocaleData->GetElement("", "datePatterns"); |
| 138 if (!pElement) { | 148 if (!pElement) { |
| 139 return; | 149 return; |
| 140 } | 150 } |
| 141 CFX_WideString wsName; | 151 CFX_WideString wsName; |
| 142 switch (eType) { | 152 switch (eType) { |
| 143 case FX_LOCALEDATETIMESUBCATEGORY_Short: | 153 case FX_LOCALEDATETIMESUBCATEGORY_Short: |
| 144 wsName = L"short"; | 154 wsName = L"short"; |
| 145 break; | 155 break; |
| 146 case FX_LOCALEDATETIMESUBCATEGORY_Default: | 156 case FX_LOCALEDATETIMESUBCATEGORY_Default: |
| 147 case FX_LOCALEDATETIMESUBCATEGORY_Medium: | 157 case FX_LOCALEDATETIMESUBCATEGORY_Medium: |
| 148 wsName = L"med"; | 158 wsName = L"med"; |
| 149 break; | 159 break; |
| 150 case FX_LOCALEDATETIMESUBCATEGORY_Full: | 160 case FX_LOCALEDATETIMESUBCATEGORY_Full: |
| 151 wsName = L"full"; | 161 wsName = L"full"; |
| 152 break; | 162 break; |
| 153 case FX_LOCALEDATETIMESUBCATEGORY_Long: | 163 case FX_LOCALEDATETIMESUBCATEGORY_Long: |
| 154 wsName = L"long"; | 164 wsName = L"long"; |
| 155 break; | 165 break; |
| 156 } | 166 } |
| 157 GetPattern(pElement, "datePattern", wsName.AsStringC(), wsPattern); | 167 GetPattern(pElement, "datePattern", wsName.AsStringC(), wsPattern); |
| 158 } | 168 } |
| 169 |
| 159 void CXFA_XMLLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | 170 void CXFA_XMLLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, |
| 160 CFX_WideString& wsPattern) const { | 171 CFX_WideString& wsPattern) const { |
| 161 CXML_Element* pElement = m_pLocaleData->GetElement("", "timePatterns"); | 172 CXML_Element* pElement = m_pLocaleData->GetElement("", "timePatterns"); |
| 162 if (!pElement) { | 173 if (!pElement) { |
| 163 return; | 174 return; |
| 164 } | 175 } |
| 165 CFX_WideString wsName; | 176 CFX_WideString wsName; |
| 166 switch (eType) { | 177 switch (eType) { |
| 167 case FX_LOCALEDATETIMESUBCATEGORY_Short: | 178 case FX_LOCALEDATETIMESUBCATEGORY_Short: |
| 168 wsName = L"short"; | 179 wsName = L"short"; |
| 169 break; | 180 break; |
| 170 case FX_LOCALEDATETIMESUBCATEGORY_Default: | 181 case FX_LOCALEDATETIMESUBCATEGORY_Default: |
| 171 case FX_LOCALEDATETIMESUBCATEGORY_Medium: | 182 case FX_LOCALEDATETIMESUBCATEGORY_Medium: |
| 172 wsName = L"med"; | 183 wsName = L"med"; |
| 173 break; | 184 break; |
| 174 case FX_LOCALEDATETIMESUBCATEGORY_Full: | 185 case FX_LOCALEDATETIMESUBCATEGORY_Full: |
| 175 wsName = L"full"; | 186 wsName = L"full"; |
| 176 break; | 187 break; |
| 177 case FX_LOCALEDATETIMESUBCATEGORY_Long: | 188 case FX_LOCALEDATETIMESUBCATEGORY_Long: |
| 178 wsName = L"long"; | 189 wsName = L"long"; |
| 179 break; | 190 break; |
| 180 } | 191 } |
| 181 GetPattern(pElement, "timePattern", wsName.AsStringC(), wsPattern); | 192 GetPattern(pElement, "timePattern", wsName.AsStringC(), wsPattern); |
| 182 } | 193 } |
| 194 |
| 183 void CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, | 195 void CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, |
| 184 CFX_WideString& wsPattern) const { | 196 CFX_WideString& wsPattern) const { |
| 185 CXML_Element* pElement = m_pLocaleData->GetElement("", "numberPatterns"); | 197 CXML_Element* pElement = m_pLocaleData->GetElement("", "numberPatterns"); |
| 186 if (!pElement) { | 198 if (!pElement) { |
| 187 return; | 199 return; |
| 188 } | 200 } |
| 189 switch (eType) { | 201 switch (eType) { |
| 190 case FX_LOCALENUMPATTERN_Percent: | 202 case FX_LOCALENUMPATTERN_Percent: |
| 191 wsPattern = g_FX_Percent; | 203 wsPattern = g_FX_Percent; |
| 192 break; | 204 break; |
| 193 case FX_LOCALENUMPATTERN_Currency: | 205 case FX_LOCALENUMPATTERN_Currency: |
| 194 wsPattern = g_FX_Currency; | 206 wsPattern = g_FX_Currency; |
| 195 break; | 207 break; |
| 196 case FX_LOCALENUMPATTERN_Decimal: | 208 case FX_LOCALENUMPATTERN_Decimal: |
| 197 wsPattern = g_FX_Decimal; | 209 wsPattern = g_FX_Decimal; |
| 198 break; | 210 break; |
| 199 case FX_LOCALENUMPATTERN_Integer: | 211 case FX_LOCALENUMPATTERN_Integer: |
| 200 wsPattern = g_FX_Integer; | 212 wsPattern = g_FX_Integer; |
| 201 break; | 213 break; |
| 202 } | 214 } |
| 203 } | 215 } |
| 216 |
| 204 void CXFA_XMLLocale::GetPattern(CXML_Element* pElement, | 217 void CXFA_XMLLocale::GetPattern(CXML_Element* pElement, |
| 205 const CFX_ByteStringC& bsTag, | 218 const CFX_ByteStringC& bsTag, |
| 206 const CFX_WideStringC& wsName, | 219 const CFX_WideStringC& wsName, |
| 207 CFX_WideString& wsPattern) const { | 220 CFX_WideString& wsPattern) const { |
| 208 int32_t iCount = pElement->CountElements("", bsTag); | 221 int32_t iCount = pElement->CountElements("", bsTag); |
| 209 for (int32_t i = 0; i < iCount; i++) { | 222 for (int32_t i = 0; i < iCount; i++) { |
| 210 CXML_Element* pChild = pElement->GetElement("", bsTag, i); | 223 CXML_Element* pChild = pElement->GetElement("", bsTag, i); |
| 211 if (pChild->GetAttrValue("name") == wsName) { | 224 if (pChild->GetAttrValue("name") == wsName) { |
| 212 wsPattern = pChild->GetContent(0); | 225 wsPattern = pChild->GetContent(0); |
| 213 return; | 226 return; |
| 214 } | 227 } |
| 215 } | 228 } |
| 216 } | 229 } |
| 217 CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) { | 230 |
| 218 m_pLocale = pLocale; | 231 CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) : m_pLocale(pLocale) {} |
| 219 } | 232 |
| 220 CXFA_NodeLocale::~CXFA_NodeLocale() {} | 233 CXFA_NodeLocale::~CXFA_NodeLocale() {} |
| 234 |
| 221 void CXFA_NodeLocale::Release() { | 235 void CXFA_NodeLocale::Release() { |
| 222 delete this; | 236 delete this; |
| 223 } | 237 } |
| 238 |
| 224 CFX_WideString CXFA_NodeLocale::GetName() { | 239 CFX_WideString CXFA_NodeLocale::GetName() { |
| 225 return CFX_WideString(m_pLocale ? m_pLocale->GetCData(XFA_ATTRIBUTE_Name) | 240 return CFX_WideString(m_pLocale ? m_pLocale->GetCData(XFA_ATTRIBUTE_Name) |
| 226 : nullptr); | 241 : nullptr); |
| 227 } | 242 } |
| 243 |
| 228 void CXFA_NodeLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, | 244 void CXFA_NodeLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, |
| 229 CFX_WideString& wsNumSymbol) const { | 245 CFX_WideString& wsNumSymbol) const { |
| 230 switch (eType) { | 246 switch (eType) { |
| 231 case FX_LOCALENUMSYMBOL_Decimal: | 247 case FX_LOCALENUMSYMBOL_Decimal: |
| 232 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"decimal")); | 248 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"decimal")); |
| 233 break; | 249 break; |
| 234 case FX_LOCALENUMSYMBOL_Grouping: | 250 case FX_LOCALENUMSYMBOL_Grouping: |
| 235 wsNumSymbol = | 251 wsNumSymbol = |
| 236 GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"grouping")); | 252 GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"grouping")); |
| 237 break; | 253 break; |
| 238 case FX_LOCALENUMSYMBOL_Percent: | 254 case FX_LOCALENUMSYMBOL_Percent: |
| 239 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"percent")); | 255 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"percent")); |
| 240 break; | 256 break; |
| 241 case FX_LOCALENUMSYMBOL_Minus: | 257 case FX_LOCALENUMSYMBOL_Minus: |
| 242 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"minus")); | 258 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"minus")); |
| 243 break; | 259 break; |
| 244 case FX_LOCALENUMSYMBOL_Zero: | 260 case FX_LOCALENUMSYMBOL_Zero: |
| 245 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"zero")); | 261 wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, FX_WSTRC(L"zero")); |
| 246 break; | 262 break; |
| 247 case FX_LOCALENUMSYMBOL_CurrencySymbol: | 263 case FX_LOCALENUMSYMBOL_CurrencySymbol: |
| 248 wsNumSymbol = | 264 wsNumSymbol = |
| 249 GetSymbol(XFA_Element::CurrencySymbols, FX_WSTRC(L"symbol")); | 265 GetSymbol(XFA_Element::CurrencySymbols, FX_WSTRC(L"symbol")); |
| 250 break; | 266 break; |
| 251 case FX_LOCALENUMSYMBOL_CurrencyName: | 267 case FX_LOCALENUMSYMBOL_CurrencyName: |
| 252 wsNumSymbol = | 268 wsNumSymbol = |
| 253 GetSymbol(XFA_Element::CurrencySymbols, FX_WSTRC(L"isoname")); | 269 GetSymbol(XFA_Element::CurrencySymbols, FX_WSTRC(L"isoname")); |
| 254 break; | 270 break; |
| 255 } | 271 } |
| 256 } | 272 } |
| 273 |
| 257 void CXFA_NodeLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { | 274 void CXFA_NodeLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { |
| 258 CXFA_Node* pSymbols = | 275 CXFA_Node* pSymbols = |
| 259 m_pLocale ? m_pLocale->GetChild(0, XFA_Element::DateTimeSymbols) | 276 m_pLocale ? m_pLocale->GetChild(0, XFA_Element::DateTimeSymbols) |
| 260 : nullptr; | 277 : nullptr; |
| 261 wsDtSymbol = pSymbols ? pSymbols->GetContent() : CFX_WideString(); | 278 wsDtSymbol = pSymbols ? pSymbols->GetContent() : CFX_WideString(); |
| 262 } | 279 } |
| 280 |
| 263 void CXFA_NodeLocale::GetMonthName(int32_t nMonth, | 281 void CXFA_NodeLocale::GetMonthName(int32_t nMonth, |
| 264 CFX_WideString& wsMonthName, | 282 CFX_WideString& wsMonthName, |
| 265 FX_BOOL bAbbr) const { | 283 FX_BOOL bAbbr) const { |
| 266 wsMonthName = GetCalendarSymbol(XFA_Element::MonthNames, nMonth, bAbbr); | 284 wsMonthName = GetCalendarSymbol(XFA_Element::MonthNames, nMonth, bAbbr); |
| 267 } | 285 } |
| 286 |
| 268 void CXFA_NodeLocale::GetDayName(int32_t nWeek, | 287 void CXFA_NodeLocale::GetDayName(int32_t nWeek, |
| 269 CFX_WideString& wsDayName, | 288 CFX_WideString& wsDayName, |
| 270 FX_BOOL bAbbr) const { | 289 FX_BOOL bAbbr) const { |
| 271 wsDayName = GetCalendarSymbol(XFA_Element::DayNames, nWeek, bAbbr); | 290 wsDayName = GetCalendarSymbol(XFA_Element::DayNames, nWeek, bAbbr); |
| 272 } | 291 } |
| 292 |
| 273 void CXFA_NodeLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, | 293 void CXFA_NodeLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, |
| 274 FX_BOOL bAM) const { | 294 FX_BOOL bAM) const { |
| 275 wsMeridiemName = | 295 wsMeridiemName = |
| 276 GetCalendarSymbol(XFA_Element::MeridiemNames, bAM ? 0 : 1, FALSE); | 296 GetCalendarSymbol(XFA_Element::MeridiemNames, bAM ? 0 : 1, FALSE); |
| 277 } | 297 } |
| 298 |
| 278 void CXFA_NodeLocale::GetTimeZone(FX_TIMEZONE& tz) const { | 299 void CXFA_NodeLocale::GetTimeZone(FX_TIMEZONE& tz) const { |
| 279 CXFA_TimeZoneProvider::Get()->GetTimeZone(tz); | 300 CXFA_TimeZoneProvider::Get()->GetTimeZone(tz); |
| 280 } | 301 } |
| 302 |
| 281 void CXFA_NodeLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { | 303 void CXFA_NodeLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { |
| 282 wsEraName = GetCalendarSymbol(XFA_Element::EraNames, bAD ? 1 : 0, FALSE); | 304 wsEraName = GetCalendarSymbol(XFA_Element::EraNames, bAD ? 1 : 0, FALSE); |
| 283 } | 305 } |
| 306 |
| 284 void CXFA_NodeLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | 307 void CXFA_NodeLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, |
| 285 CFX_WideString& wsPattern) const { | 308 CFX_WideString& wsPattern) const { |
| 286 switch (eType) { | 309 switch (eType) { |
| 287 case FX_LOCALEDATETIMESUBCATEGORY_Short: | 310 case FX_LOCALEDATETIMESUBCATEGORY_Short: |
| 288 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"short")); | 311 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"short")); |
| 289 break; | 312 break; |
| 290 case FX_LOCALEDATETIMESUBCATEGORY_Medium: | 313 case FX_LOCALEDATETIMESUBCATEGORY_Medium: |
| 291 case FX_LOCALEDATETIMESUBCATEGORY_Default: | 314 case FX_LOCALEDATETIMESUBCATEGORY_Default: |
| 292 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"med")); | 315 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"med")); |
| 293 break; | 316 break; |
| 294 case FX_LOCALEDATETIMESUBCATEGORY_Full: | 317 case FX_LOCALEDATETIMESUBCATEGORY_Full: |
| 295 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"full")); | 318 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"full")); |
| 296 break; | 319 break; |
| 297 case FX_LOCALEDATETIMESUBCATEGORY_Long: | 320 case FX_LOCALEDATETIMESUBCATEGORY_Long: |
| 298 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"long")); | 321 wsPattern = GetSymbol(XFA_Element::DatePatterns, FX_WSTRC(L"long")); |
| 299 break; | 322 break; |
| 300 } | 323 } |
| 301 } | 324 } |
| 325 |
| 302 void CXFA_NodeLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | 326 void CXFA_NodeLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, |
| 303 CFX_WideString& wsPattern) const { | 327 CFX_WideString& wsPattern) const { |
| 304 switch (eType) { | 328 switch (eType) { |
| 305 case FX_LOCALEDATETIMESUBCATEGORY_Short: | 329 case FX_LOCALEDATETIMESUBCATEGORY_Short: |
| 306 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"short")); | 330 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"short")); |
| 307 break; | 331 break; |
| 308 case FX_LOCALEDATETIMESUBCATEGORY_Medium: | 332 case FX_LOCALEDATETIMESUBCATEGORY_Medium: |
| 309 case FX_LOCALEDATETIMESUBCATEGORY_Default: | 333 case FX_LOCALEDATETIMESUBCATEGORY_Default: |
| 310 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"med")); | 334 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"med")); |
| 311 break; | 335 break; |
| 312 case FX_LOCALEDATETIMESUBCATEGORY_Full: | 336 case FX_LOCALEDATETIMESUBCATEGORY_Full: |
| 313 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"full")); | 337 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"full")); |
| 314 break; | 338 break; |
| 315 case FX_LOCALEDATETIMESUBCATEGORY_Long: | 339 case FX_LOCALEDATETIMESUBCATEGORY_Long: |
| 316 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"long")); | 340 wsPattern = GetSymbol(XFA_Element::TimePatterns, FX_WSTRC(L"long")); |
| 317 break; | 341 break; |
| 318 } | 342 } |
| 319 } | 343 } |
| 344 |
| 320 void CXFA_NodeLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, | 345 void CXFA_NodeLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, |
| 321 CFX_WideString& wsPattern) const { | 346 CFX_WideString& wsPattern) const { |
| 322 switch (eType) { | 347 switch (eType) { |
| 323 case FX_LOCALENUMPATTERN_Percent: | 348 case FX_LOCALENUMPATTERN_Percent: |
| 324 wsPattern = g_FX_Percent; | 349 wsPattern = g_FX_Percent; |
| 325 break; | 350 break; |
| 326 case FX_LOCALENUMPATTERN_Currency: | 351 case FX_LOCALENUMPATTERN_Currency: |
| 327 wsPattern = g_FX_Currency; | 352 wsPattern = g_FX_Currency; |
| 328 break; | 353 break; |
| 329 case FX_LOCALENUMPATTERN_Decimal: | 354 case FX_LOCALENUMPATTERN_Decimal: |
| 330 wsPattern = g_FX_Decimal; | 355 wsPattern = g_FX_Decimal; |
| 331 break; | 356 break; |
| 332 case FX_LOCALENUMPATTERN_Integer: | 357 case FX_LOCALENUMPATTERN_Integer: |
| 333 wsPattern = g_FX_Integer; | 358 wsPattern = g_FX_Integer; |
| 334 break; | 359 break; |
| 335 } | 360 } |
| 336 } | 361 } |
| 362 |
| 337 CXFA_Node* CXFA_NodeLocale::GetNodeByName(CXFA_Node* pParent, | 363 CXFA_Node* CXFA_NodeLocale::GetNodeByName(CXFA_Node* pParent, |
| 338 const CFX_WideStringC& wsName) const { | 364 const CFX_WideStringC& wsName) const { |
| 339 CXFA_Node* pChild = | 365 CXFA_Node* pChild = |
| 340 pParent ? pParent->GetNodeItem(XFA_NODEITEM_FirstChild) : nullptr; | 366 pParent ? pParent->GetNodeItem(XFA_NODEITEM_FirstChild) : nullptr; |
| 341 while (pChild) { | 367 while (pChild) { |
| 342 CFX_WideString wsChild; | 368 CFX_WideString wsChild; |
| 343 if (pChild->GetAttribute(XFA_ATTRIBUTE_Name, wsChild)) { | 369 if (pChild->GetAttribute(XFA_ATTRIBUTE_Name, wsChild)) { |
| 344 if (wsChild == wsName) { | 370 if (wsChild == wsName) { |
| 345 return pChild; | 371 return pChild; |
| 346 } | 372 } |
| 347 } | 373 } |
| 348 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); | 374 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 349 } | 375 } |
| 350 return nullptr; | 376 return nullptr; |
| 351 } | 377 } |
| 378 |
| 352 CFX_WideString CXFA_NodeLocale::GetSymbol( | 379 CFX_WideString CXFA_NodeLocale::GetSymbol( |
| 353 XFA_Element eElement, | 380 XFA_Element eElement, |
| 354 const CFX_WideStringC& symbol_type) const { | 381 const CFX_WideStringC& symbol_type) const { |
| 355 CXFA_Node* pSymbols = m_pLocale ? m_pLocale->GetChild(0, eElement) : nullptr; | 382 CXFA_Node* pSymbols = m_pLocale ? m_pLocale->GetChild(0, eElement) : nullptr; |
| 356 CXFA_Node* pSymbol = GetNodeByName(pSymbols, symbol_type); | 383 CXFA_Node* pSymbol = GetNodeByName(pSymbols, symbol_type); |
| 357 return pSymbol ? pSymbol->GetContent() : CFX_WideString(); | 384 return pSymbol ? pSymbol->GetContent() : CFX_WideString(); |
| 358 } | 385 } |
| 386 |
| 359 CFX_WideString CXFA_NodeLocale::GetCalendarSymbol(XFA_Element eElement, | 387 CFX_WideString CXFA_NodeLocale::GetCalendarSymbol(XFA_Element eElement, |
| 360 int index, | 388 int index, |
| 361 FX_BOOL bAbbr) const { | 389 FX_BOOL bAbbr) const { |
| 362 CXFA_Node* pCalendar = | 390 CXFA_Node* pCalendar = |
| 363 m_pLocale ? m_pLocale->GetChild(0, XFA_Element::CalendarSymbols) | 391 m_pLocale ? m_pLocale->GetChild(0, XFA_Element::CalendarSymbols) |
| 364 : nullptr; | 392 : nullptr; |
| 365 if (pCalendar) { | 393 if (pCalendar) { |
| 366 CXFA_Node* pNode = pCalendar->GetFirstChildByClass(eElement); | 394 CXFA_Node* pNode = pCalendar->GetFirstChildByClass(eElement); |
| 367 for (; pNode; pNode = pNode->GetNextSameClassSibling(eElement)) { | 395 for (; pNode; pNode = pNode->GetNextSameClassSibling(eElement)) { |
| 368 if (pNode->GetBoolean(XFA_ATTRIBUTE_Abbr) == bAbbr) { | 396 if (pNode->GetBoolean(XFA_ATTRIBUTE_Abbr) == bAbbr) { |
| 369 CXFA_Node* pSymbol = pNode->GetChild(index, XFA_Element::Unknown); | 397 CXFA_Node* pSymbol = pNode->GetChild(index, XFA_Element::Unknown); |
| 370 return pSymbol ? pSymbol->GetContent() : CFX_WideString(); | 398 return pSymbol ? pSymbol->GetContent() : CFX_WideString(); |
| 371 } | 399 } |
| 372 } | 400 } |
| 373 } | 401 } |
| 374 return CFX_WideString(); | 402 return CFX_WideString(); |
| 375 } | 403 } |
| OLD | NEW |