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_FGAS_LOCALIZATION_FGAS_LOCALEIMP_H_
8 #define XFA_FGAS_LOCALIZATION_FGAS_LOCALEIMP_H_
9 
10 #include <vector>
11 
12 #include "xfa/fgas/localization/fgas_locale.h"
13 
14 class CFX_LCNumeric;
15 
16 class CFX_FormatString {
17  public:
18   CFX_FormatString(IFX_LocaleMgr* pLocaleMgr, bool bUseLCID);
19   ~CFX_FormatString();
20 
21   void SplitFormatString(const CFX_WideString& wsFormatString,
22                          std::vector<CFX_WideString>& wsPatterns);
23   FX_LOCALECATEGORY GetCategory(const CFX_WideString& wsPattern);
24   uint16_t GetLCID(const CFX_WideString& wsPattern);
25   CFX_WideString GetLocaleName(const CFX_WideString& wsPattern);
26   bool ParseText(const CFX_WideString& wsSrcText,
27                  const CFX_WideString& wsPattern,
28                  CFX_WideString& wsValue);
29   bool ParseNum(const CFX_WideString& wsSrcNum,
30                 const CFX_WideString& wsPattern,
31                 FX_FLOAT& fValue);
32   bool ParseNum(const CFX_WideString& wsSrcNum,
33                 const CFX_WideString& wsPattern,
34                 CFX_WideString& wsValue);
35   bool ParseDateTime(const CFX_WideString& wsSrcDateTime,
36                      const CFX_WideString& wsPattern,
37                      FX_DATETIMETYPE eDateTimeType,
38                      CFX_Unitime& dtValue);
39   bool ParseZero(const CFX_WideString& wsSrcText,
40                  const CFX_WideString& wsPattern);
41   bool ParseNull(const CFX_WideString& wsSrcText,
42                  const CFX_WideString& wsPattern);
43   bool FormatText(const CFX_WideString& wsSrcText,
44                   const CFX_WideString& wsPattern,
45                   CFX_WideString& wsOutput);
46   bool FormatNum(const CFX_WideString& wsSrcNum,
47                  const CFX_WideString& wsPattern,
48                  CFX_WideString& wsOutput);
49   bool FormatNum(FX_FLOAT fNum,
50                  const CFX_WideString& wsPattern,
51                  CFX_WideString& wsOutput);
52   bool FormatDateTime(const CFX_WideString& wsSrcDateTime,
53                       const CFX_WideString& wsPattern,
54                       CFX_WideString& wsOutput);
55   bool FormatDateTime(const CFX_WideString& wsSrcDateTime,
56                       const CFX_WideString& wsPattern,
57                       CFX_WideString& wsOutput,
58                       FX_DATETIMETYPE eDateTimeType);
59   bool FormatDateTime(const CFX_Unitime& dt,
60                       const CFX_WideString& wsPattern,
61                       CFX_WideString& wsOutput);
62   bool FormatZero(const CFX_WideString& wsPattern, CFX_WideString& wsOutput);
63   bool FormatNull(const CFX_WideString& wsPattern, CFX_WideString& wsOutput);
64 
65  protected:
66   IFX_Locale* GetTextFormat(const CFX_WideString& wsPattern,
67                             const CFX_WideStringC& wsCategory,
68                             CFX_WideString& wsPurgePattern);
69   IFX_Locale* GetNumericFormat(const CFX_WideString& wsPattern,
70                                int32_t& iDotIndex,
71                                uint32_t& dwStyle,
72                                CFX_WideString& wsPurgePattern);
73   bool FormatStrNum(const CFX_WideStringC& wsInputNum,
74                     const CFX_WideString& wsPattern,
75                     CFX_WideString& wsOutput);
76   bool FormatLCNumeric(CFX_LCNumeric& lcNum,
77                        const CFX_WideString& wsPattern,
78                        CFX_WideString& wsOutput);
79   FX_DATETIMETYPE GetDateTimeFormat(const CFX_WideString& wsPattern,
80                                     IFX_Locale*& pLocale,
81                                     CFX_WideString& wsDatePattern,
82                                     CFX_WideString& wsTimePattern);
83   IFX_Locale* GetPatternLocale(const CFX_WideString& wsLocale);
84 
85   IFX_LocaleMgr* m_pLocaleMgr;
86   bool m_bUseLCID;
87 };
88 
89 #endif  // XFA_FGAS_LOCALIZATION_FGAS_LOCALEIMP_H_
90