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 "core/fxcrt/unowned_ptr.h"
13 #include "xfa/fxfa/parser/cxfa_node.h"
14 
15 class LocaleIface;
16 class CFX_DateTime;
17 class CXFA_LocaleMgr;
18 
19 #define XFA_VT_NULL 0
20 #define XFA_VT_BOOLEAN 1
21 #define XFA_VT_INTEGER 2
22 #define XFA_VT_DECIMAL 4
23 #define XFA_VT_FLOAT 8
24 #define XFA_VT_TEXT 16
25 #define XFA_VT_DATE 32
26 #define XFA_VT_TIME 64
27 #define XFA_VT_DATETIME 128
28 
29 class CXFA_LocaleValue {
30  public:
31   CXFA_LocaleValue();
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                    LocaleIface* pLocale,
40                    CXFA_LocaleMgr* pLocaleMgr);
41   CXFA_LocaleValue(const CXFA_LocaleValue& that);
42   ~CXFA_LocaleValue();
43 
44   CXFA_LocaleValue& operator=(const CXFA_LocaleValue& that);
45 
46   bool ValidateValue(const WideString& wsValue,
47                      const WideString& wsPattern,
48                      LocaleIface* pLocale,
49                      WideString* pMatchFormat);
50 
51   bool FormatPatterns(WideString& wsResult,
52                       const WideString& wsFormat,
53                       LocaleIface* pLocale,
54                       XFA_VALUEPICTURE eValueType) const;
55 
56   void GetNumericFormat(WideString& wsFormat, int32_t nIntLen, int32_t nDecLen);
57   bool ValidateNumericTemp(const WideString& wsNumeric,
58                            const WideString& wsFormat,
59                            LocaleIface* pLocale);
60 
IsValid()61   bool IsValid() const { return m_bValid; }
GetValue()62   const WideString& GetValue() const { return m_wsValue; }
GetType()63   uint32_t GetType() const { return m_dwType; }
64   double GetDoubleNum() const;
65   bool SetDate(const CFX_DateTime& d);
66   CFX_DateTime GetDate() const;
67   CFX_DateTime GetTime() const;
68 
69  private:
70   bool FormatSinglePattern(WideString& wsResult,
71                            const WideString& wsFormat,
72                            LocaleIface* pLocale,
73                            XFA_VALUEPICTURE eValueType) const;
74   bool ValidateCanonicalValue(const WideString& wsValue, uint32_t dwVType);
75   bool ValidateCanonicalDate(const WideString& wsDate, CFX_DateTime* unDate);
76   bool ValidateCanonicalTime(const WideString& wsTime);
77 
78   bool SetTime(const CFX_DateTime& t);
79   bool SetDateTime(const CFX_DateTime& dt);
80 
81   bool ParsePatternValue(const WideString& wsValue,
82                          const WideString& wsPattern,
83                          LocaleIface* pLocale);
84 
85   UnownedPtr<CXFA_LocaleMgr> m_pLocaleMgr;
86   WideString m_wsValue;
87   uint32_t m_dwType = XFA_VT_NULL;
88   bool m_bValid = true;
89 };
90 
91 #endif  // XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_
92