1 // Copyright 2014 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_ 8 #define XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_ 9 10 #include <stdint.h> 11 12 #include "core/fxcrt/unowned_ptr.h" 13 #include "core/fxcrt/widestring.h" 14 #include "v8/include/cppgc/macros.h" 15 #include "xfa/fxfa/parser/cxfa_node.h" 16 17 class CFX_DateTime; 18 class CXFA_LocaleMgr; 19 class GCedLocaleIface; 20 21 class CXFA_LocaleValue { 22 CPPGC_STACK_ALLOCATED(); // Raw/Unowned pointers allowed. 23 24 public: 25 enum class ValueType : uint8_t { 26 kNull = 0, 27 kBoolean, 28 kInteger, 29 kDecimal, 30 kFloat, 31 kText, 32 kDate, 33 kTime, 34 kDateTime, 35 }; 36 37 CXFA_LocaleValue(); 38 CXFA_LocaleValue(ValueType eType, CXFA_LocaleMgr* pLocaleMgr); 39 CXFA_LocaleValue(ValueType eType, 40 const WideString& wsValue, 41 CXFA_LocaleMgr* pLocaleMgr); 42 CXFA_LocaleValue(ValueType dwType, 43 const WideString& wsValue, 44 const WideString& wsFormat, 45 GCedLocaleIface* pLocale, 46 CXFA_LocaleMgr* pLocaleMgr); 47 CXFA_LocaleValue(const CXFA_LocaleValue& that); 48 ~CXFA_LocaleValue(); 49 50 CXFA_LocaleValue& operator=(const CXFA_LocaleValue& that); 51 52 bool ValidateValue(const WideString& wsValue, 53 const WideString& wsPattern, 54 GCedLocaleIface* pLocale, 55 WideString* pMatchFormat); 56 57 bool FormatPatterns(WideString& wsResult, 58 const WideString& wsFormat, 59 GCedLocaleIface* pLocale, 60 XFA_ValuePicture eValueType) const; 61 62 void GetNumericFormat(WideString& wsFormat, int32_t nIntLen, int32_t nDecLen); 63 bool ValidateNumericTemp(const WideString& wsNumeric, 64 const WideString& wsFormat, 65 GCedLocaleIface* pLocale); 66 IsValid()67 bool IsValid() const { return m_bValid; } GetValue()68 const WideString& GetValue() const { return m_wsValue; } GetType()69 ValueType GetType() const { return m_eType; } 70 double GetDoubleNum() const; 71 bool SetDate(const CFX_DateTime& d); 72 CFX_DateTime GetDate() const; 73 CFX_DateTime GetTime() const; 74 75 private: 76 bool FormatSinglePattern(WideString& wsResult, 77 const WideString& wsFormat, 78 GCedLocaleIface* pLocale, 79 XFA_ValuePicture eValueType) const; 80 bool ValidateCanonicalValue(const WideString& wsValue, ValueType eType); 81 bool ValidateCanonicalDate(const WideString& wsDate, CFX_DateTime* unDate); 82 bool ValidateCanonicalTime(const WideString& wsTime); 83 84 bool SetTime(const CFX_DateTime& t); 85 bool SetDateTime(const CFX_DateTime& dt); 86 87 bool ParsePatternValue(const WideString& wsValue, 88 const WideString& wsPattern, 89 GCedLocaleIface* pLocale); 90 91 UnownedPtr<CXFA_LocaleMgr> m_pLocaleMgr; // Ok, stack-only. 92 WideString m_wsValue; 93 ValueType m_eType = ValueType::kNull; 94 bool m_bValid = true; 95 }; 96 97 #endif // XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_ 98