blob: c5cc84cc2311c56ddd33f9ef4aa69854630ea166 [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
7#include "../../include/javascript/JavaScript.h"
8#include "../../include/javascript/IJavaScript.h"
9#include "../../include/javascript/JS_Define.h"
10#include "../../include/javascript/JS_Object.h"
11#include "../../include/javascript/JS_Value.h"
12#include "../../include/javascript/PublicMethods.h"
13#include "../../include/javascript/JS_EventHandler.h"
14#include "../../include/javascript/resource.h"
15#include "../../include/javascript/JS_Context.h"
16#include "../../include/javascript/JS_Value.h"
17#include "../../include/javascript/util.h"
18#include "../../include/javascript/Field.h"
19#include "../../include/javascript/color.h"
20#include "../../include/javascript/JS_Runtime.h"
21
22static v8::Isolate* GetIsolate(IFXJS_Context* cc)
23{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070024 CJS_Context* pContext = (CJS_Context *)cc;
25 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026
Tom Sepez2f2ffec2015-07-23 14:42:09 -070027 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
28 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029
Tom Sepez2f2ffec2015-07-23 14:42:09 -070030 return pRuntime->GetIsolate();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031}
32
33
34/* -------------------------------- CJS_PublicMethods -------------------------------- */
35
Tom Sepez2f2ffec2015-07-23 14:42:09 -070036#define DOUBLE_CORRECT 0.000000000000001
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037
38BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070039 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format)
40 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke)
41 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format)
42 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke)
43 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx)
44 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx)
45 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format)
46 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke)
47 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx)
48 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx)
49 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format)
50 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke)
51 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format)
52 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke)
53 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx)
54 JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple)
55 JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber)
56 JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate)
57 JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate)
58 JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange)
59 JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx)
60 JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061END_JS_STATIC_GLOBAL_FUN()
62
63IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
64
Tom Sepezd7e5cc72015-06-10 14:33:37 -070065static const FX_WCHAR* months[] =
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070067 L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068};
69
Tom Sepezd7e5cc72015-06-10 14:33:37 -070070static const FX_WCHAR* const fullmonths[] =
71{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070072 L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"August", L"September", L"October", L"November", L"December"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073};
74
Tom Sepezd7e5cc72015-06-10 14:33:37 -070075FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070077 CFX_WideString sTrim = StrTrim(string);
78 const FX_WCHAR* pTrim = sTrim.c_str();
79 const FX_WCHAR* p = pTrim;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080
81
Tom Sepez2f2ffec2015-07-23 14:42:09 -070082 FX_BOOL bDot = FALSE;
83 FX_BOOL bKXJS = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084
Tom Sepez2f2ffec2015-07-23 14:42:09 -070085 wchar_t c;
86 while ((c = *p))
87 {
88 if (c == '.' || c == ',')
89 {
90 if (bDot) return FALSE;
91 bDot = TRUE;
92 }
93 else if (c == '-' || c == '+')
94 {
95 if (p != pTrim)
96 return FALSE;
97 }
98 else if (c == 'e' || c == 'E')
99 {
100 if (bKXJS)
101 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700103 p++;
104 c = *p;
105 if (c == '+' || c == '-')
106 {
107 bKXJS = TRUE;
108 }
109 else
110 {
111 return FALSE;
112 }
113 }
114 else if (!IsDigit(c))
115 {
116 return FALSE;
117 }
118 p++;
119 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700121 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122}
123
124FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch)
125{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700126 return (ch >= L'0' && ch <= L'9');
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127}
128
129FX_BOOL CJS_PublicMethods::IsDigit(char ch)
130{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700131 return (ch >= '0' && ch <= '9');
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
134FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch)
135{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700136 return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
139FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch)
140{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700141 return (IsDigit(ch) || IsAlphabetic(ch));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142}
143
144FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
145{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700146 switch (c_Mask)
147 {
148 case L'9':
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700149 return IsDigit(c_Change);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150 case L'A':
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700151 return IsAlphabetic(c_Change);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152 case L'O':
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700153 return IsAlphaNumeric(c_Change);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154 case L'X':
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700155 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700156 default:
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700157 return (c_Change == c_Mask);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700158 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159}
160
161FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch)
162{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700163 return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164}
165
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700166double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, double dValue1, double dValue2)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700167{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700168 if (FXSYS_wcsicmp(sFuction,L"AVG") == 0 || FXSYS_wcsicmp(sFuction,L"SUM") == 0)
169 {
170 return dValue1 + dValue2;
171 }
172 if (FXSYS_wcsicmp(sFuction, L"PRD") == 0)
173 {
174 return dValue1 * dValue2;
175 }
176 if (FXSYS_wcsicmp(sFuction,L"MIN") == 0)
177 {
178 return FX_MIN(dValue1, dValue2);
179 }
180 if (FXSYS_wcsicmp(sFuction,L"MAX") == 0)
181 {
182 return FX_MAX(dValue1, dValue2);
183 }
184 return dValue1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185}
186
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700187CFX_WideString CJS_PublicMethods::StrLTrim(const FX_WCHAR* pStr)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700189 while (*pStr && *pStr == L' ') pStr++;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700191 return pStr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192}
193
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700194CFX_WideString CJS_PublicMethods::StrRTrim(const FX_WCHAR* pStr)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700195{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700196 const FX_WCHAR* p = pStr;
197 while (*p) p++;
198 while (p > pStr && *(p - 1) == L' ') p--;
Tom Sepez46773fd2014-07-23 10:50:06 -0700199
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700200 return CFX_WideString(pStr, p - pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201}
202
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700203CFX_WideString CJS_PublicMethods::StrTrim(const FX_WCHAR* pStr)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700205 return StrRTrim(StrLTrim(pStr).c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700206}
207
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700208CFX_ByteString CJS_PublicMethods::StrLTrim(const FX_CHAR* pStr)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700210 while (*pStr && *pStr == ' ') pStr++;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
Tom Sepez46773fd2014-07-23 10:50:06 -0700212 return pStr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700213}
214
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700215CFX_ByteString CJS_PublicMethods::StrRTrim(const FX_CHAR* pStr)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700217 const FX_CHAR* p = pStr;
218 while (*p) p++;
219 while (p > pStr && *(p - 1) == L' ') p--;
Tom Sepez46773fd2014-07-23 10:50:06 -0700220
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700221 return CFX_ByteString(pStr,p-pStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700222}
223
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700224CFX_ByteString CJS_PublicMethods::StrTrim(const FX_CHAR* pStr)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700226 return StrRTrim(StrLTrim(pStr));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227}
228
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700229double CJS_PublicMethods::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 -0700230{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700231 bDot = FALSE;
232 bSign = FALSE;
233 bKXJS = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700235 FX_BOOL bDigitExist = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700237 const FX_WCHAR* p = swSource;
238 wchar_t c;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700240 const FX_WCHAR* pStart = NULL;
241 const FX_WCHAR* pEnd = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700243 while ((c = *p))
244 {
245 if (!pStart && c != L' ')
246 {
247 pStart = p;
248 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700250 pEnd = p;
251 p++;
252 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700254 if (!pStart)
255 {
256 bAllDigits = FALSE;
257 return 0;
258 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700259
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700260 while (pEnd != pStart)
261 {
262 if (*pEnd == L' ')
263 pEnd --;
264 else
265 break;
266 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700267
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700268 double dRet = 0;
269 p = pStart;
270 bAllDigits = TRUE;
271 CFX_WideString swDigits;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700272
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700273 while (p <= pEnd)
274 {
275 c = *p;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700277 if (IsDigit(c))
278 {
279 swDigits += c;
280 bDigitExist = TRUE;
281 }
282 else
283 {
284 switch (c)
285 {
286 case L' ':
287 bAllDigits = FALSE;
288 break;
289 case L'.':
290 case L',':
291 if (!bDot)
292 {
293 if (bDigitExist)
294 {
295 swDigits += L'.';
296 }
297 else
298 {
299 swDigits += L'0';
300 swDigits += L'.';
301 bDigitExist = TRUE;
302 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700303
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700304 bDot = TRUE;
305 break;
306 }
307 case 'e':
308 case 'E':
309 if (!bKXJS)
310 {
311 p++;
312 c = *p;
313 if (c == '+' || c == '-')
314 {
315 bKXJS = TRUE;
316 swDigits += 'e';
317 swDigits += c;
318 }
319 break;
320 }
321 case L'-':
322 if (!bDigitExist && !bSign)
323 {
324 swDigits += c;
325 bSign = TRUE;
326 break;
327 }
328 default:
329 bAllDigits = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700330
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700331 if (p != pStart && !bDot && bDigitExist)
332 {
333 swDigits += L'.';
334 bDot = TRUE;
335 }
336 else
337 {
338 bDot = FALSE;
339 bDigitExist = FALSE;
340 swDigits = L"";
341 }
342 break;
343 }
344 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700345
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700346 p++;
347 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700348
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700349 if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
350 {
351 CFX_ByteString sDigits = swDigits.UTF8Encode();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700352
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700353 if (bKXJS)
354 {
355 dRet = atof(sDigits);
356 }
357 else
358 {
359 if (bDot)
360 {
361 char* pStopString;
362 dRet = ::strtod(sDigits, &pStopString);
363 }
364 else
365 {
366 dRet = atol(sDigits);
367 }
368 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700370 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700372 return dRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373}
374
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700375double CJS_PublicMethods::ParseStringToNumber(const FX_WCHAR* swSource)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700376{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700377 FX_BOOL bAllDigits = FALSE;
378 FX_BOOL bDot = FALSE;
379 FX_BOOL bSign = FALSE;
380 FX_BOOL bKXJS = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700381
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700382 return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383}
384
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700385FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource, double & dRet, FX_BOOL & bDot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700386{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700387 FX_BOOL bAllDigits = FALSE;
388 FX_BOOL bSign = FALSE;
389 FX_BOOL bKXJS = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700391 dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700393 return bAllDigits;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700394}
395
396CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val)
397{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700398 CJS_Array StrArray(isolate);
399 if(val.IsArrayObject())
400 {
401 val.ConvertToArray(StrArray);
402 return StrArray;
403 }
404 CFX_WideString wsStr = val.ToCFXWideString();
405 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
406 const char * p = (const char *)t;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700407
408
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700409 int ch = ',' ;
410 int nIndex = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700411
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700412 while (*p)
413 {
414 const char * pTemp = strchr(p, ch);
415 if (pTemp == NULL)
416 {
417 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str()));
418 break;
419 }
420 else
421 {
422 char * pSub = new char[pTemp - p + 1];
423 strncpy(pSub, p, pTemp - p);
424 *(pSub + (pTemp - p)) = '\0';
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700425
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700426 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str()));
427 delete []pSub;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700428
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700429 nIndex ++;
430 p = ++pTemp;
431 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700432
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700433 }
434 return StrArray;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700435}
436
437int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStart,int& nSkip, int nMaxStep)
438{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700439 int nRet = 0;
440 nSkip = 0;
441 for (int i=nStart, sz=string.GetLength(); i < sz; i++)
442 {
443 if (i-nStart > 10)
444 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700445
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700446 FX_WCHAR c = string.GetAt(i);
447 if (IsDigit((wchar_t)c))
448 {
449 nRet = nRet * 10 + (c - '0');
450 nSkip = i - nStart + 1;
451 if (nSkip >= nMaxStep)
452 break;
453 }
454 else
455 break;
456 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700457
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700458 return nRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700459}
460
461CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string, int nStart, int& nSkip)
462{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700463 CFX_WideString swRet;
464 nSkip = 0;
465 for (int i=nStart, sz=string.GetLength(); i < sz; i++)
466 {
467 FX_WCHAR c = string.GetAt(i);
468 if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
469 {
470 swRet += c;
471 nSkip = i - nStart + 1;
472 }
473 else
474 break;
475 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700476
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700477 return swRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478}
479
480double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat)
481{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700482 double dt = JS_GetDateTime();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700483
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700484 int nYear = JS_GetYearFromTime(dt);
485 int nMonth = JS_GetMonthFromTime(dt) + 1;
486 int nDay = JS_GetDayFromTime(dt);
487 int nHour = JS_GetHourFromTime(dt);
488 int nMin = JS_GetMinFromTime(dt);
489 int nSec = JS_GetSecFromTime(dt);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700491 int number[3];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700492
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700493 int nSkip = 0;
494 int nLen = value.GetLength();
495 int nIndex = 0;
496 int i = 0;
497 while (i < nLen)
498 {
499 if (nIndex > 2) break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700500
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700501 FX_WCHAR c = value.GetAt(i);
502 if (IsDigit((wchar_t)c))
503 {
504 number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
505 i += nSkip;
506 }
507 else
508 {
509 i ++;
510 }
511 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700512
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700513 if (nIndex == 2)
514 {
515 // case2: month/day
516 // case3: day/month
517 if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
518 {
519 nMonth = number[0];
520 nDay = number[1];
521 }
522 else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12))
523 {
524 nDay = number[0];
525 nMonth = number[1];
526 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700527
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700528 bWrongFormat = FALSE;
529 }
530 else if (nIndex == 3)
531 {
532 // case1: year/month/day
533 // case2: month/day/year
534 // case3: day/month/year
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700535
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700536 if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
537 {
538 nYear = number[0];
539 nMonth = number[1];
540 nDay = number[2];
541 }
542 else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31)
543 {
544 nMonth = number[0];
545 nDay = number[1];
546 nYear = number[2];
547 }
548 else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31)
549 {
550 nDay = number[0];
551 nMonth = number[1];
552 nYear = number[2];
553 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700555 bWrongFormat = FALSE;
556 }
557 else
558 {
559 bWrongFormat = TRUE;
560 return dt;
561 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700563 CFX_WideString swTemp;
564 swTemp.Format(L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
565 return JS_DateParse(swTemp.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700566}
567
568double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CFX_WideString & format, FX_BOOL& bWrongFormat)
569{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700570 double dt = JS_GetDateTime();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700572 if (format.IsEmpty() || value.IsEmpty())
573 return dt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700574
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700575 int nYear = JS_GetYearFromTime(dt);
576 int nMonth = JS_GetMonthFromTime(dt) + 1;
577 int nDay = JS_GetDayFromTime(dt);
578 int nHour = JS_GetHourFromTime(dt);
579 int nMin = JS_GetMinFromTime(dt);
580 int nSec = JS_GetSecFromTime(dt);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700581
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700582 int nYearSub = 99; //nYear - 2000;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700584 FX_BOOL bPm = FALSE;
585 FX_BOOL bExit = FALSE;
586 bWrongFormat = FALSE;
Tom Sepez5ffacd62014-07-18 14:42:12 -0700587
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700588 int i=0;
589 int j=0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700591 while (i < format.GetLength())
592 {
593 if (bExit) break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700594
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700595 FX_WCHAR c = format.GetAt(i);
596 switch (c)
597 {
598 case ':':
599 case '.':
600 case '-':
601 case '\\':
602 case '/':
603 i++;
604 j++;
605 break;
Tom Sepez5ffacd62014-07-18 14:42:12 -0700606
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700607 case 'y':
608 case 'm':
609 case 'd':
610 case 'H':
611 case 'h':
612 case 'M':
613 case 's':
614 case 't':
615 {
616 int oldj = j;
617 int nSkip = 0;
618 int remaining = format.GetLength() - i - 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700620 if (remaining == 0 || format.GetAt(i+1) != c)
621 {
622 switch (c)
623 {
624 case 'y':
625 i++;
626 j++;
627 break;
628 case 'm':
629 nMonth = ParseStringInteger(value, j, nSkip, 2);
630 i++;
631 j += nSkip;
632 break;
633 case 'd':
634 nDay = ParseStringInteger(value, j, nSkip, 2);
635 i++;
636 j += nSkip;
637 break;
638 case 'H':
639 nHour = ParseStringInteger(value, j, nSkip, 2);
640 i++;
641 j += nSkip;
642 break;
643 case 'h':
644 nHour = ParseStringInteger(value, j, nSkip, 2);
645 i++;
646 j += nSkip;
647 break;
648 case 'M':
649 nMin = ParseStringInteger(value, j, nSkip, 2);
650 i++;
651 j += nSkip;
652 break;
653 case 's':
654 nSec = ParseStringInteger(value, j, nSkip, 2);
655 i++;
656 j += nSkip;
657 break;
658 case 't':
659 bPm = (j < value.GetLength() && value.GetAt(j) == 'p');
660 i++;
661 j++;
662 break;
663 }
664 }
665 else if (remaining == 1 || format.GetAt(i+2) != c)
666 {
667 switch (c)
668 {
669 case 'y':
670 nYear = ParseStringInteger(value, j, nSkip, 4);
671 i += 2;
672 j += nSkip;
673 break;
674 case 'm':
675 nMonth = ParseStringInteger(value, j, nSkip, 2);
676 i += 2;
677 j += nSkip;
678 break;
679 case 'd':
680 nDay = ParseStringInteger(value, j, nSkip, 2);
681 i += 2;
682 j += nSkip;
683 break;
684 case 'H':
685 nHour = ParseStringInteger(value, j, nSkip, 2);
686 i += 2;
687 j += nSkip;
688 break;
689 case 'h':
690 nHour = ParseStringInteger(value, j, nSkip, 2);
691 i += 2;
692 j += nSkip;
693 break;
694 case 'M':
695 nMin = ParseStringInteger(value, j, nSkip, 2);
696 i += 2;
697 j += nSkip;
698 break;
699 case 's':
700 nSec = ParseStringInteger(value, j, nSkip, 2);
701 i += 2;
702 j += nSkip;
703 break;
704 case 't':
705 bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
706 i += 2;
707 j += 2;
708 break;
709 }
710 }
711 else if (remaining == 2 || format.GetAt(i+3) != c)
712 {
713 switch (c)
714 {
715 case 'm':
716 {
717 CFX_WideString sMonth = ParseStringString(value, j, nSkip);
718 FX_BOOL bFind = FALSE;
719 for (int m = 0; m < 12; m++)
720 {
721 if (sMonth.CompareNoCase(months[m]) == 0)
722 {
723 nMonth = m + 1;
724 i+=3;
725 j+=nSkip;
726 bFind = TRUE;
727 break;
728 }
729 }
Tom Sepez5ffacd62014-07-18 14:42:12 -0700730
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700731 if (!bFind)
732 {
733 nMonth = ParseStringInteger(value, j, nSkip, 3);
734 i+=3;
735 j += nSkip;
736 }
737 }
738 break;
739 case 'y':
740 break;
741 default:
742 i+=3;
743 j+=3;
744 break;
745 }
746 }
747 else if (remaining == 3 || format.GetAt(i+4) != c)
748 {
749 switch (c)
750 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751
752
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700753 case 'y':
754 nYear = ParseStringInteger(value, j, nSkip, 4);
755 j += nSkip;
756 i += 4;
757 break;
758 case 'm':
759 {
760 FX_BOOL bFind = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700761
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700762 CFX_WideString sMonth = ParseStringString(value, j, nSkip);
763 sMonth.MakeLower();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700765 for (int m = 0; m < 12; m++)
766 {
767 CFX_WideString sFullMonths = fullmonths[m];
768 sFullMonths.MakeLower();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700770 if (sFullMonths.Find(sMonth.c_str(), 0) != -1)
771 {
772 nMonth = m + 1;
773 i += 4;
774 j += nSkip;
775 bFind = TRUE;
776 break;
777 }
778 }
Tom Sepez5ffacd62014-07-18 14:42:12 -0700779
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700780 if (!bFind)
781 {
782 nMonth = ParseStringInteger(value, j, nSkip, 4);
783 i+=4;
784 j += nSkip;
785 }
786 }
787 break;
788 default:
789 i += 4;
790 j += 4;
791 break;
792 }
793 }
794 else
795 {
796 if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j))
797 {
798 bWrongFormat = TRUE;
799 bExit = TRUE;
800 }
801 i++;
802 j++;
803 }
Tom Sepez5ffacd62014-07-18 14:42:12 -0700804
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700805 if (oldj == j)
806 {
807 bWrongFormat = TRUE;
808 bExit = TRUE;
809 }
810 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700812 break;
813 default:
814 if (value.GetLength() <= j)
815 {
816 bExit = TRUE;
817 }
818 else if (format.GetAt(i) != value.GetAt(j))
819 {
820 bWrongFormat = TRUE;
821 bExit = TRUE;
822 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700824 i++;
825 j++;
826 break;
827 }
828 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700830 if (bPm) nHour += 12;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700832 if (nYear >= 0 && nYear <= nYearSub)
833 nYear += 2000;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700835 if (nMonth < 1 || nMonth > 12)
836 bWrongFormat = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700837
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700838 if (nDay < 1 || nDay > 31)
839 bWrongFormat = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700840
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700841 if (nHour < 0 || nHour > 24)
842 bWrongFormat = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700844 if (nMin < 0 || nMin > 60)
845 bWrongFormat = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700846
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700847 if (nSec < 0 || nSec > 60)
848 bWrongFormat = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700849
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700850 double dRet = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700851
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700852 if (bWrongFormat)
853 {
854 dRet = ParseNormalDate(value, bWrongFormat);
855 }
856 else
857 {
858 dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700859
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700860 if (JS_PortIsNan(dRet))
861 {
862 dRet = JS_DateParse(value.c_str());
863 }
864 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700865
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700866 if (JS_PortIsNan(dRet))
867 {
868 dRet = ParseNormalDate(value, bWrongFormat);
869 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700870
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700871 return dRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700872
873}
874
875CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideString & format)
876{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700877 CFX_WideString sRet = L"",sPart = L"";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700879 int nYear = JS_GetYearFromTime(dDate);
880 int nMonth = JS_GetMonthFromTime(dDate) + 1;
881 int nDay = JS_GetDayFromTime(dDate);
882 int nHour = JS_GetHourFromTime(dDate);
883 int nMin = JS_GetMinFromTime(dDate);
884 int nSec = JS_GetSecFromTime(dDate);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700886 int i = 0;
887 while (i < format.GetLength())
888 {
889 FX_WCHAR c = format.GetAt(i);
Tom Sepez85386422014-07-23 10:28:37 -0700890 int remaining = format.GetLength() - i - 1;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700891 sPart = L"";
892 switch (c)
893 {
894 case 'y':
895 case 'm':
896 case 'd':
897 case 'H':
898 case 'h':
899 case 'M':
900 case 's':
901 case 't':
902 if (remaining == 0 || format.GetAt(i+1) != c)
903 {
904 switch (c)
905 {
906 case 'y':
907 sPart += c;
908 break;
909 case 'm':
910 sPart.Format(L"%d",nMonth);
911 break;
912 case 'd':
913 sPart.Format(L"%d",nDay);
914 break;
915 case 'H':
916 sPart.Format(L"%d",nHour);
917 break;
918 case 'h':
919 sPart.Format(L"%d",nHour>12?nHour - 12:nHour);
920 break;
921 case 'M':
922 sPart.Format(L"%d",nMin);
923 break;
924 case 's':
925 sPart.Format(L"%d",nSec);
926 break;
927 case 't':
928 sPart += nHour>12?'p':'a';
929 break;
930 }
931 i++;
932 }
933 else if (remaining == 1 || format.GetAt(i+2) != c)
934 {
935 switch (c)
936 {
937 case 'y':
938 sPart.Format(L"%02d",nYear - (nYear / 100) * 100);
939 break;
940 case 'm':
941 sPart.Format(L"%02d",nMonth);
942 break;
943 case 'd':
944 sPart.Format(L"%02d",nDay);
945 break;
946 case 'H':
947 sPart.Format(L"%02d",nHour);
948 break;
949 case 'h':
950 sPart.Format(L"%02d",nHour>12?nHour - 12:nHour);
951 break;
952 case 'M':
953 sPart.Format(L"%02d",nMin);
954 break;
955 case 's':
956 sPart.Format(L"%02d",nSec);
957 break;
958 case 't':
959 sPart = nHour>12? L"pm": L"am";
960 break;
961 }
962 i+=2;
963 }
964 else if (remaining == 2 || format.GetAt(i+3) != c)
965 {
966 switch (c)
967 {
968 case 'm':
969 i+=3;
970 if (nMonth > 0&&nMonth <= 12)
971 sPart += months[nMonth - 1];
972 break;
973 default:
974 i+=3;
975 sPart += c;
976 sPart += c;
977 sPart += c;
978 break;
979 }
980 }
981 else if (remaining == 3 || format.GetAt(i+4) != c)
982 {
983 switch (c)
984 {
985 case 'y':
986 sPart.Format(L"%04d",nYear);
987 i += 4;
988 break;
989 case 'm':
990 i+=4;
991 if (nMonth > 0&&nMonth <= 12)
992 sPart += fullmonths[nMonth - 1];
993 break;
994 default:
995 i += 4;
996 sPart += c;
997 sPart += c;
998 sPart += c;
999 sPart += c;
1000 break;
1001 }
1002 }
1003 else
1004 {
1005 i++;
1006 sPart += c;
1007 }
1008 break;
1009 default:
1010 i++;
1011 sPart += c;
1012 break;
1013 }
Tom Sepez85386422014-07-23 10:28:37 -07001014
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001015 sRet += sPart;
1016 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001017
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001018 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001019}
1020
1021/* -------------------------------------------------------------------------- */
1022
1023//function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001024FX_BOOL CJS_PublicMethods::AFNumber_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001025{
1026#if _FX_OS_ != _FX_ANDROID_
1027 v8::Isolate* isolate = ::GetIsolate(cc);
1028 CJS_Context* pContext = (CJS_Context *)cc;
1029 ASSERT(pContext != NULL);
1030 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1031 ASSERT(pEvent != NULL);
1032
1033 if (params.size() != 6)
1034 {
1035 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1036 return FALSE;
1037 }
1038 if(!pEvent->m_pValue)
1039 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001040 CFX_WideString& Value = pEvent->Value();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001041 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001042
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001043 if (strValue.IsEmpty()) return TRUE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001044
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001045 int iDec = params[0].ToInt();
1046 int iSepStyle = params[1].ToInt();
1047 int iNegStyle = params[2].ToInt();
Nico Weber55681f92014-07-30 19:00:31 -07001048 // params[3] is iCurrStyle, it's not used.
Tom Sepez4f7bc042015-04-27 12:06:58 -07001049 std::wstring wstrCurrency(params[4].ToCFXWideString().c_str());
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001050 FX_BOOL bCurrencyPrepend = params[5].ToBool();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001051
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001052 if (iDec < 0) iDec = -iDec;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001053
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001054 if (iSepStyle < 0 || iSepStyle > 3)
1055 iSepStyle = 0;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001056
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001057 if (iNegStyle < 0 || iNegStyle > 3)
1058 iNegStyle = 0;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001059
1060
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001061 //////////////////////////////////////////////////////
1062 //for processing decimal places
1063 strValue.Replace(",", ".");
1064 double dValue = atof(strValue);
1065 if (iDec > 0)
1066 dValue += DOUBLE_CORRECT;//
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001067
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001068 int iDec2;
1069 FX_BOOL bNagative = FALSE;
1070
1071 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1072 if (strValue.IsEmpty())
1073 {
1074 dValue = 0;
1075 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1076 if (strValue.IsEmpty())
1077 {
1078 strValue = "0";
1079 iDec2 = 1;
1080 }
1081
1082 }
1083
1084 if (iDec2 < 0)
1085 {
1086 for (int iNum = 0;iNum < abs(iDec2);iNum++)
1087 {
1088 strValue = "0" + strValue;
1089 }
1090 iDec2 = 0;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001091
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001092 }
1093 int iMax = strValue.GetLength();
1094 if (iDec2 > iMax)
1095 {
1096 for (int iNum = 0;iNum <= iDec2 - iMax ;iNum++)
1097 {
1098 strValue += "0";
1099 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001100 iMax = iDec2+1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001101 }
1102 ///////////////////////////////////////////////////////
1103 //for processing seperator style
1104 if (iDec2 < iMax)
1105 {
1106 if (iSepStyle == 0 || iSepStyle == 1)
1107 {
1108 strValue.Insert(iDec2, '.');
1109 iMax++;
1110 }
1111 else if (iSepStyle == 2 || iSepStyle == 3)
1112 {
1113 strValue.Insert(iDec2, ',');
1114 iMax++;
1115 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001116
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001117 if (iDec2 == 0)
1118 strValue.Insert(iDec2, '0');
1119 }
1120 if (iSepStyle == 0 || iSepStyle == 2)
1121 {
1122 char cSeperator;
1123 if (iSepStyle == 0)
1124 cSeperator = ',';
1125 else
1126 cSeperator = '.';
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001127
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001128 int iDecPositive,iDecNagative;
1129 iDecPositive = iDec2;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001130 iDecNagative = iDec2;
1131
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001132 for (iDecPositive = iDec2 -3; iDecPositive > 0;iDecPositive -= 3)
1133 {
1134 strValue.Insert(iDecPositive, cSeperator);
1135 iMax++;
1136 }
1137 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001138
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001139 //////////////////////////////////////////////////////////////////////
1140 //for processing currency string
1141
1142 Value = CFX_WideString::FromLocal(strValue);
Tom Sepez4f7bc042015-04-27 12:06:58 -07001143 std::wstring strValue2 = Value.c_str();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001144
1145 if (bCurrencyPrepend)
1146 strValue2 = wstrCurrency + strValue2;
1147 else
1148 strValue2 = strValue2 + wstrCurrency;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001149
1150
1151
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001152 /////////////////////////////////////////////////////////////////////////
1153 //for processing negative style
1154 if (bNagative)
1155 {
1156 if (iNegStyle == 0)
1157 {
1158 strValue2.insert(0,L"-");
1159 }
1160 if (iNegStyle == 2 || iNegStyle == 3)
1161 {
1162 strValue2.insert(0,L"(");
1163 strValue2.insert(strValue2.length(),L")");
1164 }
1165 if (iNegStyle == 1 || iNegStyle == 3)
1166 {
1167 if (Field * fTarget = pEvent->Target_Field())
1168 {
1169 CJS_Array arColor(isolate);
1170 CJS_Value vColElm(isolate);
1171 vColElm = L"RGB";
1172 arColor.SetElement(0,vColElm);
1173 vColElm = 1;
1174 arColor.SetElement(1,vColElm);
1175 vColElm = 0;
1176 arColor.SetElement(2,vColElm);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001177
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001178 arColor.SetElement(3,vColElm);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001179
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001180 CJS_PropValue vProp(isolate);
1181 vProp.StartGetting();
1182 vProp<<arColor;
1183 vProp.StartSetting();
1184 fTarget->textColor(cc,vProp,sError);// red
1185 }
1186 }
1187 }
1188 else
1189 {
1190 if (iNegStyle == 1 || iNegStyle == 3)
1191 {
1192 if (Field *fTarget = pEvent->Target_Field())
1193 {
1194 CJS_Array arColor(isolate);
1195 CJS_Value vColElm(isolate);
1196 vColElm = L"RGB";
1197 arColor.SetElement(0,vColElm);
1198 vColElm = 0;
1199 arColor.SetElement(1,vColElm);
1200 arColor.SetElement(2,vColElm);
1201 arColor.SetElement(3,vColElm);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001202
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001203 CJS_PropValue vProp(isolate);
1204 vProp.StartGetting();
1205 fTarget->textColor(cc,vProp,sError);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001206
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001207 CJS_Array aProp(isolate);
1208 vProp.ConvertToArray(aProp);
1209
1210 CPWL_Color crProp;
1211 CPWL_Color crColor;
1212 color::ConvertArrayToPWLColor(aProp, crProp);
1213 color::ConvertArrayToPWLColor(arColor, crColor);
1214
1215 if (crColor != crProp)
1216 {
1217 CJS_PropValue vProp2(isolate);
1218 vProp2.StartGetting();
1219 vProp2<<arColor;
1220 vProp2.StartSetting();
1221 fTarget->textColor(cc,vProp2,sError);
1222 }
1223 }
1224 }
1225 }
1226 Value = strValue2.c_str();
1227#endif
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001228 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001229}
1230
1231//function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001232FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001233{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001234 CJS_Context* pContext = (CJS_Context *)cc;
1235 ASSERT(pContext != NULL);
1236 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1237 ASSERT(pEvent != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001238
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001239 if(params.size() < 2)
1240 return FALSE;
1241 int iSepStyle = params[1].ToInt();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001242
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001243 if (iSepStyle < 0 || iSepStyle > 3)
1244 iSepStyle = 0;
1245 if(!pEvent->m_pValue)
1246 return FALSE;
1247 CFX_WideString & val = pEvent->Value();
1248 CFX_WideString & w_strChange = pEvent->Change();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001249 CFX_WideString w_strValue = val;
1250
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001251 if (pEvent->WillCommit())
1252 {
1253 CFX_WideString wstrChange = w_strChange;
1254 CFX_WideString wstrValue = StrLTrim(w_strValue.c_str());
1255 if (wstrValue.IsEmpty())
1256 return TRUE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001257
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001258 CFX_WideString swTemp = wstrValue;
1259 swTemp.Replace(L",", L".");
1260 if (!IsNumber(swTemp.c_str()))
1261 {
1262 pEvent->Rc() = FALSE;
1263 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
1264 Alert(pContext, sError.c_str());
1265 return TRUE;
1266 }
1267 return TRUE; // it happens after the last keystroke and before validating,
1268 }
Tom Sepez4f7bc042015-04-27 12:06:58 -07001269
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001270 std::wstring w_strValue2 = w_strValue.c_str();
1271 std::wstring w_strChange2 = w_strChange.c_str();
1272 std::wstring w_strSelected;
1273 if(-1 != pEvent->SelStart())
1274 w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
1275 FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
1276 if (bHasSign)
1277 {
1278 //can't insert "change" in front to sign postion.
1279 if (pEvent->SelStart() == 0)
1280 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001281 FX_BOOL &bRc = pEvent->Rc();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001282 bRc = FALSE;
1283 return TRUE;
1284 }
1285 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001286
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001287 char cSep = L'.';
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001288
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001289 switch (iSepStyle)
1290 {
1291 case 0:
1292 case 1:
1293 cSep = L'.';
1294 break;
1295 case 2:
1296 case 3:
1297 cSep = L',';
1298 break;
1299 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001300
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001301 FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
1302 for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.end(); it++)
1303 {
1304 if (*it == cSep)
1305 {
1306 if (bHasSep)
1307 {
1308 FX_BOOL &bRc = pEvent->Rc();
1309 bRc = FALSE;
1310 return TRUE;
1311 }
1312 bHasSep = TRUE;
1313 continue;
1314 }
1315 if (*it == L'-')
1316 {
1317 if (bHasSign)
1318 {
1319 FX_BOOL &bRc = pEvent->Rc();
1320 bRc = FALSE;
1321 return TRUE;
1322 }
1323 if (it != w_strChange2.begin()) //sign's position is not correct
1324 {
1325 FX_BOOL &bRc = pEvent->Rc();
1326 bRc = FALSE;
1327 return TRUE;
1328 }
1329 if (pEvent->SelStart() != 0)
1330 {
1331 FX_BOOL &bRc = pEvent->Rc();
1332 bRc = FALSE;
1333 return TRUE;
1334 }
1335 bHasSign = TRUE;
1336 continue;
1337 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001338
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001339 if (!IsDigit(*it))
1340 {
1341 FX_BOOL &bRc = pEvent->Rc();
1342 bRc = FALSE;
1343 return TRUE;
1344 }
1345 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001346
1347
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001348 std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
1349 std::wstring w_postfix;
1350 if (pEvent->SelEnd()<(int)w_strValue2.length())
1351 w_postfix = w_strValue2.substr(pEvent->SelEnd());
1352 w_strValue2 = w_prefix + w_strChange2 + w_postfix;
1353 w_strValue = w_strValue2.c_str();
1354 val = w_strValue;
1355 return TRUE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001356
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001357}
1358
1359//function AFPercent_Format(nDec, sepStyle)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001360FX_BOOL CJS_PublicMethods::AFPercent_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001361{
1362#if _FX_OS_ != _FX_ANDROID_
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001363 CJS_Context* pContext = (CJS_Context *)cc;
1364 ASSERT(pContext != NULL);
1365 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1366 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001367
1368 if (params.size() != 2)
1369 {
1370 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1371 return FALSE;
1372 }
1373 if(!pEvent->m_pValue)
1374 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001375
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001376 CFX_WideString& Value = pEvent->Value();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001377 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001378 if (strValue.IsEmpty())
1379 return TRUE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001380
1381 int iDec = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001382 if (iDec < 0)
1383 iDec = -iDec;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001384
1385 int iSepStyle = params[1].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001386 if (iSepStyle < 0 || iSepStyle > 3)
1387 iSepStyle = 0;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001388
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001389 //////////////////////////////////////////////////////
1390 //for processing decimal places
1391 double dValue = atof(strValue);
1392 dValue *= 100;
1393 if (iDec > 0)
1394 dValue += DOUBLE_CORRECT;//УÕý
1395
1396 int iDec2;
1397 FX_BOOL bNagative = FALSE;
1398 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1399 if (strValue.IsEmpty())
1400 {
1401 dValue = 0;
1402 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1403 }
1404
1405 if (iDec2 < 0)
1406 {
1407 for (int iNum = 0; iNum < abs(iDec2); iNum++)
1408 {
1409 strValue = "0" + strValue;
1410 }
1411 iDec2 = 0;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001412
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001413 }
1414 int iMax = strValue.GetLength();
1415 if (iDec2 > iMax)
1416 {
1417 for (int iNum = 0; iNum <= iDec2 - iMax; iNum++)
1418 {
1419 strValue += "0";
1420 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001421 iMax = iDec2+1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001422 }
1423 ///////////////////////////////////////////////////////
1424 //for processing seperator style
1425 if (iDec2 < iMax)
1426 {
1427 if (iSepStyle == 0 || iSepStyle == 1)
1428 {
1429 strValue.Insert(iDec2, '.');
1430 iMax++;
1431 }
1432 else if (iSepStyle == 2 || iSepStyle == 3)
1433 {
1434 strValue.Insert(iDec2, ',');
1435 iMax++;
1436 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001437
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001438 if (iDec2 == 0)
1439 strValue.Insert(iDec2, '0');
1440 }
1441 if (iSepStyle == 0 || iSepStyle == 2)
1442 {
1443 char cSeperator;
1444 if (iSepStyle == 0)
1445 cSeperator = ',';
1446 else
1447 cSeperator = '.';
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001448
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001449 int iDecPositive,iDecNagative;
1450 iDecPositive = iDec2;
1451 iDecNagative = iDec2;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001452
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001453 for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
1454 {
1455 strValue.Insert(iDecPositive,cSeperator);
1456 iMax++;
1457 }
1458 }
1459 ////////////////////////////////////////////////////////////////////
1460 //nagative mark
1461 if(bNagative)
1462 strValue = "-" + strValue;
1463 strValue += "%";
1464 Value = CFX_WideString::FromLocal(strValue);
1465#endif
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001466 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001467}
1468//AFPercent_Keystroke(nDec, sepStyle)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001469FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001470{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001471 return AFNumber_Keystroke(cc,params,vRet,sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001472}
1473
1474//function AFDate_FormatEx(cFormat)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001475FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001476{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001477 CJS_Context* pContext = (CJS_Context *)cc;
1478 ASSERT(pContext != NULL);
1479 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1480 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001481
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001482 if (params.size() != 1)
1483 {
1484 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1485 return FALSE;
1486 }
1487 if(!pEvent->m_pValue)
1488 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001489
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001490 CFX_WideString& val = pEvent->Value();
1491 CFX_WideString strValue = val;
1492 if (strValue.IsEmpty())
1493 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001494
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001495 CFX_WideString sFormat = params[0].ToCFXWideString();
1496 FX_BOOL bWrongFormat = FALSE;
1497 double dDate = 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001498
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001499 if(strValue.Find(L"GMT") != -1)
1500 {
1501 //for GMT format time
1502 //such as "Tue Aug 11 14:24:16 GMT+08002009"
1503 dDate = MakeInterDate(strValue);
1504 }
1505 else
1506 {
1507 dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
1508 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001509
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001510 if (JS_PortIsNan(dDate))
1511 {
1512 CFX_WideString swMsg;
1513 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
1514 Alert(pContext, swMsg.c_str());
1515 return FALSE;
1516 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001517
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001518 val = MakeFormatDate(dDate,sFormat);
1519 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001520}
1521
1522double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue)
1523{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001524 int nHour;
1525 int nMin;
1526 int nSec;
1527 int nYear;
1528 int nMonth;
1529 int nDay;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001530
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001531 CFX_WideStringArray wsArray;
1532 CFX_WideString sMonth = L"";
1533 CFX_WideString sTemp = L"";
1534 int nSize = strValue.GetLength();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001535
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001536 for(int i = 0; i < nSize; i++)
1537 {
1538 FX_WCHAR c = strValue.GetAt(i);
1539 if(c == L' ' || c == L':')
1540 {
1541 wsArray.Add(sTemp);
1542 sTemp = L"";
1543 continue;
1544 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001545
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001546 sTemp += c;
1547 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001548
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001549 wsArray.Add(sTemp);
1550 if(wsArray.GetSize() != 8)return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001551
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001552 sTemp = wsArray[1];
1553 if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
1554 if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
1555 if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
1556 if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
1557 if(sTemp.Compare(L"May") == 0) nMonth = 5;
1558 if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
1559 if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
1560 if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
1561 if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
1562 if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
1563 if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
1564 if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001565
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001566 nDay = (int)ParseStringToNumber(wsArray[2].c_str());
1567 nHour = (int)ParseStringToNumber(wsArray[3].c_str());
1568 nMin = (int)ParseStringToNumber(wsArray[4].c_str());
1569 nSec = (int)ParseStringToNumber(wsArray[5].c_str());
1570 nYear = (int)ParseStringToNumber(wsArray[7].c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001571
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001572 double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001573
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001574 if (JS_PortIsNan(dRet))
1575 {
1576 dRet = JS_DateParse(strValue.c_str());
1577 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001578
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001579 return dRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001580}
1581
1582//AFDate_KeystrokeEx(cFormat)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001583FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001584{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001585 CJS_Context* pContext = (CJS_Context *)cc;
1586 ASSERT(pContext != NULL);
1587 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1588 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001589
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001590 if (params.size() != 1)
1591 {
1592 sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
1593 return FALSE;
1594 }
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001595
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001596 if (pEvent->WillCommit())
1597 {
1598 if(!pEvent->m_pValue)
1599 return FALSE;
1600 CFX_WideString strValue = pEvent->Value();
1601 if (strValue.IsEmpty())
1602 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001603
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001604 CFX_WideString sFormat = params[0].ToCFXWideString();
1605 FX_BOOL bWrongFormat = FALSE;
1606 double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
1607 if (bWrongFormat || JS_PortIsNan(dRet))
1608 {
1609 CFX_WideString swMsg;
1610 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
1611 Alert(pContext, swMsg.c_str());
1612 pEvent->Rc() = FALSE;
1613 return TRUE;
1614 }
1615 }
1616 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001617}
1618
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001619FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001620{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001621 v8::Isolate* isolate = ::GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001622
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001623 if (params.size() != 1)
1624 {
1625 CJS_Context* pContext = (CJS_Context*)cc;
1626 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001627
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001628 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1629 return FALSE;
1630 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001631
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001632 int iIndex = params[0].ToInt();
1633 const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy",
1634 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
1635 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001636
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001637 ASSERT(iIndex < FX_ArraySize(cFormats));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001638
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001639 if (iIndex < 0)
1640 iIndex = 0;
1641 if (iIndex >= FX_ArraySize(cFormats))
1642 iIndex = 0;
1643 CJS_Parameters newParams;
1644 CJS_Value val(isolate,cFormats[iIndex]);
1645 newParams.push_back(val);
1646 return AFDate_FormatEx(cc,newParams,vRet,sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001647}
1648
1649//AFDate_KeystrokeEx(cFormat)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001650FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001651{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001652 v8::Isolate* isolate = ::GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001653
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001654 if (params.size() != 1)
1655 {
1656 CJS_Context* pContext = (CJS_Context*)cc;
1657 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001658
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001659 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1660 return FALSE;
1661 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001662
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001663 int iIndex = params[0].ToInt();
1664 const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy",
1665 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
1666 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001667
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001668 ASSERT(iIndex<FX_ArraySize(cFormats));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001669
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001670 if (iIndex < 0)
1671 iIndex = 0;
1672 if (iIndex >= FX_ArraySize(cFormats))
1673 iIndex = 0;
1674 CJS_Parameters newParams;
1675 CJS_Value val(isolate,cFormats[iIndex]);
1676 newParams.push_back(val);
1677 return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001678}
1679
1680//function AFTime_Format(ptf)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001681FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001682{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001683 v8::Isolate* isolate = ::GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001684
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001685 if (params.size() != 1)
1686 {
1687 CJS_Context* pContext = (CJS_Context*)cc;
1688 ASSERT(pContext != NULL);
1689 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1690 return FALSE;
1691 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001692
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001693 int iIndex = params[0].ToInt();
1694 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001695
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001696 ASSERT(iIndex<FX_ArraySize(cFormats));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001697
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001698 if (iIndex < 0)
1699 iIndex = 0;
1700 if (iIndex >= FX_ArraySize(cFormats))
1701 iIndex = 0;
1702 CJS_Parameters newParams;
1703 CJS_Value val(isolate,cFormats[iIndex]);
1704 newParams.push_back(val);
1705 return AFDate_FormatEx(cc,newParams,vRet,sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001706}
1707
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001708FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001709{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001710 v8::Isolate* isolate = ::GetIsolate(cc);
1711 if (params.size() != 1)
1712 {
1713 CJS_Context* pContext = (CJS_Context*)cc;
1714 ASSERT(pContext != NULL);
1715 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1716 return FALSE;
1717 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001718
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001719 int iIndex = params[0].ToInt();
1720 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001721
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001722 ASSERT(iIndex<FX_ArraySize(cFormats));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001723
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001724 if (iIndex < 0)
1725 iIndex = 0;
1726 if (iIndex >= FX_ArraySize(cFormats))
1727 iIndex = 0;
1728 CJS_Parameters newParams;
1729 CJS_Value val(isolate,cFormats[iIndex]);
1730 newParams.push_back(val);
1731 return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001732}
1733
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001734FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001735{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001736 return AFDate_FormatEx(cc,params,vRet,sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001737}
1738
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001739FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001740{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001741 return AFDate_KeystrokeEx(cc,params,vRet,sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001742}
1743
1744//function AFSpecial_Format(psf)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001745FX_BOOL CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001746{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001747 CJS_Context* pContext = (CJS_Context *)cc;
1748 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001749
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001750 if (params.size() != 1)
1751 {
1752 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1753 return FALSE;
1754 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001755
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001756 std::string cFormat;
1757 int iIndex = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001758
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001759 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1760 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001761
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001762 if(!pEvent->m_pValue)
1763 return FALSE;
1764 CFX_WideString& Value = pEvent->Value();
1765 std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001766
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001767 switch (iIndex)
1768 {
1769 case 0:
1770 cFormat = "99999";
1771 break;
1772 case 1:
1773 cFormat = "99999-9999";
1774 break;
1775 case 2:
1776 {
1777 std::string NumberStr;
1778 util::printx("9999999999", strSrc,NumberStr);
1779 if (NumberStr.length() >= 10 )
1780 cFormat = "(999) 999-9999";
1781 else
1782 cFormat = "999-9999";
1783 break;
1784 }
1785 case 3:
1786 cFormat = "999-99-9999";
1787 break;
1788 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001789
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001790 std::string strDes;
1791 util::printx(cFormat,strSrc,strDes);
1792 Value = CFX_WideString::FromLocal(strDes.c_str());
1793 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001794}
1795
1796
1797//function AFSpecial_KeystrokeEx(mask)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001798FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001799{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001800 CJS_Context* pContext = (CJS_Context *)cc;
1801 ASSERT(pContext != NULL);
1802 CJS_EventHandler* pEvent = pContext->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001803
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001804 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001805
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001806 if (params.size() < 1)
1807 {
1808 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1809 return FALSE;
1810 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001811
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001812 if(!pEvent->m_pValue)
1813 return FALSE;
1814 CFX_WideString& valEvent = pEvent->Value();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001815
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001816 CFX_WideString wstrMask = params[0].ToCFXWideString();
1817 if (wstrMask.IsEmpty())
1818 return TRUE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001819
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001820 std::wstring wstrValue = valEvent.c_str();
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001821
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001822 if (pEvent->WillCommit())
1823 {
1824 if (wstrValue.empty())
1825 return TRUE;
1826 int iIndexMask = 0;
1827 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); it++)
1828 {
1829 wchar_t w_Value = *it;
1830 if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
1831 break;
1832 iIndexMask++;
1833 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001834
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001835 if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0))
1836 {
1837 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
1838 pEvent->Rc() = FALSE;
1839 }
1840 return TRUE;
1841 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001842
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001843 CFX_WideString &wideChange = pEvent->Change();
1844 std::wstring wChange = wideChange.c_str();
1845 if (wChange.empty())
1846 return TRUE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001847
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001848 int iIndexMask = pEvent->SelStart();
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001849
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001850 if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
1851 {
1852 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
1853 pEvent->Rc() = FALSE;
1854 return TRUE;
1855 }
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001856
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001857 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
1858 {
1859 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
1860 pEvent->Rc() = FALSE;
1861 return TRUE;
1862 }
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001863
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001864 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
1865 {
1866 if (iIndexMask >= wstrMask.GetLength())
1867 {
1868 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
1869 pEvent->Rc() = FALSE;
1870 return TRUE;
1871 }
1872 wchar_t w_Mask = wstrMask[iIndexMask];
1873 if (!isReservedMaskChar(w_Mask))
1874 {
1875 *it = w_Mask;
1876 }
1877 wchar_t w_Change = *it;
1878 if (!maskSatisfied(w_Change,w_Mask))
1879 {
1880 pEvent->Rc() = FALSE;
1881 return TRUE;
1882 }
1883 iIndexMask++;
1884 }
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001885
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001886 wideChange = wChange.c_str();
1887 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001888}
1889
1890
1891//function AFSpecial_Keystroke(psf)
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001892FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001893{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001894 v8::Isolate* isolate = ::GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001895
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001896 CJS_Context* pContext = (CJS_Context *)cc;
1897 ASSERT(pContext != NULL);
1898 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1899 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001900
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001901 if (params.size() != 1)
1902 {
1903 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1904 return FALSE;
1905 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001906
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001907 std::string cFormat;
1908 int iIndex = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001909
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001910 if(!pEvent->m_pValue)
1911 return FALSE;
1912 //CJS_Value val = pEvent->Value();
1913 CFX_WideString& val = pEvent->Value();
1914 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str();
1915 std::wstring wstrChange = pEvent->Change().c_str();
Tom Sepez4f7bc042015-04-27 12:06:58 -07001916
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001917 switch (iIndex)
1918 {
1919 case 0:
1920 cFormat = "99999";
1921 break;
1922 case 1:
1923 //cFormat = "99999-9999";
1924 cFormat = "999999999";
1925 break;
1926 case 2:
1927 {
1928 std::string NumberStr;
1929 util::printx("9999999999", strSrc,NumberStr);
1930 if (strSrc.length() + wstrChange.length() > 7 )
1931 //cFormat = "(999) 999-9999";
1932 cFormat = "9999999999";
1933 else
1934 //cFormat = "999-9999";
1935 cFormat = "9999999";
1936 break;
1937 }
1938 case 3:
1939 //cFormat = "999-99-9999";
1940 cFormat = "999999999";
1941 break;
1942 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001943
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001944 CJS_Parameters params2;
1945 CJS_Value vMask(isolate, cFormat.c_str());
1946 params2.push_back(vMask);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001947
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001948 return AFSpecial_KeystrokeEx(cc,params2,vRet,sError);
1949}
1950
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001951FX_BOOL CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001952{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001953 CJS_Context* pContext = (CJS_Context *)cc;
1954 ASSERT(pContext != NULL);
1955 CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
1956 ASSERT(pEventHandler != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001957
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001958 if (params.size() != 1)
1959 {
1960 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1961 return FALSE;
1962 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001963
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001964 CFX_WideString swValue;
1965 if (pEventHandler->m_pValue != NULL)
1966 swValue = pEventHandler->Value();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001967
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001968 if (pEventHandler->WillCommit())
1969 {
1970 vRet = swValue.c_str();
1971 return TRUE;
1972 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001973
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001974 CFX_WideString prefix,postfix;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001975
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001976 if (pEventHandler->SelStart() >= 0)
1977 prefix = swValue.Mid(0,pEventHandler->SelStart());
1978 else
1979 prefix = L"";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001980
1981
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001982 if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength())
1983 postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd());
1984 else postfix = L"";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001985
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001986 vRet = (prefix + pEventHandler->Change() + postfix).c_str();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001987
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001988 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001989}
1990
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001991FX_BOOL CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001992{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001993 CJS_Context* pContext = (CJS_Context *)cc;
1994 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001995
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001996 if (params.size() != 2)
1997 {
1998 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1999 return FALSE;
2000 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002001
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002002 CFX_WideString sValue = params[0].ToCFXWideString();
2003 CFX_WideString sFormat = params[1].ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002004
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002005 FX_BOOL bWrongFormat = FALSE;
2006 double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002007
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002008 if (JS_PortIsNan(dDate))
2009 {
2010 CFX_WideString swMsg;
2011 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str());
2012 Alert((CJS_Context *)cc, swMsg.c_str());
2013 return FALSE;
2014 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002015
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002016 vRet = dDate;
2017 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002018}
2019
Tom Sepez2f3dfef2015-03-02 15:35:26 -08002020FX_BOOL CJS_PublicMethods::AFSimple(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002021{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002022 if (params.size() != 3)
2023 {
2024 CJS_Context* pContext = (CJS_Context *)cc;
2025 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002026
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002027 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2028 return FALSE;
2029 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002030
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002031 vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1].ToDouble(), params[2].ToDouble());
2032 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002033}
2034
Tom Sepez2f3dfef2015-03-02 15:35:26 -08002035FX_BOOL CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002036{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002037 if (params.size() != 1)
2038 {
2039 CJS_Context* pContext = (CJS_Context *)cc;
2040 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002041
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002042 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2043 return FALSE;
2044 }
2045 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str());
2046 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002047}
2048
Tom Sepez2f3dfef2015-03-02 15:35:26 -08002049FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002050{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002051 v8::Isolate* isolate = ::GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002052
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002053 CJS_Context* pContext = (CJS_Context *)cc;
2054 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002055
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002056 if (params.size() != 2)
2057 {
2058 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2059 return FALSE;
2060 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002061
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002062 CJS_Value params1 = params[1];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002063
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002064 if (!params1.IsArrayObject() && params1.GetType() != VT_string)
2065 {
2066 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2067 return FALSE;
2068 }
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002069
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002070 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002071 ASSERT(pReaderDoc != NULL);
2072
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002073 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
2074 ASSERT(pReaderInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002075
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002076 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
2077 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002078
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002079 double dValue;
2080 CFX_WideString sFunction = params[0].ToCFXWideString();
2081 if (wcscmp(sFunction.c_str(), L"PRD") == 0)
2082 dValue = 1.0;
2083 else
2084 dValue = 0.0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002085
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002086 CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002087
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002088 int nFieldsCount = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002089
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002090 for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
2091 {
2092 CJS_Value jsValue(isolate);
2093 FieldNameArray.GetElement(i,jsValue);
2094 CFX_WideString wsFieldName = jsValue.ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002095
2096 for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002097 {
2098 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName))
2099 {
2100 double dTemp = 0.0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002101
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002102 switch (pFormField->GetFieldType())
2103 {
2104 case FIELDTYPE_TEXTFIELD:
2105 case FIELDTYPE_COMBOBOX:
2106 {
2107 dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
2108 break;
2109 }
2110 case FIELDTYPE_PUSHBUTTON:
2111 {
2112 dTemp = 0.0;
2113 break;
2114 }
2115 case FIELDTYPE_CHECKBOX:
2116 case FIELDTYPE_RADIOBUTTON:
2117 {
2118 dTemp = 0.0;
2119 for (int c=0,csz=pFormField->CountControls(); c<csz; c++)
2120 {
2121 if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c))
2122 {
2123 if (pFormCtrl->IsChecked())
2124 {
2125 dTemp += ParseStringToNumber(pFormCtrl->GetExportValue().c_str());
2126 break;
2127 }
2128 else
2129 continue;
2130 }
2131 }
2132 break;
2133 }
2134 case FIELDTYPE_LISTBOX:
2135 {
2136 dTemp = 0.0;
2137 if (pFormField->CountSelectedItems() > 1)
2138 break;
2139 else
2140 {
2141 dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
2142 break;
2143 }
2144 }
2145 default:
2146 break;
2147 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002148
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002149 if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || wcscmp(sFunction.c_str(), L"MAX") == 0))
2150 dValue = dTemp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002151
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002152 dValue = AF_Simple(sFunction.c_str(), dValue, dTemp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002153
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002154 nFieldsCount++;
2155 }
2156 }
2157 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002158
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002159 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0)
2160 dValue /= nFieldsCount;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002161
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002162 dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6);
2163 CJS_Value jsValue(isolate,dValue);
2164 if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
2165 ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue.ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002166
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002167 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002168}
2169
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002170/* This function validates the current event to ensure that its value is
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002171** within the specified range. */
2172
Tom Sepez2f3dfef2015-03-02 15:35:26 -08002173FX_BOOL CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002174{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002175 CJS_Context* pContext = (CJS_Context *)cc;
2176 ASSERT(pContext != NULL);
2177 CJS_EventHandler* pEvent = pContext->GetEventHandler();
2178 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002179
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002180 if (params.size() != 4)
2181 {
2182 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2183 return FALSE;
2184 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002185
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002186 if(!pEvent->m_pValue)
2187 return FALSE;
2188 if (pEvent->Value().IsEmpty() )
2189 return TRUE;
2190 double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
2191 FX_BOOL bGreaterThan = params[0].ToBool();
2192 double dGreaterThan = params[1].ToDouble();
2193 FX_BOOL bLessThan = params[2].ToBool();
2194 double dLessThan = params[3].ToDouble();
2195 CFX_WideString swMsg;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002196
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002197 if (bGreaterThan && bLessThan)
2198 {
2199 if (dEentValue < dGreaterThan || dEentValue > dLessThan)
2200 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(),
2201 params[1].ToCFXWideString().c_str(),
2202 params[3].ToCFXWideString().c_str());
2203 }
2204 else if (bGreaterThan)
2205 {
2206 if (dEentValue < dGreaterThan)
2207 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(),
2208 params[1].ToCFXWideString().c_str());
2209 }
2210 else if (bLessThan)
2211 {
2212 if (dEentValue > dLessThan)
2213 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(),
2214 params[3].ToCFXWideString().c_str());
2215 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002216
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002217 if (!swMsg.IsEmpty())
2218 {
2219 Alert(pContext, swMsg.c_str());
2220 pEvent->Rc() = FALSE;
2221 }
2222 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002223}
2224
Tom Sepez2f3dfef2015-03-02 15:35:26 -08002225FX_BOOL CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002226{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002227 v8::Isolate* isolate = ::GetIsolate(cc);
2228 CJS_Context* pContext = (CJS_Context*)cc;
2229 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002230
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002231 if (params.size() != 1)
2232 {
2233 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2234 return FALSE;
2235 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002236
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002237 CJS_Array nums(isolate);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002238
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002239 CFX_WideString str = params[0].ToCFXWideString();
2240 CFX_WideString sPart;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002241
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002242 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
2243 str = L"0" + str;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002244
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002245 int nIndex = 0;
2246 for (int i=0, sz=str.GetLength(); i<sz; i++)
2247 {
2248 FX_WCHAR wc = str.GetAt(i);
2249 if (IsDigit((wchar_t)wc))
2250 {
2251 sPart += wc;
2252 }
2253 else
2254 {
2255 if (sPart.GetLength() > 0)
2256 {
2257 nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
2258 sPart = L"";
2259 nIndex ++;
2260 }
2261 }
2262 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002263
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002264 if (sPart.GetLength() > 0)
2265 {
2266 nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
2267 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002268
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002269 if (nums.GetLength() > 0)
2270 vRet = nums;
2271 else
2272 vRet.SetNull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002273
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002274 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002275}