1 // Copyright 2014 PDFium Authors. All rights reserved. 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_XFA_LOCALEVALUE_H_ 8 #define XFA_FXFA_PARSER_XFA_LOCALEVALUE_H_ 9 10 #include "core/fxcrt/fx_string.h" 11 #include "core/fxcrt/fx_system.h" 12 #include "xfa/fxfa/parser/cxfa_widgetdata.h" 13 14 class IFX_Locale; 15 class CFX_Unitime; 16 class CXFA_LocaleMgr; 17 18 #define XFA_VT_NULL 0 19 #define XFA_VT_BOOLEAN 1 20 #define XFA_VT_INTEGER 2 21 #define XFA_VT_DECIMAL 4 22 #define XFA_VT_FLOAT 8 23 #define XFA_VT_TEXT 16 24 #define XFA_VT_DATE 32 25 #define XFA_VT_TIME 64 26 #define XFA_VT_DATETIME 128 27 28 class CXFA_LocaleValue { 29 public: 30 CXFA_LocaleValue(); 31 CXFA_LocaleValue(const CXFA_LocaleValue& value); 32 CXFA_LocaleValue(uint32_t dwType, CXFA_LocaleMgr* pLocaleMgr); 33 CXFA_LocaleValue(uint32_t dwType, 34 const CFX_WideString& wsValue, 35 CXFA_LocaleMgr* pLocaleMgr); 36 CXFA_LocaleValue(uint32_t dwType, 37 const CFX_WideString& wsValue, 38 const CFX_WideString& wsFormat, 39 IFX_Locale* pLocale, 40 CXFA_LocaleMgr* pLocaleMgr); 41 ~CXFA_LocaleValue(); 42 CXFA_LocaleValue& operator=(const CXFA_LocaleValue& value); 43 44 bool ValidateValue(const CFX_WideString& wsValue, 45 const CFX_WideString& wsPattern, 46 IFX_Locale* pLocale, 47 CFX_WideString* pMatchFormat = nullptr); 48 bool FormatPatterns(CFX_WideString& wsResult, 49 const CFX_WideString& wsFormat, 50 IFX_Locale* pLocale, 51 XFA_VALUEPICTURE eValueType) const; 52 bool FormatSinglePattern(CFX_WideString& wsResult, 53 const CFX_WideString& wsFormat, 54 IFX_Locale* pLocale, 55 XFA_VALUEPICTURE eValueType) const; 56 bool ValidateCanonicalValue(const CFX_WideString& wsValue, uint32_t dwVType); 57 bool ValidateCanonicalDate(const CFX_WideString& wsDate, CFX_Unitime& unDate); 58 bool ValidateCanonicalTime(const CFX_WideString& wsTime); 59 bool ValidateCanonicalDateTime(const CFX_WideString& wsDateTime); 60 void GetNumbericFormat(CFX_WideString& wsFormat, 61 int32_t nIntLen, 62 int32_t nDecLen, 63 bool bSign = true); 64 bool ValidateNumericTemp(CFX_WideString& wsNumeric, 65 CFX_WideString& wsFormat, 66 IFX_Locale* pLocale = nullptr, 67 int32_t* pos = nullptr); 68 69 CFX_WideString GetValue() const; 70 uint32_t GetType() const; 71 void SetValue(const CFX_WideString& wsValue, uint32_t dwType); 72 CFX_WideString GetText() const; 73 FX_FLOAT GetNum() const; 74 FX_DOUBLE GetDoubleNum() const; 75 CFX_Unitime GetDate() const; 76 CFX_Unitime GetTime() const; 77 CFX_Unitime GetDateTime() const; 78 bool SetText(const CFX_WideString& wsText); 79 bool SetText(const CFX_WideString& wsText, 80 const CFX_WideString& wsFormat, 81 IFX_Locale* pLocale); 82 bool SetNum(FX_FLOAT fNum); 83 bool SetNum(const CFX_WideString& wsNum, 84 const CFX_WideString& wsFormat, 85 IFX_Locale* pLocale); 86 bool SetDate(const CFX_Unitime& d); 87 bool SetDate(const CFX_WideString& wsDate, 88 const CFX_WideString& wsFormat, 89 IFX_Locale* pLocale); 90 bool SetTime(const CFX_Unitime& t); 91 bool SetTime(const CFX_WideString& wsTime, 92 const CFX_WideString& wsFormat, 93 IFX_Locale* pLocale); 94 bool SetDateTime(const CFX_Unitime& dt); 95 bool SetDateTime(const CFX_WideString& wsDateTime, 96 const CFX_WideString& wsFormat, 97 IFX_Locale* pLocale); IsNull()98 bool IsNull() const { return m_dwType == XFA_VT_NULL; } IsEmpty()99 bool IsEmpty() const { return m_wsValue.IsEmpty(); } IsValid()100 bool IsValid() const { return m_bValid; } 101 102 protected: 103 bool ParsePatternValue(const CFX_WideString& wsValue, 104 const CFX_WideString& wsPattern, 105 IFX_Locale* pLocale); 106 CXFA_LocaleMgr* m_pLocaleMgr; 107 CFX_WideString m_wsValue; 108 uint32_t m_dwType; 109 bool m_bValid; 110 }; 111 112 #endif // XFA_FXFA_PARSER_XFA_LOCALEVALUE_H_ 113