blob: 47885b428ba2e248a90b42c1073ebcfb1583baa5 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez37458412015-10-06 11:33:46 -07007#ifndef FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_
8#define FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez9a3f8122015-04-07 15:35:48 -070010#include "JS_Define.h"
11
Nico Weber9d8ec5a2015-08-04 13:00:21 -070012class CJS_PublicMethods : public CJS_Object {
13 public:
Tom Sepez808a99e2015-09-10 12:28:37 -070014 CJS_PublicMethods(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -070015 ~CJS_PublicMethods() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017 public:
18 static FX_BOOL AFNumber_Format(IFXJS_Context* cc,
19 const CJS_Parameters& params,
20 CJS_Value& vRet,
21 CFX_WideString& sError);
22 static FX_BOOL AFNumber_Keystroke(IFXJS_Context* cc,
23 const CJS_Parameters& params,
24 CJS_Value& vRet,
25 CFX_WideString& sError);
26 static FX_BOOL AFPercent_Format(IFXJS_Context* cc,
27 const CJS_Parameters& params,
28 CJS_Value& vRet,
29 CFX_WideString& sError);
30 static FX_BOOL AFPercent_Keystroke(IFXJS_Context* cc,
31 const CJS_Parameters& params,
32 CJS_Value& vRet,
33 CFX_WideString& sError);
34 static FX_BOOL AFDate_FormatEx(IFXJS_Context* cc,
35 const CJS_Parameters& params,
36 CJS_Value& vRet,
37 CFX_WideString& sError);
38 static FX_BOOL AFDate_KeystrokeEx(IFXJS_Context* cc,
39 const CJS_Parameters& params,
40 CJS_Value& vRet,
41 CFX_WideString& sError);
42 static FX_BOOL AFDate_Format(IFXJS_Context* cc,
43 const CJS_Parameters& params,
44 CJS_Value& vRet,
45 CFX_WideString& sError);
46 static FX_BOOL AFDate_Keystroke(IFXJS_Context* cc,
47 const CJS_Parameters& params,
48 CJS_Value& vRet,
49 CFX_WideString& sError);
50 static FX_BOOL AFTime_FormatEx(IFXJS_Context* cc,
51 const CJS_Parameters& params,
52 CJS_Value& vRet,
53 CFX_WideString& sError); //
54 static FX_BOOL AFTime_KeystrokeEx(IFXJS_Context* cc,
55 const CJS_Parameters& params,
56 CJS_Value& vRet,
57 CFX_WideString& sError);
58 static FX_BOOL AFTime_Format(IFXJS_Context* cc,
59 const CJS_Parameters& params,
60 CJS_Value& vRet,
61 CFX_WideString& sError);
62 static FX_BOOL AFTime_Keystroke(IFXJS_Context* cc,
63 const CJS_Parameters& params,
64 CJS_Value& vRet,
65 CFX_WideString& sError);
66 static FX_BOOL AFSpecial_Format(IFXJS_Context* cc,
67 const CJS_Parameters& params,
68 CJS_Value& vRet,
69 CFX_WideString& sError);
70 static FX_BOOL AFSpecial_Keystroke(IFXJS_Context* cc,
71 const CJS_Parameters& params,
72 CJS_Value& vRet,
73 CFX_WideString& sError);
74 static FX_BOOL AFSpecial_KeystrokeEx(IFXJS_Context* cc,
75 const CJS_Parameters& params,
76 CJS_Value& vRet,
77 CFX_WideString& sError); //
78 static FX_BOOL AFSimple(IFXJS_Context* cc,
79 const CJS_Parameters& params,
80 CJS_Value& vRet,
81 CFX_WideString& sError);
82 static FX_BOOL AFMakeNumber(IFXJS_Context* cc,
83 const CJS_Parameters& params,
84 CJS_Value& vRet,
85 CFX_WideString& sError);
86 static FX_BOOL AFSimple_Calculate(IFXJS_Context* cc,
87 const CJS_Parameters& params,
88 CJS_Value& vRet,
89 CFX_WideString& sError);
90 static FX_BOOL AFRange_Validate(IFXJS_Context* cc,
91 const CJS_Parameters& params,
92 CJS_Value& vRet,
93 CFX_WideString& sError);
94 static FX_BOOL AFMergeChange(IFXJS_Context* cc,
95 const CJS_Parameters& params,
96 CJS_Value& vRet,
97 CFX_WideString& sError);
98 static FX_BOOL AFParseDateEx(IFXJS_Context* cc,
99 const CJS_Parameters& params,
100 CJS_Value& vRet,
101 CFX_WideString& sError);
102 static FX_BOOL AFExtractNums(IFXJS_Context* cc,
103 const CJS_Parameters& params,
104 CJS_Value& vRet,
105 CFX_WideString& sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 public:
108 JS_STATIC_GLOBAL_FUN(AFNumber_Format);
109 JS_STATIC_GLOBAL_FUN(AFNumber_Keystroke);
110 JS_STATIC_GLOBAL_FUN(AFPercent_Format);
111 JS_STATIC_GLOBAL_FUN(AFPercent_Keystroke);
112 JS_STATIC_GLOBAL_FUN(AFDate_FormatEx);
113 JS_STATIC_GLOBAL_FUN(AFDate_KeystrokeEx);
114 JS_STATIC_GLOBAL_FUN(AFDate_Format);
115 JS_STATIC_GLOBAL_FUN(AFDate_Keystroke);
116 JS_STATIC_GLOBAL_FUN(AFTime_FormatEx);
117 JS_STATIC_GLOBAL_FUN(AFTime_KeystrokeEx);
118 JS_STATIC_GLOBAL_FUN(AFTime_Format);
119 JS_STATIC_GLOBAL_FUN(AFTime_Keystroke);
120 JS_STATIC_GLOBAL_FUN(AFSpecial_Format);
121 JS_STATIC_GLOBAL_FUN(AFSpecial_Keystroke);
122 JS_STATIC_GLOBAL_FUN(AFSpecial_KeystrokeEx);
123 JS_STATIC_GLOBAL_FUN(AFSimple);
124 JS_STATIC_GLOBAL_FUN(AFMakeNumber);
125 JS_STATIC_GLOBAL_FUN(AFSimple_Calculate);
126 JS_STATIC_GLOBAL_FUN(AFRange_Validate);
127 JS_STATIC_GLOBAL_FUN(AFMergeChange);
128 JS_STATIC_GLOBAL_FUN(AFParseDateEx);
129 JS_STATIC_GLOBAL_FUN(AFExtractNums);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 JS_STATIC_DECLARE_GLOBAL_FUN();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 public:
134 static int ParseStringInteger(const CFX_WideString& string,
135 int nStart,
136 int& nSkip,
137 int nMaxStep);
138 static CFX_WideString ParseStringString(const CFX_WideString& string,
139 int nStart,
140 int& nSkip);
141 static double MakeRegularDate(const CFX_WideString& value,
142 const CFX_WideString& format,
143 FX_BOOL& bWrongFormat);
144 static CFX_WideString MakeFormatDate(double dDate,
145 const CFX_WideString& format);
146 static FX_BOOL ConvertStringToNumber(const FX_WCHAR* swSource,
147 double& dRet,
148 FX_BOOL& bDot);
149 static double ParseStringToNumber(const FX_WCHAR* swSource);
150 static double ParseNormalDate(const CFX_WideString& value,
151 FX_BOOL& bWrongFormat);
152 static double MakeInterDate(CFX_WideString strValue);
153 static double ParseNumber(const FX_WCHAR* swSource,
154 FX_BOOL& bAllDigits,
155 FX_BOOL& bDot,
156 FX_BOOL& bSign,
157 FX_BOOL& bKXJS);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 public:
160 static CFX_WideString StrLTrim(const FX_WCHAR* pStr);
161 static CFX_WideString StrRTrim(const FX_WCHAR* pStr);
162 static CFX_WideString StrTrim(const FX_WCHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 static CFX_ByteString StrLTrim(const FX_CHAR* pStr);
165 static CFX_ByteString StrRTrim(const FX_CHAR* pStr);
166 static CFX_ByteString StrTrim(const FX_CHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700167
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 static FX_BOOL IsNumber(const FX_CHAR* string);
169 static FX_BOOL IsNumber(const FX_WCHAR* string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 static FX_BOOL IsDigit(char ch);
172 static FX_BOOL IsDigit(wchar_t ch);
173 static FX_BOOL IsAlphabetic(wchar_t ch);
174 static FX_BOOL IsAlphaNumeric(wchar_t ch);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 static FX_BOOL maskSatisfied(wchar_t c_Change, wchar_t c_Mask);
177 static FX_BOOL isReservedMaskChar(wchar_t ch);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 static double AF_Simple(const FX_WCHAR* sFuction,
180 double dValue1,
181 double dValue2);
182 static CJS_Array AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183};
184
Tom Sepez37458412015-10-06 11:33:46 -0700185#endif // FPDFSDK_SRC_JAVASCRIPT_PUBLICMETHODS_H_