• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_CRT_CFGAS_FORMATSTRING_H_
8 #define XFA_FGAS_CRT_CFGAS_FORMATSTRING_H_
9 
10 #include <vector>
11 
12 #include "core/fxcrt/ifx_locale.h"
13 #include "xfa/fxfa/parser/cxfa_localemgr.h"
14 
15 bool FX_DateFromCanonical(const WideString& wsDate, CFX_DateTime* datetime);
16 bool FX_TimeFromCanonical(const WideStringView& wsTime,
17                           CFX_DateTime* datetime,
18                           IFX_Locale* pLocale);
19 
20 class CFGAS_FormatString {
21  public:
22   explicit CFGAS_FormatString(CXFA_LocaleMgr* pLocaleMgr);
23   ~CFGAS_FormatString();
24 
25   void SplitFormatString(const WideString& wsFormatString,
26                          std::vector<WideString>* wsPatterns);
27   FX_LOCALECATEGORY GetCategory(const WideString& wsPattern);
28 
29   bool ParseText(const WideString& wsSrcText,
30                  const WideString& wsPattern,
31                  WideString* wsValue);
32   bool ParseNum(const WideString& wsSrcNum,
33                 const WideString& wsPattern,
34                 WideString* wsValue);
35   bool ParseDateTime(const WideString& wsSrcDateTime,
36                      const WideString& wsPattern,
37                      FX_DATETIMETYPE eDateTimeType,
38                      CFX_DateTime* dtValue);
39   bool ParseZero(const WideString& wsSrcText, const WideString& wsPattern);
40   bool ParseNull(const WideString& wsSrcText, const WideString& wsPattern);
41 
42   bool FormatText(const WideString& wsSrcText,
43                   const WideString& wsPattern,
44                   WideString* wsOutput);
45   bool FormatNum(const WideString& wsSrcNum,
46                  const WideString& wsPattern,
47                  WideString* wsOutput);
48   bool FormatDateTime(const WideString& wsSrcDateTime,
49                       const WideString& wsPattern,
50                       FX_DATETIMETYPE eDateTimeType,
51                       WideString* wsOutput);
52   bool FormatZero(const WideString& wsPattern, WideString* wsOutput);
53   bool FormatNull(const WideString& wsPattern, WideString* wsOutput);
54 
55  private:
56   WideString GetTextFormat(const WideString& wsPattern,
57                            const WideStringView& wsCategory);
58   IFX_Locale* GetNumericFormat(const WideString& wsPattern,
59                                int32_t* iDotIndex,
60                                uint32_t* dwStyle,
61                                WideString* wsPurgePattern);
62   bool FormatStrNum(const WideStringView& wsInputNum,
63                     const WideString& wsPattern,
64                     WideString* wsOutput);
65   FX_DATETIMETYPE GetDateTimeFormat(const WideString& wsPattern,
66                                     IFX_Locale** pLocale,
67                                     WideString* wsDatePattern,
68                                     WideString* wsTimePattern);
69 
70   CXFA_LocaleMgr* m_pLocaleMgr;
71 };
72 
73 #endif  // XFA_FGAS_CRT_CFGAS_FORMATSTRING_H_
74