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); | 594 ASSERT(pLocale); |
595 pLocale->GetNumPattern(eSubCategory, wsSubCategory); | 595 pLocale->GetNumPattern(eSubCategory, wsSubCategory); |
596 iDotIndex = wsSubCategory.Find('.'); | 596 iDotIndex = wsSubCategory.Find('.'); |
597 if (iDotIndex > 0) { | 597 if (iDotIndex > 0) { |
598 iDotIndex += wsPurgePattern.GetLength(); | 598 iDotIndex += wsPurgePattern.GetLength(); |
599 bFindDot = TRUE; | 599 bFindDot = TRUE; |
600 dwStyle |= FX_NUMSTYLE_DotVorv; | 600 dwStyle |= FX_NUMSTYLE_DotVorv; |
601 } | 601 } |
602 wsPurgePattern += wsSubCategory; | 602 wsPurgePattern += wsSubCategory; |
603 if (eSubCategory == FX_LOCALENUMPATTERN_Percent) { | 603 if (eSubCategory == FX_LOCALENUMPATTERN_Percent) { |
604 dwStyle |= FX_NUMSTYLE_Percent; | 604 dwStyle |= FX_NUMSTYLE_Percent; |
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 if (bNeg) { | 1915 if (bNeg) { |
1916 wsValue = L'-' + wsValue; | 1916 wsValue = L'-' + wsValue; |
1917 } | 1917 } |
1918 return TRUE; | 1918 return TRUE; |
1919 } | 1919 } |
1920 FX_DATETIMETYPE CFX_FormatString::GetDateTimeFormat( | 1920 FX_DATETIMETYPE CFX_FormatString::GetDateTimeFormat( |
1921 const CFX_WideString& wsPattern, | 1921 const CFX_WideString& wsPattern, |
1922 IFX_Locale*& pLocale, | 1922 IFX_Locale*& pLocale, |
1923 CFX_WideString& wsDatePattern, | 1923 CFX_WideString& wsDatePattern, |
1924 CFX_WideString& wsTimePattern) { | 1924 CFX_WideString& wsTimePattern) { |
1925 pLocale = NULL; | 1925 pLocale = nullptr; |
1926 CFX_WideString wsTempPattern; | 1926 CFX_WideString wsTempPattern; |
1927 FX_LOCALECATEGORY eCategory = FX_LOCALECATEGORY_Unknown; | 1927 FX_LOCALECATEGORY eCategory = FX_LOCALECATEGORY_Unknown; |
1928 int32_t ccf = 0; | 1928 int32_t ccf = 0; |
1929 int32_t iLenf = wsPattern.GetLength(); | 1929 int32_t iLenf = wsPattern.GetLength(); |
1930 const FX_WCHAR* pStr = wsPattern.c_str(); | 1930 const FX_WCHAR* pStr = wsPattern.c_str(); |
1931 int32_t iFindCategory = 0; | 1931 int32_t iFindCategory = 0; |
1932 FX_BOOL bBraceOpen = FALSE; | 1932 FX_BOOL bBraceOpen = FALSE; |
1933 CFX_WideStringC wsConstChars(gs_wsConstChars); | 1933 CFX_WideStringC wsConstChars(gs_wsConstChars); |
1934 while (ccf < iLenf) { | 1934 while (ccf < iLenf) { |
1935 if (pStr[ccf] == '\'') { | 1935 if (pStr[ccf] == '\'') { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 if (g_FXLocaleDateTimeSubCatData[i].uHash == dwSubHash) { | 1994 if (g_FXLocaleDateTimeSubCatData[i].uHash == dwSubHash) { |
1995 eSubCategory = | 1995 eSubCategory = |
1996 (FX_LOCALEDATETIMESUBCATEGORY)g_FXLocaleDateTimeSubCatData[i] | 1996 (FX_LOCALEDATETIMESUBCATEGORY)g_FXLocaleDateTimeSubCatData[i] |
1997 .eSubCategory; | 1997 .eSubCategory; |
1998 break; | 1998 break; |
1999 } | 1999 } |
2000 } | 2000 } |
2001 if (!pLocale) { | 2001 if (!pLocale) { |
2002 pLocale = m_pLocaleMgr->GetDefLocale(); | 2002 pLocale = m_pLocaleMgr->GetDefLocale(); |
2003 } | 2003 } |
2004 ASSERT(pLocale != NULL); | 2004 ASSERT(pLocale); |
2005 switch (eCategory) { | 2005 switch (eCategory) { |
2006 case FX_LOCALECATEGORY_Date: | 2006 case FX_LOCALECATEGORY_Date: |
2007 pLocale->GetDatePattern(eSubCategory, wsDatePattern); | 2007 pLocale->GetDatePattern(eSubCategory, wsDatePattern); |
2008 wsDatePattern = wsTempPattern + wsDatePattern; | 2008 wsDatePattern = wsTempPattern + wsDatePattern; |
2009 break; | 2009 break; |
2010 case FX_LOCALECATEGORY_Time: | 2010 case FX_LOCALECATEGORY_Time: |
2011 pLocale->GetTimePattern(eSubCategory, wsTimePattern); | 2011 pLocale->GetTimePattern(eSubCategory, wsTimePattern); |
2012 wsTimePattern = wsTempPattern + wsTimePattern; | 2012 wsTimePattern = wsTempPattern + wsTimePattern; |
2013 break; | 2013 break; |
2014 case FX_LOCALECATEGORY_DateTime: | 2014 case FX_LOCALECATEGORY_DateTime: |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 } | 2469 } |
2470 FX_BOOL CFX_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime, | 2470 FX_BOOL CFX_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime, |
2471 const CFX_WideString& wsPattern, | 2471 const CFX_WideString& wsPattern, |
2472 FX_DATETIMETYPE eDateTimeType, | 2472 FX_DATETIMETYPE eDateTimeType, |
2473 CFX_Unitime& dtValue) { | 2473 CFX_Unitime& dtValue) { |
2474 dtValue.Set(0); | 2474 dtValue.Set(0); |
2475 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { | 2475 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { |
2476 return FALSE; | 2476 return FALSE; |
2477 } | 2477 } |
2478 CFX_WideString wsDatePattern, wsTimePattern; | 2478 CFX_WideString wsDatePattern, wsTimePattern; |
2479 IFX_Locale* pLocale = NULL; | 2479 IFX_Locale* pLocale = nullptr; |
2480 FX_DATETIMETYPE eCategory = | 2480 FX_DATETIMETYPE eCategory = |
2481 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 2481 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
2482 if (!pLocale) { | 2482 if (!pLocale) { |
2483 return FALSE; | 2483 return FALSE; |
2484 } | 2484 } |
2485 if (eCategory == FX_DATETIMETYPE_Unknown) { | 2485 if (eCategory == FX_DATETIMETYPE_Unknown) { |
2486 eCategory = eDateTimeType; | 2486 eCategory = eDateTimeType; |
2487 } | 2487 } |
2488 if (eCategory == FX_DATETIMETYPE_Unknown) { | 2488 if (eCategory == FX_DATETIMETYPE_Unknown) { |
2489 return FALSE; | 2489 return FALSE; |
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3984 wsOutput = bDateFirst ? wsDateOut + wsTimeOut : wsTimeOut + wsDateOut; | 3984 wsOutput = bDateFirst ? wsDateOut + wsTimeOut : wsTimeOut + wsDateOut; |
3985 return bRet; | 3985 return bRet; |
3986 } | 3986 } |
3987 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, | 3987 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, |
3988 const CFX_WideString& wsPattern, | 3988 const CFX_WideString& wsPattern, |
3989 CFX_WideString& wsOutput) { | 3989 CFX_WideString& wsOutput) { |
3990 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { | 3990 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { |
3991 return FALSE; | 3991 return FALSE; |
3992 } | 3992 } |
3993 CFX_WideString wsDatePattern, wsTimePattern; | 3993 CFX_WideString wsDatePattern, wsTimePattern; |
3994 IFX_Locale* pLocale = NULL; | 3994 IFX_Locale* pLocale = nullptr; |
3995 FX_DATETIMETYPE eCategory = | 3995 FX_DATETIMETYPE eCategory = |
3996 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 3996 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
3997 if (pLocale == NULL || eCategory == FX_DATETIMETYPE_Unknown) { | 3997 if (!pLocale || eCategory == FX_DATETIMETYPE_Unknown) { |
3998 return FALSE; | 3998 return FALSE; |
3999 } | 3999 } |
4000 CFX_Unitime dt(0); | 4000 CFX_Unitime dt(0); |
4001 int32_t iT = wsSrcDateTime.Find(L"T"); | 4001 int32_t iT = wsSrcDateTime.Find(L"T"); |
4002 if (iT < 0) { | 4002 if (iT < 0) { |
4003 if (eCategory == FX_DATETIMETYPE_Date) { | 4003 if (eCategory == FX_DATETIMETYPE_Date) { |
4004 FX_DateFromCanonical(wsSrcDateTime, dt); | 4004 FX_DateFromCanonical(wsSrcDateTime, dt); |
4005 } else if (eCategory == FX_DATETIMETYPE_Time) { | 4005 } else if (eCategory == FX_DATETIMETYPE_Time) { |
4006 FX_TimeFromCanonical(wsSrcDateTime.AsStringC(), dt, pLocale); | 4006 FX_TimeFromCanonical(wsSrcDateTime.AsStringC(), dt, pLocale); |
4007 } | 4007 } |
4008 } else { | 4008 } else { |
4009 FX_DateFromCanonical(wsSrcDateTime.Left(iT), dt); | 4009 FX_DateFromCanonical(wsSrcDateTime.Left(iT), dt); |
4010 FX_TimeFromCanonical( | 4010 FX_TimeFromCanonical( |
4011 wsSrcDateTime.Right(wsSrcDateTime.GetLength() - iT - 1).AsStringC(), dt, | 4011 wsSrcDateTime.Right(wsSrcDateTime.GetLength() - iT - 1).AsStringC(), dt, |
4012 pLocale); | 4012 pLocale); |
4013 } | 4013 } |
4014 return FX_FormatDateTime(dt, wsDatePattern, wsTimePattern, | 4014 return FX_FormatDateTime(dt, wsDatePattern, wsTimePattern, |
4015 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, | 4015 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, |
4016 wsOutput); | 4016 wsOutput); |
4017 } | 4017 } |
4018 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, | 4018 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, |
4019 const CFX_WideString& wsPattern, | 4019 const CFX_WideString& wsPattern, |
4020 CFX_WideString& wsOutput, | 4020 CFX_WideString& wsOutput, |
4021 FX_DATETIMETYPE eDateTimeType) { | 4021 FX_DATETIMETYPE eDateTimeType) { |
4022 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { | 4022 if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { |
4023 return FALSE; | 4023 return FALSE; |
4024 } | 4024 } |
4025 CFX_WideString wsDatePattern, wsTimePattern; | 4025 CFX_WideString wsDatePattern, wsTimePattern; |
4026 IFX_Locale* pLocale = NULL; | 4026 IFX_Locale* pLocale = nullptr; |
4027 FX_DATETIMETYPE eCategory = | 4027 FX_DATETIMETYPE eCategory = |
4028 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 4028 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
4029 if (!pLocale) { | 4029 if (!pLocale) { |
4030 return FALSE; | 4030 return FALSE; |
4031 } | 4031 } |
4032 if (eCategory == FX_DATETIMETYPE_Unknown) { | 4032 if (eCategory == FX_DATETIMETYPE_Unknown) { |
4033 if (eDateTimeType == FX_DATETIMETYPE_Time) { | 4033 if (eDateTimeType == FX_DATETIMETYPE_Time) { |
4034 wsTimePattern = wsDatePattern; | 4034 wsTimePattern = wsDatePattern; |
4035 wsDatePattern.clear(); | 4035 wsDatePattern.clear(); |
4036 } | 4036 } |
(...skipping 30 matching lines...) Expand all Loading... |
4067 } | 4067 } |
4068 return FALSE; | 4068 return FALSE; |
4069 } | 4069 } |
4070 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_Unitime& dt, | 4070 FX_BOOL CFX_FormatString::FormatDateTime(const CFX_Unitime& dt, |
4071 const CFX_WideString& wsPattern, | 4071 const CFX_WideString& wsPattern, |
4072 CFX_WideString& wsOutput) { | 4072 CFX_WideString& wsOutput) { |
4073 if (wsPattern.IsEmpty()) { | 4073 if (wsPattern.IsEmpty()) { |
4074 return FALSE; | 4074 return FALSE; |
4075 } | 4075 } |
4076 CFX_WideString wsDatePattern, wsTimePattern; | 4076 CFX_WideString wsDatePattern, wsTimePattern; |
4077 IFX_Locale* pLocale = NULL; | 4077 IFX_Locale* pLocale = nullptr; |
4078 FX_DATETIMETYPE eCategory = | 4078 FX_DATETIMETYPE eCategory = |
4079 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); | 4079 GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); |
4080 if (!pLocale) { | 4080 if (!pLocale) { |
4081 return FALSE; | 4081 return FALSE; |
4082 } | 4082 } |
4083 return FX_FormatDateTime(dt, wsPattern, wsTimePattern, | 4083 return FX_FormatDateTime(dt, wsPattern, wsTimePattern, |
4084 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, | 4084 eCategory != FX_DATETIMETYPE_TimeDate, pLocale, |
4085 wsOutput); | 4085 wsOutput); |
4086 } | 4086 } |
4087 FX_BOOL CFX_FormatString::FormatZero(const CFX_WideString& wsPattern, | 4087 FX_BOOL CFX_FormatString::FormatZero(const CFX_WideString& wsPattern, |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4768 } | 4768 } |
4769 CFX_Decimal CFX_Decimal::operator*(const CFX_Decimal& val) const { | 4769 CFX_Decimal CFX_Decimal::operator*(const CFX_Decimal& val) const { |
4770 return Multiply(val); | 4770 return Multiply(val); |
4771 } | 4771 } |
4772 CFX_Decimal CFX_Decimal::operator/(const CFX_Decimal& val) const { | 4772 CFX_Decimal CFX_Decimal::operator/(const CFX_Decimal& val) const { |
4773 return Divide(val); | 4773 return Divide(val); |
4774 } | 4774 } |
4775 CFX_Decimal CFX_Decimal::operator%(const CFX_Decimal& val) const { | 4775 CFX_Decimal CFX_Decimal::operator%(const CFX_Decimal& val) const { |
4776 return Modulus(val); | 4776 return Modulus(val); |
4777 } | 4777 } |
OLD | NEW |