summaryrefslogtreecommitdiff
path: root/xfa/fgas/crt/cfgas_formatstring.h
blob: 5eae25dca5597ae81f12bf2d42f8de8714d412b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FGAS_CRT_CFGAS_FORMATSTRING_H_
#define XFA_FGAS_CRT_CFGAS_FORMATSTRING_H_

#include <vector>

#include "core/fxcrt/ifx_locale.h"
#include "xfa/fxfa/parser/cxfa_localemgr.h"

bool FX_DateFromCanonical(const WideString& wsDate, CFX_DateTime* datetime);
bool FX_TimeFromCanonical(const WideStringView& wsTime,
                          CFX_DateTime* datetime,
                          IFX_Locale* pLocale);

class CFGAS_FormatString {
 public:
  explicit CFGAS_FormatString(CXFA_LocaleMgr* pLocaleMgr);
  ~CFGAS_FormatString();

  void SplitFormatString(const WideString& wsFormatString,
                         std::vector<WideString>* wsPatterns);
  FX_LOCALECATEGORY GetCategory(const WideString& wsPattern);

  bool ParseText(const WideString& wsSrcText,
                 const WideString& wsPattern,
                 WideString* wsValue);
  bool ParseNum(const WideString& wsSrcNum,
                const WideString& wsPattern,
                WideString* wsValue);
  bool ParseDateTime(const WideString& wsSrcDateTime,
                     const WideString& wsPattern,
                     FX_DATETIMETYPE eDateTimeType,
                     CFX_DateTime* dtValue);
  bool ParseZero(const WideString& wsSrcText, const WideString& wsPattern);
  bool ParseNull(const WideString& wsSrcText, const WideString& wsPattern);

  bool FormatText(const WideString& wsSrcText,
                  const WideString& wsPattern,
                  WideString* wsOutput);
  bool FormatNum(const WideString& wsSrcNum,
                 const WideString& wsPattern,
                 WideString* wsOutput);
  bool FormatDateTime(const WideString& wsSrcDateTime,
                      const WideString& wsPattern,
                      FX_DATETIMETYPE eDateTimeType,
                      WideString* wsOutput);
  bool FormatZero(const WideString& wsPattern, WideString* wsOutput);
  bool FormatNull(const WideString& wsPattern, WideString* wsOutput);

 private:
  WideString GetTextFormat(const WideString& wsPattern,
                           const WideStringView& wsCategory);
  IFX_Locale* GetNumericFormat(const WideString& wsPattern,
                               int32_t* iDotIndex,
                               uint32_t* dwStyle,
                               WideString* wsPurgePattern);
  bool FormatStrNum(const WideStringView& wsInputNum,
                    const WideString& wsPattern,
                    WideString* wsOutput);
  FX_DATETIMETYPE GetDateTimeFormat(const WideString& wsPattern,
                                    IFX_Locale** pLocale,
                                    WideString* wsDatePattern,
                                    WideString* wsTimePattern);

  CXFA_LocaleMgr* m_pLocaleMgr;
};

#endif  // XFA_FGAS_CRT_CFGAS_FORMATSTRING_H_