| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "core/fxcrt/include/fx_xml.h" | 10 #include "core/fxcrt/include/fx_xml.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 static const FX_WCHAR gs_wsTimeSymbols[] = L"hHkKMSFAzZ"; | 59 static const FX_WCHAR gs_wsTimeSymbols[] = L"hHkKMSFAzZ"; |
| 60 static const FX_WCHAR gs_wsDateSymbols[] = L"DJMEeGgYwW"; | 60 static const FX_WCHAR gs_wsDateSymbols[] = L"DJMEeGgYwW"; |
| 61 static const FX_WCHAR gs_wsConstChars[] = L",-:/. "; | 61 static const FX_WCHAR gs_wsConstChars[] = L",-:/. "; |
| 62 | 62 |
| 63 static const FX_WCHAR* const gs_LocalNumberSymbols[] = { | 63 static const FX_WCHAR* const gs_LocalNumberSymbols[] = { |
| 64 L"decimal", L"grouping", L"percent", L"minus", | 64 L"decimal", L"grouping", L"percent", L"minus", |
| 65 L"zero", L"currencySymbol", L"currencyName", | 65 L"zero", L"currencySymbol", L"currencyName", |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 IFX_Locale* IFX_Locale::Create(CXML_Element* pLocaleData) { | |
| 69 return new CFX_Locale(pLocaleData); | |
| 70 } | |
| 71 CFX_Locale::CFX_Locale(CXML_Element* pLocaleData) { | |
| 72 m_pElement = pLocaleData; | |
| 73 } | |
| 74 CFX_Locale::~CFX_Locale() {} | |
| 75 CFX_WideString CFX_Locale::GetName() { | |
| 76 return CFX_WideString(); | |
| 77 } | |
| 78 static CFX_WideString FX_GetXMLContent(const CFX_ByteStringC& bsSpace, | |
| 79 CXML_Element* pxmlElement, | |
| 80 const CFX_ByteStringC& bsTag, | |
| 81 const CFX_WideStringC& wsName) { | |
| 82 CXML_Element* pDatePattern = NULL; | |
| 83 int32_t nCount = pxmlElement->CountElements(bsSpace, bsTag); | |
| 84 int32_t i = 0; | |
| 85 for (; i < nCount; i++) { | |
| 86 pDatePattern = pxmlElement->GetElement(bsSpace, bsTag, i); | |
| 87 if (pDatePattern->GetAttrValue("name") == wsName) { | |
| 88 break; | |
| 89 } | |
| 90 } | |
| 91 if (i < nCount && pDatePattern) { | |
| 92 return pDatePattern->GetContent(0); | |
| 93 } | |
| 94 return L""; | |
| 95 } | |
| 96 void CFX_Locale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, | |
| 97 CFX_WideString& wsNumSymbol) const { | |
| 98 if (!m_pElement) { | |
| 99 return; | |
| 100 } | |
| 101 CFX_ByteString bsSpace; | |
| 102 CFX_WideString wsName = gs_LocalNumberSymbols[eType]; | |
| 103 CXML_Element* pNumberSymbols = | |
| 104 m_pElement->GetElement(bsSpace.AsStringC(), "numberSymbols"); | |
| 105 if (!pNumberSymbols) { | |
| 106 return; | |
| 107 } | |
| 108 wsNumSymbol = FX_GetXMLContent(bsSpace.AsStringC(), pNumberSymbols, | |
| 109 "numberSymbol", wsName.AsStringC()); | |
| 110 } | |
| 111 void CFX_Locale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { | |
| 112 if (!m_pElement) { | |
| 113 return; | |
| 114 } | |
| 115 CFX_ByteString bsSpace; | |
| 116 CXML_Element* pNumberSymbols = | |
| 117 m_pElement->GetElement(bsSpace.AsStringC(), "dateTimeSymbols"); | |
| 118 if (!pNumberSymbols) { | |
| 119 return; | |
| 120 } | |
| 121 wsDtSymbol = pNumberSymbols->GetContent(0); | |
| 122 } | |
| 123 static void FX_GetCalendarSymbol(CXML_Element* pXmlElement, | |
| 124 const CFX_ByteString& symbol_type, | |
| 125 int32_t index, | |
| 126 FX_BOOL bAbbr, | |
| 127 CFX_WideString& wsName) { | |
| 128 CFX_ByteString bsSpace; | |
| 129 CFX_ByteString pstrSymbolNames = symbol_type + "Names"; | |
| 130 CXML_Element* pChild = | |
| 131 pXmlElement->GetElement(bsSpace.AsStringC(), "calendarSymbols"); | |
| 132 if (!pChild) { | |
| 133 return; | |
| 134 } | |
| 135 CXML_Element* pSymbolNames = | |
| 136 pChild->GetElement(bsSpace.AsStringC(), pstrSymbolNames.AsStringC()); | |
| 137 if (!pSymbolNames) { | |
| 138 return; | |
| 139 } | |
| 140 if (pSymbolNames->GetAttrInteger("abbr") != bAbbr) { | |
| 141 pSymbolNames = | |
| 142 pChild->GetElement(bsSpace.AsStringC(), pstrSymbolNames.AsStringC(), 1); | |
| 143 } | |
| 144 if (pSymbolNames && pSymbolNames->GetAttrInteger("abbr") == bAbbr) { | |
| 145 CXML_Element* pSymbolName = pSymbolNames->GetElement( | |
| 146 bsSpace.AsStringC(), symbol_type.AsStringC(), index); | |
| 147 if (pSymbolName) { | |
| 148 wsName = pSymbolName->GetContent(0); | |
| 149 } | |
| 150 } | |
| 151 } | |
| 152 void CFX_Locale::GetMonthName(int32_t nMonth, | |
| 153 CFX_WideString& wsMonthName, | |
| 154 FX_BOOL bAbbr) const { | |
| 155 if (!m_pElement) { | |
| 156 return; | |
| 157 } | |
| 158 FX_GetCalendarSymbol(m_pElement, "month", nMonth, bAbbr, wsMonthName); | |
| 159 } | |
| 160 void CFX_Locale::GetDayName(int32_t nWeek, | |
| 161 CFX_WideString& wsDayName, | |
| 162 FX_BOOL bAbbr) const { | |
| 163 if (!m_pElement) { | |
| 164 return; | |
| 165 } | |
| 166 FX_GetCalendarSymbol(m_pElement, "day", nWeek, bAbbr, wsDayName); | |
| 167 } | |
| 168 void CFX_Locale::GetMeridiemName(CFX_WideString& wsMeridiemName, | |
| 169 FX_BOOL bAM) const { | |
| 170 if (!m_pElement) { | |
| 171 return; | |
| 172 } | |
| 173 FX_GetCalendarSymbol(m_pElement, "meridiem", bAM ? 0 : 1, FALSE, | |
| 174 wsMeridiemName); | |
| 175 } | |
| 176 static int32_t FX_ParseTimeZone(const FX_WCHAR* pStr, | 68 static int32_t FX_ParseTimeZone(const FX_WCHAR* pStr, |
| 177 int32_t iLen, | 69 int32_t iLen, |
| 178 FX_TIMEZONE& tz) { | 70 FX_TIMEZONE& tz) { |
| 179 tz.tzHour = 0; | 71 tz.tzHour = 0; |
| 180 tz.tzMinute = 0; | 72 tz.tzMinute = 0; |
| 181 if (iLen < 0) { | 73 if (iLen < 0) { |
| 182 return 0; | 74 return 0; |
| 183 } | 75 } |
| 184 int32_t iStart = 1; | 76 int32_t iStart = 1; |
| 185 int32_t iEnd = iStart + 2; | 77 int32_t iEnd = iStart + 2; |
| 186 while (iStart < iLen && iStart < iEnd) { | 78 while (iStart < iLen && iStart < iEnd) { |
| 187 tz.tzHour = tz.tzHour * 10 + pStr[iStart++] - '0'; | 79 tz.tzHour = tz.tzHour * 10 + pStr[iStart++] - '0'; |
| 188 } | 80 } |
| 189 if (iStart < iLen && pStr[iStart] == ':') { | 81 if (iStart < iLen && pStr[iStart] == ':') { |
| 190 iStart++; | 82 iStart++; |
| 191 } | 83 } |
| 192 iEnd = iStart + 2; | 84 iEnd = iStart + 2; |
| 193 while (iStart < iLen && iStart < iEnd) { | 85 while (iStart < iLen && iStart < iEnd) { |
| 194 tz.tzMinute = tz.tzMinute * 10 + pStr[iStart++] - '0'; | 86 tz.tzMinute = tz.tzMinute * 10 + pStr[iStart++] - '0'; |
| 195 } | 87 } |
| 196 if (pStr[0] == '-') { | 88 if (pStr[0] == '-') { |
| 197 tz.tzHour = -tz.tzHour; | 89 tz.tzHour = -tz.tzHour; |
| 198 } | 90 } |
| 199 return iStart; | 91 return iStart; |
| 200 } | 92 } |
| 201 void CFX_Locale::GetTimeZone(FX_TIMEZONE& tz) const { | 93 |
| 202 tz.tzHour = 0; | |
| 203 tz.tzMinute = 0; | |
| 204 if (!m_pElement) { | |
| 205 return; | |
| 206 } | |
| 207 CXML_Element* pxmlTimeZone = m_pElement->GetElement("", "timeZone"); | |
| 208 if (pxmlTimeZone) { | |
| 209 CFX_WideString wsTimeZone = pxmlTimeZone->GetContent(0); | |
| 210 FX_ParseTimeZone(wsTimeZone.c_str(), wsTimeZone.GetLength(), tz); | |
| 211 } | |
| 212 } | |
| 213 void CFX_Locale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { | |
| 214 if (!m_pElement) { | |
| 215 return; | |
| 216 } | |
| 217 FX_GetCalendarSymbol(m_pElement, "era", bAD ? 0 : 1, FALSE, wsEraName); | |
| 218 } | |
| 219 static void FX_GetPattern(CXML_Element* pXmlElement, | |
| 220 const CFX_ByteString& bsCategory, | |
| 221 const CFX_WideString& wsSubCategory, | |
| 222 CFX_WideString& wsPattern) { | |
| 223 CFX_ByteString bsSpace; | |
| 224 CXML_Element* pDatePatterns = pXmlElement->GetElement( | |
| 225 bsSpace.AsStringC(), (bsCategory + "s").AsStringC()); | |
| 226 if (!pDatePatterns) { | |
| 227 return; | |
| 228 } | |
| 229 wsPattern = | |
| 230 FX_GetXMLContent(bsSpace.AsStringC(), pDatePatterns, | |
| 231 bsCategory.AsStringC(), wsSubCategory.AsStringC()); | |
| 232 } | |
| 233 static void FX_GetDateTimePattern(CXML_Element* pXmlElement, | |
| 234 const CFX_ByteString& bsCategory, | |
| 235 FX_LOCALEDATETIMESUBCATEGORY eType, | |
| 236 CFX_WideString& wsPattern) { | |
| 237 CFX_WideString wsType = g_FXLocaleDateTimeSubCatData[eType].pName; | |
| 238 FX_GetPattern(pXmlElement, bsCategory, wsType, wsPattern); | |
| 239 } | |
| 240 void CFX_Locale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | |
| 241 CFX_WideString& wsPattern) const { | |
| 242 if (!m_pElement) { | |
| 243 return; | |
| 244 } | |
| 245 FX_GetDateTimePattern(m_pElement, "datePattern", eType, wsPattern); | |
| 246 } | |
| 247 void CFX_Locale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, | |
| 248 CFX_WideString& wsPattern) const { | |
| 249 if (!m_pElement) { | |
| 250 return; | |
| 251 } | |
| 252 FX_GetDateTimePattern(m_pElement, "timePattern", eType, wsPattern); | |
| 253 } | |
| 254 void CFX_Locale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, | |
| 255 CFX_WideString& wsPattern) const { | |
| 256 CFX_WideString wsType = g_FXLocaleNumSubCatData[eType].pName; | |
| 257 FX_GetPattern(m_pElement, "numberPattern", wsType, wsPattern); | |
| 258 } | |
| 259 static FX_BOOL FX_IsDigit(FX_WCHAR c) { | 94 static FX_BOOL FX_IsDigit(FX_WCHAR c) { |
| 260 return c >= '0' && c <= '9'; | 95 return c >= '0' && c <= '9'; |
| 261 } | 96 } |
| 262 static FX_BOOL FX_IsAlpha(FX_WCHAR c) { | 97 static FX_BOOL FX_IsAlpha(FX_WCHAR c) { |
| 263 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); | 98 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); |
| 264 } | 99 } |
| 265 static FX_BOOL FX_IsSpace(FX_WCHAR c) { | 100 static FX_BOOL FX_IsSpace(FX_WCHAR c) { |
| 266 return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); | 101 return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); |
| 267 } | 102 } |
| 268 static const FX_FLOAT gs_fraction_scales[] = { | 103 static const FX_FLOAT gs_fraction_scales[] = { |
| (...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 } | 1433 } |
| 1599 if (bHavePercentSymbol) { | 1434 if (bHavePercentSymbol) { |
| 1600 dbRetValue /= 100.0; | 1435 dbRetValue /= 100.0; |
| 1601 } | 1436 } |
| 1602 if (bNeg) { | 1437 if (bNeg) { |
| 1603 dbRetValue = -dbRetValue; | 1438 dbRetValue = -dbRetValue; |
| 1604 } | 1439 } |
| 1605 fValue = (FX_FLOAT)dbRetValue; | 1440 fValue = (FX_FLOAT)dbRetValue; |
| 1606 return TRUE; | 1441 return TRUE; |
| 1607 } | 1442 } |
| 1608 void FX_ParseNumString(const CFX_WideString& wsNum, CFX_WideString& wsResult) { | 1443 |
| 1609 int32_t iCount = wsNum.GetLength(); | |
| 1610 const FX_WCHAR* pStr = wsNum.c_str(); | |
| 1611 FX_WCHAR* pDst = wsResult.GetBuffer(iCount); | |
| 1612 int32_t nIndex = 0; | |
| 1613 FX_BOOL bMinus = FALSE; | |
| 1614 int32_t i = 0; | |
| 1615 for (i = 0; i < iCount; i++) { | |
| 1616 FX_WCHAR wc = pStr[i]; | |
| 1617 if (wc == '.') { | |
| 1618 break; | |
| 1619 } | |
| 1620 if ((wc == L'0' || wc == L' ' || wc == '+') && nIndex == 0) { | |
| 1621 continue; | |
| 1622 } | |
| 1623 if (wc == '-') { | |
| 1624 pDst[nIndex++] = wc; | |
| 1625 bMinus = TRUE; | |
| 1626 continue; | |
| 1627 } | |
| 1628 if (wc == L'0' && nIndex == 1 && bMinus) { | |
| 1629 continue; | |
| 1630 } | |
| 1631 pDst[nIndex++] = wc; | |
| 1632 } | |
| 1633 if (bMinus && nIndex == 1) { | |
| 1634 pDst[nIndex++] = '0'; | |
| 1635 } | |
| 1636 if (nIndex == 0) { | |
| 1637 wsResult.ReleaseBuffer(0); | |
| 1638 pDst = wsResult.GetBuffer(iCount + 1); | |
| 1639 pDst[nIndex++] = '0'; | |
| 1640 } | |
| 1641 int32_t j = 0; | |
| 1642 for (j = iCount - 1; j > i; j--) { | |
| 1643 FX_WCHAR wc = pStr[j]; | |
| 1644 if (wc != L'0' && wc != L' ') { | |
| 1645 break; | |
| 1646 } | |
| 1647 } | |
| 1648 if (j > i) { | |
| 1649 pDst[nIndex++] = '.'; | |
| 1650 FXSYS_wcsncpy(pDst + nIndex, pStr + i + 1, j - i); | |
| 1651 nIndex += j - i; | |
| 1652 } | |
| 1653 wsResult.ReleaseBuffer(nIndex); | |
| 1654 } | |
| 1655 FX_BOOL CFX_FormatString::ParseNum(const CFX_WideString& wsSrcNum, | 1444 FX_BOOL CFX_FormatString::ParseNum(const CFX_WideString& wsSrcNum, |
| 1656 const CFX_WideString& wsPattern, | 1445 const CFX_WideString& wsPattern, |
| 1657 CFX_WideString& wsValue) { | 1446 CFX_WideString& wsValue) { |
| 1658 wsValue.clear(); | 1447 wsValue.clear(); |
| 1659 if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) { | 1448 if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) { |
| 1660 return FALSE; | 1449 return FALSE; |
| 1661 } | 1450 } |
| 1662 int32_t dot_index_f = -1; | 1451 int32_t dot_index_f = -1; |
| 1663 uint32_t dwFormatStyle = 0; | 1452 uint32_t dwFormatStyle = 0; |
| 1664 CFX_WideString wsNumFormat; | 1453 CFX_WideString wsNumFormat; |
| (...skipping 3320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4985 } | 4774 } |
| 4986 CFX_Decimal CFX_Decimal::operator*(const CFX_Decimal& val) const { | 4775 CFX_Decimal CFX_Decimal::operator*(const CFX_Decimal& val) const { |
| 4987 return Multiply(val); | 4776 return Multiply(val); |
| 4988 } | 4777 } |
| 4989 CFX_Decimal CFX_Decimal::operator/(const CFX_Decimal& val) const { | 4778 CFX_Decimal CFX_Decimal::operator/(const CFX_Decimal& val) const { |
| 4990 return Divide(val); | 4779 return Divide(val); |
| 4991 } | 4780 } |
| 4992 CFX_Decimal CFX_Decimal::operator%(const CFX_Decimal& val) const { | 4781 CFX_Decimal CFX_Decimal::operator%(const CFX_Decimal& val) const { |
| 4993 return Modulus(val); | 4782 return Modulus(val); |
| 4994 } | 4783 } |
| OLD | NEW |