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/include/fx_string.h" 11 #include "core/fxcrt/include/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 FX_BOOL ValidateValue(const CFX_WideString& wsValue, 45 const CFX_WideString& wsPattern, 46 IFX_Locale* pLocale, 47 CFX_WideString* pMatchFormat = nullptr); 48 FX_BOOL FormatPatterns(CFX_WideString& wsResult, 49 const CFX_WideString& wsFormat, 50 IFX_Locale* pLocale, 51 XFA_VALUEPICTURE eValueType) const; 52 FX_BOOL FormatSinglePattern(CFX_WideString& wsResult, 53 const CFX_WideString& wsFormat, 54 IFX_Locale* pLocale, 55 XFA_VALUEPICTURE eValueType) const; 56 FX_BOOL ValidateCanonicalValue(const CFX_WideString& wsValue, 57 uint32_t dwVType); 58 FX_BOOL ValidateCanonicalDate(const CFX_WideString& wsDate, 59 CFX_Unitime& unDate); 60 FX_BOOL ValidateCanonicalTime(const CFX_WideString& wsTime); 61 FX_BOOL ValidateCanonicalDateTime(const CFX_WideString& wsDateTime); 62 void GetNumbericFormat(CFX_WideString& wsFormat, 63 int32_t nIntLen, 64 int32_t nDecLen, 65 FX_BOOL bSign = TRUE); 66 FX_BOOL ValidateNumericTemp(CFX_WideString& wsNumeric, 67 CFX_WideString& wsFormat, 68 IFX_Locale* pLocale = nullptr, 69 int32_t* pos = nullptr); 70 71 CFX_WideString GetValue() const; 72 uint32_t GetType() const; 73 void SetValue(const CFX_WideString& wsValue, uint32_t dwType); 74 CFX_WideString GetText() const; 75 FX_FLOAT GetNum() const; 76 FX_DOUBLE GetDoubleNum() const; 77 CFX_Unitime GetDate() const; 78 CFX_Unitime GetTime() const; 79 CFX_Unitime GetDateTime() const; 80 FX_BOOL SetText(const CFX_WideString& wsText); 81 FX_BOOL SetText(const CFX_WideString& wsText, 82 const CFX_WideString& wsFormat, 83 IFX_Locale* pLocale); 84 FX_BOOL SetNum(FX_FLOAT fNum); 85 FX_BOOL SetNum(const CFX_WideString& wsNum, 86 const CFX_WideString& wsFormat, 87 IFX_Locale* pLocale); 88 FX_BOOL SetDate(const CFX_Unitime& d); 89 FX_BOOL SetDate(const CFX_WideString& wsDate, 90 const CFX_WideString& wsFormat, 91 IFX_Locale* pLocale); 92 FX_BOOL SetTime(const CFX_Unitime& t); 93 FX_BOOL SetTime(const CFX_WideString& wsTime, 94 const CFX_WideString& wsFormat, 95 IFX_Locale* pLocale); 96 FX_BOOL SetDateTime(const CFX_Unitime& dt); 97 FX_BOOL SetDateTime(const CFX_WideString& wsDateTime, 98 const CFX_WideString& wsFormat, 99 IFX_Locale* pLocale); IsNull()100 bool IsNull() const { return m_dwType == XFA_VT_NULL; } IsEmpty()101 FX_BOOL IsEmpty() const { return m_wsValue.IsEmpty(); } IsValid()102 FX_BOOL IsValid() const { return m_bValid; } 103 104 protected: 105 FX_BOOL ParsePatternValue(const CFX_WideString& wsValue, 106 const CFX_WideString& wsPattern, 107 IFX_Locale* pLocale); 108 CXFA_LocaleMgr* m_pLocaleMgr; 109 CFX_WideString m_wsValue; 110 uint32_t m_dwType; 111 FX_BOOL m_bValid; 112 }; 113 114 #endif // XFA_FXFA_PARSER_XFA_LOCALEVALUE_H_ 115