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_localevalue.h" | 7 #include "xfa/fxfa/parser/xfa_localevalue.h" |
8 | 8 |
9 #include "core/fxcrt/fx_ext.h" | 9 #include "core/fxcrt/fx_ext.h" |
10 #include "third_party/base/ptr_util.h" | |
10 #include "xfa/fgas/localization/fgas_localeimp.h" | 11 #include "xfa/fgas/localization/fgas_localeimp.h" |
11 #include "xfa/fxfa/parser/cxfa_document.h" | 12 #include "xfa/fxfa/parser/cxfa_document.h" |
12 #include "xfa/fxfa/parser/xfa_localemgr.h" | 13 #include "xfa/fxfa/parser/xfa_localemgr.h" |
13 #include "xfa/fxfa/parser/xfa_object.h" | 14 #include "xfa/fxfa/parser/xfa_object.h" |
14 #include "xfa/fxfa/parser/xfa_utils.h" | 15 #include "xfa/fxfa/parser/xfa_utils.h" |
15 | 16 |
16 static const FX_DOUBLE fraction_scales[] = {0.1, | 17 static const FX_DOUBLE fraction_scales[] = {0.1, |
17 0.01, | 18 0.01, |
18 0.001, | 19 0.001, |
19 0.0001, | 20 0.0001, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 case XFA_VT_DATE: | 87 case XFA_VT_DATE: |
87 return FX_LOCALECATEGORY_Date; | 88 return FX_LOCALECATEGORY_Date; |
88 case XFA_VT_TIME: | 89 case XFA_VT_TIME: |
89 return FX_LOCALECATEGORY_Time; | 90 return FX_LOCALECATEGORY_Time; |
90 case XFA_VT_DATETIME: | 91 case XFA_VT_DATETIME: |
91 return FX_LOCALECATEGORY_DateTime; | 92 return FX_LOCALECATEGORY_DateTime; |
92 } | 93 } |
93 } | 94 } |
94 return eCategory; | 95 return eCategory; |
95 } | 96 } |
97 | |
96 bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, | 98 bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, |
97 const CFX_WideString& wsPattern, | 99 const CFX_WideString& wsPattern, |
98 IFX_Locale* pLocale, | 100 IFX_Locale* pLocale, |
99 CFX_WideString* pMatchFormat) { | 101 CFX_WideString* pMatchFormat) { |
100 CFX_WideString wsOutput; | 102 CFX_WideString wsOutput; |
101 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); | 103 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); |
102 if (pLocale) { | 104 if (pLocale) |
103 m_pLocaleMgr->SetDefLocale(pLocale); | 105 m_pLocaleMgr->SetDefLocale(pLocale); |
104 } | |
105 CFX_FormatString* pFormat = nullptr; | |
106 if (m_pLocaleMgr) | |
Tom Sepez
2016/12/07 22:56:13
segv at 110 unless this block executes.
dsinclair
2016/12/07 23:17:43
Do we know if m_pLocalMgr can be null? Should we b
Tom Sepez
2016/12/07 23:36:36
Hope not. Should we early return ? Not unless we
dsinclair
2016/12/07 23:45:20
If CFX_FormatString doesn't need it, can we just r
Tom Sepez
2016/12/07 23:46:12
Also segv at 187, even if we manage to successfull
| |
107 pFormat = new CFX_FormatString(m_pLocaleMgr, false); | |
108 | 106 |
107 auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); | |
109 CFX_WideStringArray wsPatterns; | 108 CFX_WideStringArray wsPatterns; |
110 pFormat->SplitFormatString(wsPattern, wsPatterns); | 109 pFormat->SplitFormatString(wsPattern, wsPatterns); |
110 | |
111 bool bRet = false; | 111 bool bRet = false; |
112 int32_t iCount = wsPatterns.GetSize(); | 112 int32_t iCount = wsPatterns.GetSize(); |
113 int32_t i = 0; | 113 int32_t i = 0; |
114 for (; i < iCount && !bRet; i++) { | 114 for (; i < iCount && !bRet; i++) { |
115 CFX_WideString wsFormat = wsPatterns[i]; | 115 CFX_WideString wsFormat = wsPatterns[i]; |
116 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); | 116 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); |
117 eCategory = XFA_ValugeCategory(eCategory, m_dwType); | 117 eCategory = XFA_ValugeCategory(eCategory, m_dwType); |
118 switch (eCategory) { | 118 switch (eCategory) { |
119 case FX_LOCALECATEGORY_Null: | 119 case FX_LOCALECATEGORY_Null: |
120 bRet = pFormat->ParseNull(wsValue, wsFormat); | 120 bRet = pFormat->ParseNull(wsValue, wsFormat); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, | 174 bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, |
175 FX_DATETIMETYPE_DateTime); | 175 FX_DATETIMETYPE_DateTime); |
176 } | 176 } |
177 break; | 177 break; |
178 } | 178 } |
179 default: | 179 default: |
180 bRet = false; | 180 bRet = false; |
181 break; | 181 break; |
182 } | 182 } |
183 } | 183 } |
184 if (bRet && pMatchFormat) { | 184 if (bRet && pMatchFormat) |
185 *pMatchFormat = wsPatterns[i - 1]; | 185 *pMatchFormat = wsPatterns[i - 1]; |
186 } | 186 |
187 pFormat->Release(); | 187 if (pLocale) |
188 if (pLocale) { | |
189 m_pLocaleMgr->SetDefLocale(locale); | 188 m_pLocaleMgr->SetDefLocale(locale); |
190 } | 189 |
191 return bRet; | 190 return bRet; |
192 } | 191 } |
192 | |
193 CFX_WideString CXFA_LocaleValue::GetValue() const { | 193 CFX_WideString CXFA_LocaleValue::GetValue() const { |
194 return m_wsValue; | 194 return m_wsValue; |
195 } | 195 } |
196 uint32_t CXFA_LocaleValue::GetType() const { | 196 uint32_t CXFA_LocaleValue::GetType() const { |
197 return m_dwType; | 197 return m_dwType; |
198 } | 198 } |
199 void CXFA_LocaleValue::SetValue(const CFX_WideString& wsValue, | 199 void CXFA_LocaleValue::SetValue(const CFX_WideString& wsValue, |
200 uint32_t dwType) { | 200 uint32_t dwType) { |
201 m_wsValue = wsValue; | 201 m_wsValue = wsValue; |
202 m_dwType = dwType; | 202 m_dwType = dwType; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 m_wsValue += wsTemp; | 451 m_wsValue += wsTemp; |
452 } | 452 } |
453 return true; | 453 return true; |
454 } | 454 } |
455 bool CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime, | 455 bool CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime, |
456 const CFX_WideString& wsFormat, | 456 const CFX_WideString& wsFormat, |
457 IFX_Locale* pLocale) { | 457 IFX_Locale* pLocale) { |
458 m_dwType = XFA_VT_DATETIME; | 458 m_dwType = XFA_VT_DATETIME; |
459 return m_bValid = ParsePatternValue(wsDateTime, wsFormat, pLocale); | 459 return m_bValid = ParsePatternValue(wsDateTime, wsFormat, pLocale); |
460 } | 460 } |
461 | |
461 bool CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult, | 462 bool CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult, |
462 const CFX_WideString& wsFormat, | 463 const CFX_WideString& wsFormat, |
463 IFX_Locale* pLocale, | 464 IFX_Locale* pLocale, |
464 XFA_VALUEPICTURE eValueType) const { | 465 XFA_VALUEPICTURE eValueType) const { |
465 wsResult.clear(); | 466 auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); |
466 bool bRet = false; | |
467 | |
468 CFX_FormatString* pFormat = nullptr; | |
469 if (m_pLocaleMgr) | |
Tom Sepez
2016/12/07 22:56:13
segv at 473 unless this block executes.
dsinclair
2016/12/07 23:17:43
ditto
| |
470 pFormat = new CFX_FormatString(m_pLocaleMgr, false); | |
471 | |
472 CFX_WideStringArray wsPatterns; | 467 CFX_WideStringArray wsPatterns; |
473 pFormat->SplitFormatString(wsFormat, wsPatterns); | 468 pFormat->SplitFormatString(wsFormat, wsPatterns); |
469 wsResult.clear(); | |
474 int32_t iCount = wsPatterns.GetSize(); | 470 int32_t iCount = wsPatterns.GetSize(); |
475 for (int32_t i = 0; i < iCount; i++) { | 471 for (int32_t i = 0; i < iCount; i++) { |
476 bRet = FormatSinglePattern(wsResult, wsPatterns[i], pLocale, eValueType); | 472 if (FormatSinglePattern(wsResult, wsPatterns[i], pLocale, eValueType)) |
477 if (bRet) { | 473 return true; |
478 break; | |
479 } | |
480 } | 474 } |
481 pFormat->Release(); | 475 return false; |
482 return bRet; | |
483 } | 476 } |
477 | |
484 bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult, | 478 bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult, |
485 const CFX_WideString& wsFormat, | 479 const CFX_WideString& wsFormat, |
486 IFX_Locale* pLocale, | 480 IFX_Locale* pLocale, |
487 XFA_VALUEPICTURE eValueType) const { | 481 XFA_VALUEPICTURE eValueType) const { |
488 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); | 482 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); |
489 if (pLocale) { | 483 if (pLocale) |
490 m_pLocaleMgr->SetDefLocale(pLocale); | 484 m_pLocaleMgr->SetDefLocale(pLocale); |
491 } | 485 |
492 wsResult.clear(); | 486 wsResult.clear(); |
493 bool bRet = false; | 487 bool bRet = false; |
494 | 488 auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); |
495 CFX_FormatString* pFormat = nullptr; | |
496 if (m_pLocaleMgr) | |
Tom Sepez
2016/12/07 22:56:13
segv at 534 unless this block executes
dsinclair
2016/12/07 23:17:43
"
| |
497 pFormat = new CFX_FormatString(m_pLocaleMgr, false); | |
498 | |
499 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); | 489 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); |
500 eCategory = XFA_ValugeCategory(eCategory, m_dwType); | 490 eCategory = XFA_ValugeCategory(eCategory, m_dwType); |
501 switch (eCategory) { | 491 switch (eCategory) { |
502 case FX_LOCALECATEGORY_Null: | 492 case FX_LOCALECATEGORY_Null: |
503 if (m_wsValue.IsEmpty()) { | 493 if (m_wsValue.IsEmpty()) { |
504 bRet = pFormat->FormatNull(wsFormat, wsResult); | 494 bRet = pFormat->FormatNull(wsFormat, wsResult); |
505 } | 495 } |
506 break; | 496 break; |
507 case FX_LOCALECATEGORY_Zero: | 497 case FX_LOCALECATEGORY_Zero: |
508 if (m_wsValue == FX_WSTRC(L"0")) { | 498 if (m_wsValue == FX_WSTRC(L"0")) { |
(...skipping 15 matching lines...) Expand all Loading... | |
524 FX_DATETIMETYPE_Time); | 514 FX_DATETIMETYPE_Time); |
525 break; | 515 break; |
526 case FX_LOCALECATEGORY_DateTime: | 516 case FX_LOCALECATEGORY_DateTime: |
527 bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, | 517 bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, |
528 FX_DATETIMETYPE_DateTime); | 518 FX_DATETIMETYPE_DateTime); |
529 break; | 519 break; |
530 default: | 520 default: |
531 wsResult = m_wsValue; | 521 wsResult = m_wsValue; |
532 bRet = true; | 522 bRet = true; |
533 } | 523 } |
534 pFormat->Release(); | |
535 if (!bRet && (eCategory != FX_LOCALECATEGORY_Num || | 524 if (!bRet && (eCategory != FX_LOCALECATEGORY_Num || |
536 eValueType != XFA_VALUEPICTURE_Display)) { | 525 eValueType != XFA_VALUEPICTURE_Display)) { |
537 wsResult = m_wsValue; | 526 wsResult = m_wsValue; |
538 } | 527 } |
539 if (pLocale) { | 528 if (pLocale) |
540 m_pLocaleMgr->SetDefLocale(locale); | 529 m_pLocaleMgr->SetDefLocale(locale); |
541 } | 530 |
542 return bRet; | 531 return bRet; |
543 } | 532 } |
533 | |
544 static bool XFA_ValueSplitDateTime(const CFX_WideString& wsDateTime, | 534 static bool XFA_ValueSplitDateTime(const CFX_WideString& wsDateTime, |
545 CFX_WideString& wsDate, | 535 CFX_WideString& wsDate, |
546 CFX_WideString& wsTime) { | 536 CFX_WideString& wsTime) { |
547 wsDate = L""; | 537 wsDate = L""; |
548 wsTime = L""; | 538 wsTime = L""; |
549 if (wsDateTime.IsEmpty()) { | 539 if (wsDateTime.IsEmpty()) { |
550 return false; | 540 return false; |
551 } | 541 } |
552 int nSplitIndex = -1; | 542 int nSplitIndex = -1; |
553 nSplitIndex = wsDateTime.Find('T'); | 543 nSplitIndex = wsDateTime.Find('T'); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 } | 782 } |
793 wsDate = wsDateTime.Left(nSplitIndex); | 783 wsDate = wsDateTime.Left(nSplitIndex); |
794 wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); | 784 wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); |
795 CFX_Unitime dt; | 785 CFX_Unitime dt; |
796 return ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime); | 786 return ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime); |
797 } | 787 } |
798 bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, | 788 bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, |
799 const CFX_WideString& wsPattern, | 789 const CFX_WideString& wsPattern, |
800 IFX_Locale* pLocale) { | 790 IFX_Locale* pLocale) { |
801 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); | 791 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); |
802 if (pLocale) { | 792 if (pLocale) |
803 m_pLocaleMgr->SetDefLocale(pLocale); | 793 m_pLocaleMgr->SetDefLocale(pLocale); |
804 } | |
805 | 794 |
806 CFX_FormatString* pFormat = nullptr; | 795 auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); |
807 if (m_pLocaleMgr) | |
808 pFormat = new CFX_FormatString(m_pLocaleMgr, false); | |
Tom Sepez
2016/12/07 22:56:13
segv at 811, 881 unless this block executes
dsinclair
2016/12/07 23:17:43
"
| |
809 | |
810 CFX_WideStringArray wsPatterns; | 796 CFX_WideStringArray wsPatterns; |
811 pFormat->SplitFormatString(wsPattern, wsPatterns); | 797 pFormat->SplitFormatString(wsPattern, wsPatterns); |
812 bool bRet = false; | 798 bool bRet = false; |
813 int32_t iCount = wsPatterns.GetSize(); | 799 int32_t iCount = wsPatterns.GetSize(); |
814 for (int32_t i = 0; i < iCount && !bRet; i++) { | 800 for (int32_t i = 0; i < iCount && !bRet; i++) { |
815 CFX_WideString wsFormat = wsPatterns[i]; | 801 CFX_WideString wsFormat = wsPatterns[i]; |
816 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); | 802 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); |
817 eCategory = XFA_ValugeCategory(eCategory, m_dwType); | 803 eCategory = XFA_ValugeCategory(eCategory, m_dwType); |
818 switch (eCategory) { | 804 switch (eCategory) { |
819 case FX_LOCALECATEGORY_Null: | 805 case FX_LOCALECATEGORY_Null: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 SetDateTime(dt); | 854 SetDateTime(dt); |
869 } | 855 } |
870 break; | 856 break; |
871 } | 857 } |
872 default: | 858 default: |
873 m_wsValue = wsValue; | 859 m_wsValue = wsValue; |
874 bRet = true; | 860 bRet = true; |
875 break; | 861 break; |
876 } | 862 } |
877 } | 863 } |
878 if (!bRet) { | 864 if (!bRet) |
879 m_wsValue = wsValue; | 865 m_wsValue = wsValue; |
880 } | 866 |
881 pFormat->Release(); | 867 if (pLocale) |
882 if (pLocale) { | |
883 m_pLocaleMgr->SetDefLocale(locale); | 868 m_pLocaleMgr->SetDefLocale(locale); |
884 } | 869 |
885 return bRet; | 870 return bRet; |
886 } | 871 } |
872 | |
887 void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat, | 873 void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat, |
888 int32_t nIntLen, | 874 int32_t nIntLen, |
889 int32_t nDecLen, | 875 int32_t nDecLen, |
890 bool bSign) { | 876 bool bSign) { |
891 ASSERT(wsFormat.IsEmpty()); | 877 ASSERT(wsFormat.IsEmpty()); |
892 ASSERT(nIntLen >= -1 && nDecLen >= -1); | 878 ASSERT(nIntLen >= -1 && nDecLen >= -1); |
893 int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + (bSign ? 1 : 0) + | 879 int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + (bSign ? 1 : 0) + |
894 (nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1); | 880 (nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1); |
895 FX_WCHAR* lpBuf = wsFormat.GetBuffer(nTotalLen); | 881 FX_WCHAR* lpBuf = wsFormat.GetBuffer(nTotalLen); |
896 int32_t nPos = 0; | 882 int32_t nPos = 0; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
987 } else if (cf == L'z') { | 973 } else if (cf == L'z') { |
988 nf++; | 974 nf++; |
989 } else { | 975 } else { |
990 return false; | 976 return false; |
991 } | 977 } |
992 } | 978 } |
993 n++; | 979 n++; |
994 } | 980 } |
995 return n == nCount; | 981 return n == nCount; |
996 } | 982 } |
OLD | NEW |