blob: cff9e1147919cf323fe9adceab809385f84c9ec2 [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 Sepez19922bb2015-05-28 13:23:12 -07007#ifndef FPDFSDK_INCLUDE_JAVASCRIPT_PUBLICMETHODS_H_
8#define FPDFSDK_INCLUDE_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
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012class CJS_PublicMethods : public CJS_Object
13{
14public:
15 CJS_PublicMethods(JSFXObject pObject) : CJS_Object(pObject) {};
16 virtual ~CJS_PublicMethods(void){};
17
18public:
Tom Sepez2f3dfef2015-03-02 15:35:26 -080019 static FX_BOOL AFNumber_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
20 static FX_BOOL AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
21 static FX_BOOL AFPercent_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
22 static FX_BOOL AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
23 static FX_BOOL AFDate_FormatEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
24 static FX_BOOL AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
25 static FX_BOOL AFDate_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
26 static FX_BOOL AFDate_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
27 static FX_BOOL AFTime_FormatEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError); //
28 static FX_BOOL AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
29 static FX_BOOL AFTime_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
30 static FX_BOOL AFTime_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
31 static FX_BOOL AFSpecial_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
32 static FX_BOOL AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
33 static FX_BOOL AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);//
34 static FX_BOOL AFSimple(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
35 static FX_BOOL AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
36 static FX_BOOL AFSimple_Calculate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
37 static FX_BOOL AFRange_Validate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070038 static FX_BOOL AFMergeChange(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
Tom Sepez2f3dfef2015-03-02 15:35:26 -080039 static FX_BOOL AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
40 static FX_BOOL AFExtractNums(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041
42public:
43 JS_STATIC_GLOBAL_FUN(AFNumber_Format);
44 JS_STATIC_GLOBAL_FUN(AFNumber_Keystroke);
45 JS_STATIC_GLOBAL_FUN(AFPercent_Format);
46 JS_STATIC_GLOBAL_FUN(AFPercent_Keystroke);
47 JS_STATIC_GLOBAL_FUN(AFDate_FormatEx);
48 JS_STATIC_GLOBAL_FUN(AFDate_KeystrokeEx);
49 JS_STATIC_GLOBAL_FUN(AFDate_Format);
50 JS_STATIC_GLOBAL_FUN(AFDate_Keystroke);
51 JS_STATIC_GLOBAL_FUN(AFTime_FormatEx);
52 JS_STATIC_GLOBAL_FUN(AFTime_KeystrokeEx);
53 JS_STATIC_GLOBAL_FUN(AFTime_Format);
54 JS_STATIC_GLOBAL_FUN(AFTime_Keystroke);
55 JS_STATIC_GLOBAL_FUN(AFSpecial_Format);
56 JS_STATIC_GLOBAL_FUN(AFSpecial_Keystroke);
57 JS_STATIC_GLOBAL_FUN(AFSpecial_KeystrokeEx);
58 JS_STATIC_GLOBAL_FUN(AFSimple);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070059 JS_STATIC_GLOBAL_FUN(AFMakeNumber);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060 JS_STATIC_GLOBAL_FUN(AFSimple_Calculate);
61 JS_STATIC_GLOBAL_FUN(AFRange_Validate);
62 JS_STATIC_GLOBAL_FUN(AFMergeChange);
63 JS_STATIC_GLOBAL_FUN(AFParseDateEx);
64 JS_STATIC_GLOBAL_FUN(AFExtractNums);
65
66 JS_STATIC_DECLARE_GLOBAL_FUN();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070067
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068public:
69 static int ParseStringInteger(const CFX_WideString & string,int nStart,int & nSkip, int nMaxStep);
70 static CFX_WideString ParseStringString(const CFX_WideString& string, int nStart, int& nSkip);
71 static double MakeRegularDate(const CFX_WideString & value,const CFX_WideString & format, FX_BOOL& bWrongFormat);
72 static CFX_WideString MakeFormatDate(double dDate,const CFX_WideString & format);
Tom Sepezd7e5cc72015-06-10 14:33:37 -070073 static FX_BOOL ConvertStringToNumber(const FX_WCHAR* swSource, double & dRet, FX_BOOL & bDot);
74 static double ParseStringToNumber(const FX_WCHAR* swSource);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075 static double ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat);
76 static double MakeInterDate(CFX_WideString strValue);
Tom Sepezd7e5cc72015-06-10 14:33:37 -070077 static double ParseNumber(const FX_WCHAR* swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
79public:
Tom Sepezd7e5cc72015-06-10 14:33:37 -070080 static CFX_WideString StrLTrim(const FX_WCHAR* pStr);
81 static CFX_WideString StrRTrim(const FX_WCHAR* pStr);
82 static CFX_WideString StrTrim(const FX_WCHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070083
Tom Sepezd7e5cc72015-06-10 14:33:37 -070084 static CFX_ByteString StrLTrim(const FX_CHAR* pStr);
85 static CFX_ByteString StrRTrim(const FX_CHAR* pStr);
86 static CFX_ByteString StrTrim(const FX_CHAR* pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
Tom Sepezd7e5cc72015-06-10 14:33:37 -070088 static FX_BOOL IsNumber(const FX_CHAR* string);
89 static FX_BOOL IsNumber(const FX_WCHAR* string);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
91 static FX_BOOL IsDigit(char ch);
92 static FX_BOOL IsDigit(wchar_t ch);
93 static FX_BOOL IsAlphabetic(wchar_t ch);
94 static FX_BOOL IsAlphaNumeric(wchar_t ch);
95
96 static FX_BOOL maskSatisfied(wchar_t c_Change,wchar_t c_Mask);
97 static FX_BOOL isReservedMaskChar(wchar_t ch);
98
Tom Sepezd7e5cc72015-06-10 14:33:37 -070099 static double AF_Simple(const FX_WCHAR* sFuction, double dValue1, double dValue2);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100 static CJS_Array AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val);
101};
102
Tom Sepez19922bb2015-05-28 13:23:12 -0700103#endif // FPDFSDK_INCLUDE_JAVASCRIPT_PUBLICMETHODS_H_