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