| 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 "core/fxcrt/include/fx_xml.h" | 9 #include "core/fxcrt/include/fx_xml.h" |
| 10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 bsSymbols = "currencySymbols"; | 65 bsSymbols = "currencySymbols"; |
| 66 wsName = FX_WSTRC(L"symbol"); | 66 wsName = FX_WSTRC(L"symbol"); |
| 67 break; | 67 break; |
| 68 case FX_LOCALENUMSYMBOL_CurrencyName: | 68 case FX_LOCALENUMSYMBOL_CurrencyName: |
| 69 bsSymbols = "currencySymbols"; | 69 bsSymbols = "currencySymbols"; |
| 70 wsName = FX_WSTRC(L"isoname"); | 70 wsName = FX_WSTRC(L"isoname"); |
| 71 break; | 71 break; |
| 72 default: | 72 default: |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 CXML_Element* pElement = m_pLocaleData->GetElement("", bsSymbols); | 75 CXML_Element* pElement = m_pLocaleData->GetObjectBy("", bsSymbols); |
| 76 if (!pElement) { | 76 if (!pElement) { |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 GetPattern(pElement, CFX_ByteStringC((const FX_CHAR*)bsSymbols, | 79 GetPattern(pElement, CFX_ByteStringC((const FX_CHAR*)bsSymbols, |
| 80 bsSymbols.GetLength() - 1), | 80 bsSymbols.GetLength() - 1), |
| 81 wsName, wsNumSymbol); | 81 wsName, wsNumSymbol); |
| 82 } | 82 } |
| 83 void CXFA_XMLLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { | 83 void CXFA_XMLLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { |
| 84 if (!m_pLocaleData) { | 84 if (!m_pLocaleData) { |
| 85 return; | 85 return; |
| 86 } | 86 } |
| 87 CFX_ByteString bsSpace; | 87 CFX_ByteString bsSpace; |
| 88 CXML_Element* pNumberSymbols = | 88 CXML_Element* pNumberSymbols = |
| 89 m_pLocaleData->GetElement(bsSpace, "dateTimeSymbols"); | 89 m_pLocaleData->GetObjectBy(bsSpace, "dateTimeSymbols"); |
| 90 if (!pNumberSymbols) { | 90 if (!pNumberSymbols) { |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 wsDtSymbol = pNumberSymbols->GetContent(0); | 93 wsDtSymbol = pNumberSymbols->GetContent(0); |
| 94 } | 94 } |
| 95 void CXFA_XMLLocale::GetMonthName(int32_t nMonth, | 95 void CXFA_XMLLocale::GetMonthName(int32_t nMonth, |
| 96 CFX_WideString& wsMonthName, | 96 CFX_WideString& wsMonthName, |
| 97 FX_BOOL bAbbr) const { | 97 FX_BOOL bAbbr) const { |
| 98 wsMonthName = GetCalendarSymbol("month", nMonth, bAbbr); | 98 wsMonthName = GetCalendarSymbol("month", nMonth, bAbbr); |
| 99 } | 99 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 } | 112 } |
| 113 void CXFA_XMLLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { | 113 void CXFA_XMLLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { |
| 114 wsEraName = GetCalendarSymbol("era", bAD ? 1 : 0, FALSE); | 114 wsEraName = GetCalendarSymbol("era", bAD ? 1 : 0, FALSE); |
| 115 } | 115 } |
| 116 CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, | 116 CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, |
| 117 int index, | 117 int index, |
| 118 FX_BOOL bAbbr) const { | 118 FX_BOOL bAbbr) const { |
| 119 CFX_ByteString pstrSymbolNames = symbol + "Names"; | 119 CFX_ByteString pstrSymbolNames = symbol + "Names"; |
| 120 CFX_WideString wsSymbolName = L""; | 120 CFX_WideString wsSymbolName = L""; |
| 121 if (m_pLocaleData) { | 121 if (m_pLocaleData) { |
| 122 CXML_Element* pChild = m_pLocaleData->GetElement("", "calendarSymbols"); | 122 CXML_Element* pChild = m_pLocaleData->GetObjectBy("", "calendarSymbols"); |
| 123 if (pChild) { | 123 if (pChild) { |
| 124 CXML_Element* pSymbolNames = pChild->GetElement("", pstrSymbolNames); | 124 CXML_Element* pSymbolNames = pChild->GetObjectBy("", pstrSymbolNames); |
| 125 if (pSymbolNames) { | 125 if (pSymbolNames) { |
| 126 if (pSymbolNames->GetAttrInteger("abbr") != bAbbr) { | 126 if (pSymbolNames->GetAttrInteger("abbr") != bAbbr) { |
| 127 pSymbolNames = pChild->GetElement("", pstrSymbolNames, 1); | 127 pSymbolNames = pChild->GetObjectBy("", pstrSymbolNames, 1); |
| 128 } | 128 } |
| 129 if (pSymbolNames && pSymbolNames->GetAttrInteger("abbr") == bAbbr) { | 129 if (pSymbolNames && pSymbolNames->GetAttrInteger("abbr") == bAbbr) { |
| 130 CXML_Element* pSymbolName = | 130 CXML_Element* pSymbolName = |
| 131 pSymbolNames->GetElement("", symbol, index); | 131 pSymbolNames->GetObjectBy("", symbol, index); |
| 132 if (pSymbolName) { | 132 if (pSymbolName) { |
| 133 wsSymbolName = pSymbolName->GetContent(0); | 133 wsSymbolName = pSymbolName->GetContent(0); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 return wsSymbolName; | 139 return wsSymbolName; |
| 140 } | 140 } |
| 141 void CXFA_XMLLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | 141 void CXFA_XMLLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, |
| 142 CFX_WideString& wsPattern) const { | 142 CFX_WideString& wsPattern) const { |
| 143 CXML_Element* pElement = m_pLocaleData->GetElement("", "datePatterns"); | 143 CXML_Element* pElement = m_pLocaleData->GetObjectBy("", "datePatterns"); |
| 144 if (pElement == NULL) { | 144 if (pElement == NULL) { |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 CFX_WideString wsName; | 147 CFX_WideString wsName; |
| 148 switch (eType) { | 148 switch (eType) { |
| 149 case FX_LOCALEDATETIMESUBCATEGORY_Short: | 149 case FX_LOCALEDATETIMESUBCATEGORY_Short: |
| 150 wsName = L"short"; | 150 wsName = L"short"; |
| 151 break; | 151 break; |
| 152 case FX_LOCALEDATETIMESUBCATEGORY_Default: | 152 case FX_LOCALEDATETIMESUBCATEGORY_Default: |
| 153 case FX_LOCALEDATETIMESUBCATEGORY_Medium: | 153 case FX_LOCALEDATETIMESUBCATEGORY_Medium: |
| 154 wsName = L"med"; | 154 wsName = L"med"; |
| 155 break; | 155 break; |
| 156 case FX_LOCALEDATETIMESUBCATEGORY_Full: | 156 case FX_LOCALEDATETIMESUBCATEGORY_Full: |
| 157 wsName = L"full"; | 157 wsName = L"full"; |
| 158 break; | 158 break; |
| 159 case FX_LOCALEDATETIMESUBCATEGORY_Long: | 159 case FX_LOCALEDATETIMESUBCATEGORY_Long: |
| 160 wsName = L"long"; | 160 wsName = L"long"; |
| 161 break; | 161 break; |
| 162 } | 162 } |
| 163 GetPattern(pElement, "datePattern", wsName, wsPattern); | 163 GetPattern(pElement, "datePattern", wsName, wsPattern); |
| 164 } | 164 } |
| 165 void CXFA_XMLLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | 165 void CXFA_XMLLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, |
| 166 CFX_WideString& wsPattern) const { | 166 CFX_WideString& wsPattern) const { |
| 167 CXML_Element* pElement = m_pLocaleData->GetElement("", "timePatterns"); | 167 CXML_Element* pElement = m_pLocaleData->GetObjectBy("", "timePatterns"); |
| 168 if (pElement == NULL) { | 168 if (pElement == NULL) { |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 CFX_WideString wsName; | 171 CFX_WideString wsName; |
| 172 switch (eType) { | 172 switch (eType) { |
| 173 case FX_LOCALEDATETIMESUBCATEGORY_Short: | 173 case FX_LOCALEDATETIMESUBCATEGORY_Short: |
| 174 wsName = L"short"; | 174 wsName = L"short"; |
| 175 break; | 175 break; |
| 176 case FX_LOCALEDATETIMESUBCATEGORY_Default: | 176 case FX_LOCALEDATETIMESUBCATEGORY_Default: |
| 177 case FX_LOCALEDATETIMESUBCATEGORY_Medium: | 177 case FX_LOCALEDATETIMESUBCATEGORY_Medium: |
| 178 wsName = L"med"; | 178 wsName = L"med"; |
| 179 break; | 179 break; |
| 180 case FX_LOCALEDATETIMESUBCATEGORY_Full: | 180 case FX_LOCALEDATETIMESUBCATEGORY_Full: |
| 181 wsName = L"full"; | 181 wsName = L"full"; |
| 182 break; | 182 break; |
| 183 case FX_LOCALEDATETIMESUBCATEGORY_Long: | 183 case FX_LOCALEDATETIMESUBCATEGORY_Long: |
| 184 wsName = L"long"; | 184 wsName = L"long"; |
| 185 break; | 185 break; |
| 186 } | 186 } |
| 187 GetPattern(pElement, "timePattern", wsName, wsPattern); | 187 GetPattern(pElement, "timePattern", wsName, wsPattern); |
| 188 } | 188 } |
| 189 void CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, | 189 void CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, |
| 190 CFX_WideString& wsPattern) const { | 190 CFX_WideString& wsPattern) const { |
| 191 CXML_Element* pElement = m_pLocaleData->GetElement("", "numberPatterns"); | 191 CXML_Element* pElement = m_pLocaleData->GetObjectBy("", "numberPatterns"); |
| 192 if (pElement == NULL) { | 192 if (pElement == NULL) { |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 switch (eType) { | 195 switch (eType) { |
| 196 case FX_LOCALENUMPATTERN_Percent: | 196 case FX_LOCALENUMPATTERN_Percent: |
| 197 wsPattern = g_FX_Percent; | 197 wsPattern = g_FX_Percent; |
| 198 break; | 198 break; |
| 199 case FX_LOCALENUMPATTERN_Currency: | 199 case FX_LOCALENUMPATTERN_Currency: |
| 200 wsPattern = g_FX_Currency; | 200 wsPattern = g_FX_Currency; |
| 201 break; | 201 break; |
| 202 case FX_LOCALENUMPATTERN_Decimal: | 202 case FX_LOCALENUMPATTERN_Decimal: |
| 203 wsPattern = g_FX_Decimal; | 203 wsPattern = g_FX_Decimal; |
| 204 break; | 204 break; |
| 205 case FX_LOCALENUMPATTERN_Integer: | 205 case FX_LOCALENUMPATTERN_Integer: |
| 206 wsPattern = g_FX_Integer; | 206 wsPattern = g_FX_Integer; |
| 207 break; | 207 break; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 void CXFA_XMLLocale::GetPattern(CXML_Element* pElement, | 210 void CXFA_XMLLocale::GetPattern(CXML_Element* pElement, |
| 211 const CFX_ByteStringC& bsTag, | 211 const CFX_ByteStringC& bsTag, |
| 212 const CFX_WideStringC& wsName, | 212 const CFX_WideStringC& wsName, |
| 213 CFX_WideString& wsPattern) const { | 213 CFX_WideString& wsPattern) const { |
| 214 int32_t iCount = pElement->CountElements("", bsTag); | 214 int32_t iCount = pElement->CountElements("", bsTag); |
| 215 for (int32_t i = 0; i < iCount; i++) { | 215 for (int32_t i = 0; i < iCount; i++) { |
| 216 CXML_Element* pChild = pElement->GetElement("", bsTag, i); | 216 CXML_Element* pChild = pElement->GetObjectBy("", bsTag, i); |
| 217 if (pChild->GetAttrValue("name") == wsName) { | 217 if (pChild->GetAttrValue("name") == wsName) { |
| 218 wsPattern = pChild->GetContent(0); | 218 wsPattern = pChild->GetContent(0); |
| 219 return; | 219 return; |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) { | 223 CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) { |
| 224 m_pLocale = pLocale; | 224 m_pLocale = pLocale; |
| 225 } | 225 } |
| 226 CXFA_NodeLocale::~CXFA_NodeLocale() {} | 226 CXFA_NodeLocale::~CXFA_NodeLocale() {} |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 CXFA_Node* pNode = pCalendar->GetFirstChildByClass(eElement); | 368 CXFA_Node* pNode = pCalendar->GetFirstChildByClass(eElement); |
| 369 for (; pNode; pNode = pNode->GetNextSameClassSibling(eElement)) { | 369 for (; pNode; pNode = pNode->GetNextSameClassSibling(eElement)) { |
| 370 if (pNode->GetBoolean(XFA_ATTRIBUTE_Abbr) == bAbbr) { | 370 if (pNode->GetBoolean(XFA_ATTRIBUTE_Abbr) == bAbbr) { |
| 371 CXFA_Node* pSymbol = pNode->GetChild(index, XFA_ELEMENT_UNKNOWN); | 371 CXFA_Node* pSymbol = pNode->GetChild(index, XFA_ELEMENT_UNKNOWN); |
| 372 return pSymbol ? pSymbol->GetContent() : CFX_WideString(); | 372 return pSymbol ? pSymbol->GetContent() : CFX_WideString(); |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 return CFX_WideString(); | 376 return CFX_WideString(); |
| 377 } | 377 } |
| OLD | NEW |