• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CXFA_LOCALEVALUE_H_
8 #define XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_
9 
10 #include "core/fxcrt/fx_string.h"
11 #include "core/fxcrt/fx_system.h"
12 #include "xfa/fxfa/cxfa_widgetacc.h"
13 
14 class IFX_Locale;
15 class CFX_DateTime;
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 WideString& wsValue,
35                    CXFA_LocaleMgr* pLocaleMgr);
36   CXFA_LocaleValue(uint32_t dwType,
37                    const WideString& wsValue,
38                    const 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 WideString& wsValue,
45                      const WideString& wsPattern,
46                      IFX_Locale* pLocale,
47                      WideString* pMatchFormat);
48 
49   bool FormatPatterns(WideString& wsResult,
50                       const WideString& wsFormat,
51                       IFX_Locale* pLocale,
52                       XFA_VALUEPICTURE eValueType) const;
53 
54   void GetNumericFormat(WideString& wsFormat, int32_t nIntLen, int32_t nDecLen);
55   bool ValidateNumericTemp(const WideString& wsNumeric,
56                            const WideString& wsFormat,
57                            IFX_Locale* pLocale);
58 
GetValue()59   WideString GetValue() const { return m_wsValue; }
GetType()60   uint32_t GetType() const { return m_dwType; }
61   double GetDoubleNum() const;
62   bool SetDate(const CFX_DateTime& d);
63   CFX_DateTime GetDate() const;
64   CFX_DateTime GetTime() const;
65 
IsValid()66   bool IsValid() const { return m_bValid; }
67 
68  private:
69   bool FormatSinglePattern(WideString& wsResult,
70                            const WideString& wsFormat,
71                            IFX_Locale* pLocale,
72                            XFA_VALUEPICTURE eValueType) const;
73   bool ValidateCanonicalValue(const WideString& wsValue, uint32_t dwVType);
74   bool ValidateCanonicalDate(const WideString& wsDate, CFX_DateTime* unDate);
75   bool ValidateCanonicalTime(const WideString& wsTime);
76 
77   bool SetTime(const CFX_DateTime& t);
78   bool SetDateTime(const CFX_DateTime& dt);
79 
80   bool ParsePatternValue(const WideString& wsValue,
81                          const WideString& wsPattern,
82                          IFX_Locale* pLocale);
83 
84   CXFA_LocaleMgr* m_pLocaleMgr;
85   WideString m_wsValue;
86   uint32_t m_dwType;
87   bool m_bValid;
88 };
89 
90 #endif  // XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_
91