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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 471 } |
472 return wsLCID; | 472 return wsLCID; |
473 } | 473 } |
474 ccf++; | 474 ccf++; |
475 } | 475 } |
476 return CFX_WideString(); | 476 return CFX_WideString(); |
477 } | 477 } |
478 IFX_Locale* CFX_FormatString::GetTextFormat(const CFX_WideString& wsPattern, | 478 IFX_Locale* CFX_FormatString::GetTextFormat(const CFX_WideString& wsPattern, |
479 const CFX_WideStringC& wsCategory, | 479 const CFX_WideStringC& wsCategory, |
480 CFX_WideString& wsPurgePattern) { | 480 CFX_WideString& wsPurgePattern) { |
481 IFX_Locale* pLocale = NULL; | 481 IFX_Locale* pLocale = nullptr; |
482 int32_t ccf = 0; | 482 int32_t ccf = 0; |
483 int32_t iLenf = wsPattern.GetLength(); | 483 int32_t iLenf = wsPattern.GetLength(); |
484 const FX_WCHAR* pStr = wsPattern.c_str(); | 484 const FX_WCHAR* pStr = wsPattern.c_str(); |
485 FX_BOOL bBrackOpen = FALSE; | 485 FX_BOOL bBrackOpen = FALSE; |
486 CFX_WideStringC wsConstChars(gs_wsConstChars); | 486 CFX_WideStringC wsConstChars(gs_wsConstChars); |
487 while (ccf < iLenf) { | 487 while (ccf < iLenf) { |
488 if (pStr[ccf] == '\'') { | 488 if (pStr[ccf] == '\'') { |
489 int32_t iCurChar = ccf; | 489 int32_t iCurChar = ccf; |
490 FX_GetLiteralText(pStr, ccf, iLenf); | 490 FX_GetLiteralText(pStr, ccf, iLenf); |
491 wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1); | 491 wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 return pLocale; | 528 return pLocale; |
529 } | 529 } |
530 #define FX_NUMSTYLE_Percent 0x01 | 530 #define FX_NUMSTYLE_Percent 0x01 |
531 #define FX_NUMSTYLE_Exponent 0x02 | 531 #define FX_NUMSTYLE_Exponent 0x02 |
532 #define FX_NUMSTYLE_DotVorv 0x04 | 532 #define FX_NUMSTYLE_DotVorv 0x04 |
533 IFX_Locale* CFX_FormatString::GetNumericFormat(const CFX_WideString& wsPattern, | 533 IFX_Locale* CFX_FormatString::GetNumericFormat(const CFX_WideString& wsPattern, |
534 int32_t& iDotIndex, | 534 int32_t& iDotIndex, |
535 uint32_t& dwStyle, | 535 uint32_t& dwStyle, |
536 CFX_WideString& wsPurgePattern) { | 536 CFX_WideString& wsPurgePattern) { |
537 dwStyle = 0; | 537 dwStyle = 0; |
538 IFX_Locale* pLocale = NULL; | 538 IFX_Locale* pLocale = nullptr; |
539 int32_t ccf = 0; | 539 int32_t ccf = 0; |
540 int32_t iLenf = wsPattern.GetLength(); | 540 int32_t iLenf = wsPattern.GetLength(); |
541 const FX_WCHAR* pStr = wsPattern.c_str(); | 541 const FX_WCHAR* pStr = wsPattern.c_str(); |
542 FX_BOOL bFindDot = FALSE; | 542 FX_BOOL bFindDot = FALSE; |
543 FX_BOOL bBrackOpen = FALSE; | 543 FX_BOOL bBrackOpen = FALSE; |
544 CFX_WideStringC wsConstChars(gs_wsConstChars); | 544 CFX_WideStringC wsConstChars(gs_wsConstChars); |
545 while (ccf < iLenf) { | 545 while (ccf < iLenf) { |
546 if (pStr[ccf] == '\'') { | 546 if (pStr[ccf] == '\'') { |
547 int32_t iCurChar = ccf; | 547 int32_t iCurChar = ccf; |
548 FX_GetLiteralText(pStr, ccf, iLenf); | 548 FX_GetLiteralText(pStr, ccf, iLenf); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 if (g_FXLocaleNumSubCatData[i].uHash == dwSubHash) { | 584 if (g_FXLocaleNumSubCatData[i].uHash == dwSubHash) { |
585 eSubCategory = (FX_LOCALENUMSUBCATEGORY)g_FXLocaleNumSubCatData[i] | 585 eSubCategory = (FX_LOCALENUMSUBCATEGORY)g_FXLocaleNumSubCatData[i] |
586 .eSubCategory; | 586 .eSubCategory; |
587 break; | 587 break; |
588 } | 588 } |
589 } | 589 } |
590 wsSubCategory.clear(); | 590 wsSubCategory.clear(); |
591 if (!pLocale) { | 591 if (!pLocale) { |
592 pLocale = m_pLocaleMgr->GetDefLocale(); | 592 pLocale = m_pLocaleMgr->GetDefLocale(); |
593 } | 593 } |
594 ASSERT(pLocale != NULL); | |
595 pLocale->GetNumPattern(eSubCategory, wsSubCategory); | 594 pLocale->GetNumPattern(eSubCategory, wsSubCategory); |
596 iDotIndex = wsSubCategory.Find('.'); | 595 iDotIndex = wsSubCategory.Find('.'); |
597 if (iDotIndex > 0) { | 596 if (iDotIndex > 0) { |
598 iDotIndex += wsPurgePattern.GetLength(); | 597 iDotIndex += wsPurgePattern.GetLength(); |
599 bFindDot = TRUE; | 598 bFindDot = TRUE; |
600 dwStyle |= FX_NUMSTYLE_DotVorv; | 599 dwStyle |= FX_NUMSTYLE_DotVorv; |
601 } | 600 } |
602 wsPurgePattern += wsSubCategory; | 601 wsPurgePattern += wsSubCategory; |
603 if (eSubCategory == FX_LOCALENUMPATTERN_Percent) { | 602 if (eSubCategory == FX_LOCALENUMPATTERN_Percent) { |
604 dwStyle |= FX_NUMSTYLE_Percent; | 603 dwStyle |= FX_NUMSTYLE_Percent; |
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 if (bNeg) { | 1914 if (bNeg) { |
1916 wsValue = L'-' + wsValue; | 1915 wsValue = L'-' + wsValue; |
1917 } | 1916 } |
1918 return TRUE; | 1917 return TRUE; |
1919 } | 1918 } |
1920 FX_DATETIMETYPE CFX_FormatString::GetDateTimeFormat( | 1919 FX_DATETIMETYPE CFX_FormatString::GetDateTimeFormat( |
1921 const CFX_WideString& wsPattern, | 1920 const CFX_WideString& wsPattern, |
1922 IFX_Locale*& pLocale, | 1921 IFX_Locale*& pLocale, |
1923 CFX_WideString& wsDatePattern, | 1922 CFX_WideString& wsDatePattern, |
1924 CFX_WideString& wsTimePattern) { | 1923 CFX_WideString& wsTimePattern) { |
1925 pLocale = NULL; | 1924 pLocale = nullptr; |
1926 CFX_WideString wsTempPattern; | 1925 CFX_WideString wsTempPattern; |
1927 FX_LOCALECATEGORY eCategory = FX_LOCALECATEGORY_Unknown; | 1926 FX_LOCALECATEGORY eCategory = FX_LOCALECATEGORY_Unknown; |
1928 int32_t ccf = 0; | 1927 int32_t ccf = 0; |
1929 int32_t iLenf = wsPattern.GetLength(); | 1928 int32_t iLenf = wsPattern.GetLength(); |
1930 const FX_WCHAR* pStr = wsPattern.c_str(); | 1929 const FX_WCHAR* pStr = wsPattern.c_str(); |
1931 int32_t iFindCategory = 0; | 1930 int32_t iFindCategory = 0; |
1932 FX_BOOL bBraceOpen = FALSE; | 1931 FX_BOOL bBraceOpen = FALSE; |
1933 CFX_WideStringC wsConstChars(gs_wsConstChars); | 1932 CFX_WideStringC wsConstChars(gs_wsConstChars); |
1934 while (ccf < iLenf) { | 1933 while (ccf < iLenf) { |
1935 if (pStr[ccf] == '\'') { | 1934 if (pStr[ccf] == '\'') { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 FX_LOCALEDATETIMESUBCATEGORY eSubCategory = | 1990 FX_LOCALEDATETIMESUBCATEGORY eSubCategory = |
1992 FX_LOCALEDATETIMESUBCATEGORY_Medium; | 1991 FX_LOCALEDATETIMESUBCATEGORY_Medium; |
1993 for (int32_t i = 0; i < g_iFXLocaleDateTimeSubCatCount; i++) { | 1992 for (int32_t i = 0; i < g_iFXLocaleDateTimeSubCatCount; i++) { |
1994 if (g_FXLocaleDateTimeSubCatData[i].uHash == dwSubHash) { | 1993 if (g_FXLocaleDateTimeSubCatData[i].uHash == dwSubHash) { |
1995 eSubCategory = | 1994 eSubCategory = |
1996 (FX_LOCALEDATETIMESUBCATEGORY)g_FXLocaleDateTimeSubCatData[i] | 1995 (FX_LOCALEDATETIMESUBCATEGORY)g_FXLocaleDateTimeSubCatData[i] |
1997 .eSubCategory; | 1996 .eSubCategory; |
1998 break; | 1997 break; |
1999 } | 1998 } |
2000 } | 1999 } |
2001 if (!pLocale) { | 2000 if (!pLocale) |
2002 pLocale = m_pLocaleMgr->GetDefLocale(); | 2001 pLocale = m_pLocaleMgr->GetDefLocale(); |
2003 } | |
2004 ASSERT(pLocale != NULL); | |
2005 switch (eCategory) { | 2002 switch (eCategory) { |
2006 case FX_LOCALECATEGORY_Date: | 2003 case FX_LOCALECATEGORY_Date: |
2007 pLocale->GetDatePattern(eSubCategory, wsDatePattern); | 2004 pLocale->GetDatePattern(eSubCategory, wsDatePattern); |
2008 wsDatePattern = wsTempPattern + wsDatePattern; | 2005 wsDatePattern = wsTempPattern + wsDatePattern; |
2009 break; | 2006 break; |
2010 case FX_LOCALECATEGORY_Time: | 2007 case FX_LOCALECATEGORY_Time: |
2011 pLocale->GetTimePattern(eSubCategory, wsTimePattern); | 2008 pLocale->GetTimePattern(eSubCategory, wsTimePattern); |
2012 wsTimePattern = wsTempPattern + wsTimePattern; | 2009 wsTimePattern = wsTempPattern + wsTimePattern; |
2013 break; | 2010 break; |
2014 case FX_LOCALECATEGORY_DateTime: | 2011 case FX_LOCALECATEGORY_DateTime: |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 } | 2466 } |
2470 FX_BOOL CFX_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime, | 2467 FX_BOOL CFX_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime, |
2471 const CFX_WideString& wsPattern, | 2468 const CFX_WideString& wsPattern, |
2472 FX_DATETIMETYPE eDateTimeType, | 2469 FX_DATETIMETYPE eDateTimeType, |
2473 CFX_Unitime& dtValue) { | 2470 CFX_Unitime& dtValue) { |
2474 dtValue.Set(0); | 2471 dtValue.Set(0); |
2475 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { | 2472 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { |
2476 return FALSE; | 2473 return FALSE; |
2477 } | 2474 } |
2478 CFX_WideString wsDatePattern, wsTimePattern; | 2475 CFX_WideString wsDatePattern, wsTimePattern; |
2479 IFX_Locale* pLocale = NULL; | 2476 IFX_Locale* pLocale = nullptr; |
2480 FX_DATETIMETYPE eCategory = | 2477 FX_DATETIMETYPE eCategory = |
2481 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 2478 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
2482 if (!pLocale) { | 2479 if (!pLocale) { |
2483 return FALSE; | 2480 return FALSE; |
2484 } | 2481 } |
2485 if (eCategory == FX_DATETIMETYPE_Unknown) { | 2482 if (eCategory == FX_DATETIMETYPE_Unknown) { |
2486 eCategory = eDateTimeType; | 2483 eCategory = eDateTimeType; |
2487 } | 2484 } |
2488 if (eCategory == FX_DATETIMETYPE_Unknown) { | 2485 if (eCategory == FX_DATETIMETYPE_Unknown) { |
2489 return FALSE; | 2486 return FALSE; |
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3984 wsOutput = bDateFirst ? wsDateOut + wsTimeOut : wsTimeOut + wsDateOut; | 3981 wsOutput = bDateFirst ? wsDateOut + wsTimeOut : wsTimeOut + wsDateOut; |
3985 return bRet; | 3982 return bRet; |
3986 } | 3983 } |
3987 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, | 3984 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, |
3988 const CFX_WideString& wsPattern, | 3985 const CFX_WideString& wsPattern, |
3989 CFX_WideString& wsOutput) { | 3986 CFX_WideString& wsOutput) { |
3990 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { | 3987 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { |
3991 return FALSE; | 3988 return FALSE; |
3992 } | 3989 } |
3993 CFX_WideString wsDatePattern, wsTimePattern; | 3990 CFX_WideString wsDatePattern, wsTimePattern; |
3994 IFX_Locale* pLocale = NULL; | 3991 IFX_Locale* pLocale = nullptr; |
3995 FX_DATETIMETYPE eCategory = | 3992 FX_DATETIMETYPE eCategory = |
3996 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 3993 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
3997 if (pLocale == NULL || eCategory == FX_DATETIMETYPE_Unknown) { | 3994 if (!pLocale || eCategory == FX_DATETIMETYPE_Unknown) |
3998 return FALSE; | 3995 return FALSE; |
3999 } | 3996 |
4000 CFX_Unitime dt(0); | 3997 CFX_Unitime dt(0); |
4001 int32_t iT = wsSrcDateTime.Find(L"T"); | 3998 int32_t iT = wsSrcDateTime.Find(L"T"); |
4002 if (iT < 0) { | 3999 if (iT < 0) { |
4003 if (eCategory == FX_DATETIMETYPE_Date) { | 4000 if (eCategory == FX_DATETIMETYPE_Date) { |
4004 FX_DateFromCanonical(wsSrcDateTime, dt); | 4001 FX_DateFromCanonical(wsSrcDateTime, dt); |
4005 } else if (eCategory == FX_DATETIMETYPE_Time) { | 4002 } else if (eCategory == FX_DATETIMETYPE_Time) { |
4006 FX_TimeFromCanonical(wsSrcDateTime.AsStringC(), dt, pLocale); | 4003 FX_TimeFromCanonical(wsSrcDateTime.AsStringC(), dt, pLocale); |
4007 } | 4004 } |
4008 } else { | 4005 } else { |
4009 FX_DateFromCanonical(wsSrcDateTime.Left(iT), dt); | 4006 FX_DateFromCanonical(wsSrcDateTime.Left(iT), dt); |
4010 FX_TimeFromCanonical( | 4007 FX_TimeFromCanonical( |
4011 wsSrcDateTime.Right(wsSrcDateTime.GetLength() - iT - 1).AsStringC(), dt, | 4008 wsSrcDateTime.Right(wsSrcDateTime.GetLength() - iT - 1).AsStringC(), dt, |
4012 pLocale); | 4009 pLocale); |
4013 } | 4010 } |
4014 return FX_FormatDateTime(dt, wsDatePattern, wsTimePattern, | 4011 return FX_FormatDateTime(dt, wsDatePattern, wsTimePattern, |
4015 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, | 4012 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, |
4016 wsOutput); | 4013 wsOutput); |
4017 } | 4014 } |
4018 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, | 4015 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, |
4019 const CFX_WideString& wsPattern, | 4016 const CFX_WideString& wsPattern, |
4020 CFX_WideString& wsOutput, | 4017 CFX_WideString& wsOutput, |
4021 FX_DATETIMETYPE eDateTimeType) { | 4018 FX_DATETIMETYPE eDateTimeType) { |
4022 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { | 4019 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { |
4023 return FALSE; | 4020 return FALSE; |
4024 } | 4021 } |
4025 CFX_WideString wsDatePattern, wsTimePattern; | 4022 CFX_WideString wsDatePattern, wsTimePattern; |
4026 IFX_Locale* pLocale = NULL; | 4023 IFX_Locale* pLocale = nullptr; |
4027 FX_DATETIMETYPE eCategory = | 4024 FX_DATETIMETYPE eCategory = |
4028 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 4025 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
4029 if (!pLocale) { | 4026 if (!pLocale) { |
4030 return FALSE; | 4027 return FALSE; |
4031 } | 4028 } |
4032 if (eCategory == FX_DATETIMETYPE_Unknown) { | 4029 if (eCategory == FX_DATETIMETYPE_Unknown) { |
4033 if (eDateTimeType == FX_DATETIMETYPE_Time) { | 4030 if (eDateTimeType == FX_DATETIMETYPE_Time) { |
4034 wsTimePattern = wsDatePattern; | 4031 wsTimePattern = wsDatePattern; |
4035 wsDatePattern.clear(); | 4032 wsDatePattern.clear(); |
4036 } | 4033 } |
(...skipping 30 matching lines...) Expand all Loading... |
4067 } | 4064 } |
4068 return FALSE; | 4065 return FALSE; |
4069 } | 4066 } |
4070 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_Unitime& dt, | 4067 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_Unitime& dt, |
4071 const CFX_WideString& wsPattern, | 4068 const CFX_WideString& wsPattern, |
4072 CFX_WideString& wsOutput) { | 4069 CFX_WideString& wsOutput) { |
4073 if (wsPattern.IsEmpty()) { | 4070 if (wsPattern.IsEmpty()) { |
4074 return FALSE; | 4071 return FALSE; |
4075 } | 4072 } |
4076 CFX_WideString wsDatePattern, wsTimePattern; | 4073 CFX_WideString wsDatePattern, wsTimePattern; |
4077 IFX_Locale* pLocale = NULL; | 4074 IFX_Locale* pLocale = nullptr; |
4078 FX_DATETIMETYPE eCategory = | 4075 FX_DATETIMETYPE eCategory = |
4079 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 4076 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
4080 if (!pLocale) { | 4077 if (!pLocale) { |
4081 return FALSE; | 4078 return FALSE; |
4082 } | 4079 } |
4083 return FX_FormatDateTime(dt, wsPattern, wsTimePattern, | 4080 return FX_FormatDateTime(dt, wsPattern, wsTimePattern, |
4084 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, | 4081 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, |
4085 wsOutput); | 4082 wsOutput); |
4086 } | 4083 } |
4087 FX_BOOL CFX_FormatString::FormatZero(const CFX_WideString& wsPattern, | 4084 FX_BOOL CFX_FormatString::FormatZero(const CFX_WideString& wsPattern, |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4768 } | 4765 } |
4769 CFX_Decimal CFX_Decimal::operator*(const CFX_Decimal& val) const { | 4766 CFX_Decimal CFX_Decimal::operator*(const CFX_Decimal& val) const { |
4770 return Multiply(val); | 4767 return Multiply(val); |
4771 } | 4768 } |
4772 CFX_Decimal CFX_Decimal::operator/(const CFX_Decimal& val) const { | 4769 CFX_Decimal CFX_Decimal::operator/(const CFX_Decimal& val) const { |
4773 return Divide(val); | 4770 return Divide(val); |
4774 } | 4771 } |
4775 CFX_Decimal CFX_Decimal::operator%(const CFX_Decimal& val) const { | 4772 CFX_Decimal CFX_Decimal::operator%(const CFX_Decimal& val) const { |
4776 return Modulus(val); | 4773 return Modulus(val); |
4777 } | 4774 } |
OLD | NEW |