• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The PDFium Authors
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_STRINGFORMATTER_H_
8 #define XFA_FGAS_CRT_CFGAS_STRINGFORMATTER_H_
9 
10 #include <vector>
11 
12 #include "core/fxcrt/widestring.h"
13 #include "third_party/base/span.h"
14 #include "xfa/fgas/crt/locale_iface.h"
15 
16 class CFX_DateTime;
17 class LocaleMgrIface;
18 
19 bool FX_DateFromCanonical(pdfium::span<const wchar_t> wsTime,
20                           CFX_DateTime* datetime);
21 bool FX_TimeFromCanonical(const LocaleIface* pLocale,
22                           pdfium::span<const wchar_t> wsTime,
23                           CFX_DateTime* datetime);
24 
25 class CFGAS_StringFormatter {
26  public:
27   enum class Category {
28     kUnknown,
29     kDate,
30     kTime,
31     kDateTime,
32     kNum,
33     kText,
34     kZero,
35     kNull,
36   };
37 
38   enum class DateTimeType {
39     kUnknown,
40     kDate,
41     kTime,
42     kDateTime,
43     kTimeDate,
44   };
45 
46   explicit CFGAS_StringFormatter(const WideString& wsPattern);
47   ~CFGAS_StringFormatter();
48 
49   static std::vector<WideString> SplitOnBars(const WideString& wsFormatString);
50 
51   Category GetCategory() const;
52 
53   bool ParseText(const WideString& wsSrcText, WideString* wsValue) const;
54   bool ParseNum(LocaleMgrIface* pLocaleMgr,
55                 const WideString& wsSrcNum,
56                 WideString* wsValue) const;
57   bool ParseDateTime(LocaleMgrIface* pLocaleMgr,
58                      const WideString& wsSrcDateTime,
59                      DateTimeType eDateTimeType,
60                      CFX_DateTime* dtValue) const;
61   bool ParseZero(const WideString& wsSrcText) const;
62   bool ParseNull(const WideString& wsSrcText) const;
63 
64   bool FormatText(const WideString& wsSrcText, WideString* wsOutput) const;
65   bool FormatNum(LocaleMgrIface* pLocaleMgr,
66                  const WideString& wsSrcNum,
67                  WideString* wsOutput) const;
68   bool FormatDateTime(LocaleMgrIface* pLocaleMgr,
69                       const WideString& wsSrcDateTime,
70                       DateTimeType eDateTimeType,
71                       WideString* wsOutput) const;
72   bool FormatZero(WideString* wsOutput) const;
73   bool FormatNull(WideString* wsOutput) const;
74 
75  private:
76   WideString GetTextFormat(WideStringView wsCategory) const;
77   LocaleIface* GetNumericFormat(LocaleMgrIface* pLocaleMgr,
78                                 size_t* iDotIndex,
79                                 uint32_t* dwStyle,
80                                 WideString* wsPurgePattern) const;
81   DateTimeType GetDateTimeFormat(LocaleMgrIface* pLocaleMgr,
82                                  LocaleIface** pLocale,
83                                  WideString* wsDatePattern,
84                                  WideString* wsTimePattern) const;
85 
86   const WideString m_wsPattern;                   // keep pattern string alive.
87   const pdfium::span<const wchar_t> m_spPattern;  // span into |m_wsPattern|.
88 };
89 
90 #endif  // XFA_FGAS_CRT_CFGAS_STRINGFORMATTER_H_
91