John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // 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 Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/javascript/PublicMethods.h" |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 8 | |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 9 | #include <algorithm> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 12 | |
Dan Sinclair | a8a28e0 | 2016-03-23 15:41:39 -0400 | [diff] [blame] | 13 | #include "core/fxcrt/include/fx_ext.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/include/fsdk_mgr.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 15 | #include "fpdfsdk/javascript/Field.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 16 | #include "fpdfsdk/javascript/JS_Define.h" |
| 17 | #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 18 | #include "fpdfsdk/javascript/JS_Object.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 19 | #include "fpdfsdk/javascript/JS_Value.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/javascript/cjs_context.h" |
| 21 | #include "fpdfsdk/javascript/cjs_runtime.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 22 | #include "fpdfsdk/javascript/color.h" |
| 23 | #include "fpdfsdk/javascript/resource.h" |
| 24 | #include "fpdfsdk/javascript/util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | #define DOUBLE_CORRECT 0.000000000000001 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
| 28 | BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) |
| 30 | JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) |
| 31 | JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) |
| 32 | JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke) |
| 33 | JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx) |
| 34 | JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx) |
| 35 | JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format) |
| 36 | JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke) |
| 37 | JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx) |
| 38 | JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx) |
| 39 | JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format) |
| 40 | JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke) |
| 41 | JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format) |
| 42 | JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke) |
| 43 | JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx) |
| 44 | JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple) |
| 45 | JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber) |
| 46 | JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate) |
| 47 | JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate) |
| 48 | JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange) |
| 49 | JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx) |
| 50 | JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 51 | END_JS_STATIC_GLOBAL_FUN() |
| 52 | |
| 53 | IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) |
| 54 | |
tsepez | 745611b | 2016-04-12 16:46:34 -0700 | [diff] [blame] | 55 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
tsepez | 745611b | 2016-04-12 16:46:34 -0700 | [diff] [blame] | 57 | const FX_WCHAR* const months[] = {L"Jan", L"Feb", L"Mar", L"Apr", |
| 58 | L"May", L"Jun", L"Jul", L"Aug", |
| 59 | L"Sep", L"Oct", L"Nov", L"Dec"}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 60 | |
tsepez | 745611b | 2016-04-12 16:46:34 -0700 | [diff] [blame] | 61 | const FX_WCHAR* const fullmonths[] = {L"January", L"February", L"March", |
| 62 | L"April", L"May", L"June", |
| 63 | L"July", L"August", L"September", |
| 64 | L"October", L"November", L"December"}; |
| 65 | |
| 66 | CFX_ByteString StrTrim(const CFX_ByteString& pStr) { |
| 67 | CFX_ByteString result(pStr); |
| 68 | result.TrimLeft(' '); |
| 69 | result.TrimRight(' '); |
| 70 | return result; |
| 71 | } |
| 72 | |
| 73 | CFX_WideString StrTrim(const CFX_WideString& pStr) { |
| 74 | CFX_WideString result(pStr); |
| 75 | result.TrimLeft(' '); |
| 76 | result.TrimRight(' '); |
| 77 | return result; |
| 78 | } |
| 79 | |
| 80 | } // namespace |
| 81 | |
| 82 | bool CJS_PublicMethods::IsNumber(const CFX_WideString& str) { |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 83 | CFX_WideString sTrim = StrTrim(str); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | const FX_WCHAR* pTrim = sTrim.c_str(); |
| 85 | const FX_WCHAR* p = pTrim; |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 86 | bool bDot = false; |
| 87 | bool bKXJS = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | wchar_t c; |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 90 | while ((c = *p) != L'\0') { |
| 91 | if (c == L'.' || c == L',') { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | if (bDot) |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 93 | return false; |
| 94 | bDot = true; |
| 95 | } else if (c == L'-' || c == L'+') { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | if (p != pTrim) |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 97 | return false; |
| 98 | } else if (c == L'e' || c == L'E') { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | if (bKXJS) |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 100 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | p++; |
| 103 | c = *p; |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 104 | if (c == L'+' || c == L'-') { |
| 105 | bKXJS = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | } else { |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 107 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | } |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 109 | } else if (!FXSYS_iswdigit(c)) { |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 110 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | } |
| 112 | p++; |
| 113 | } |
| 114 | |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 115 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 118 | bool CJS_PublicMethods::maskSatisfied(wchar_t c_Change, wchar_t c_Mask) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 119 | switch (c_Mask) { |
| 120 | case L'9': |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 121 | return FXSYS_iswdigit(c_Change); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | case L'A': |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 123 | return FXSYS_iswalpha(c_Change); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 124 | case L'O': |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 125 | return FXSYS_iswalnum(c_Change); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 126 | case L'X': |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 127 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | default: |
| 129 | return (c_Change == c_Mask); |
| 130 | } |
| 131 | } |
| 132 | |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 133 | bool CJS_PublicMethods::isReservedMaskChar(wchar_t ch) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X'; |
| 135 | } |
| 136 | |
| 137 | double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, |
| 138 | double dValue1, |
| 139 | double dValue2) { |
| 140 | if (FXSYS_wcsicmp(sFuction, L"AVG") == 0 || |
| 141 | FXSYS_wcsicmp(sFuction, L"SUM") == 0) { |
| 142 | return dValue1 + dValue2; |
| 143 | } |
| 144 | if (FXSYS_wcsicmp(sFuction, L"PRD") == 0) { |
| 145 | return dValue1 * dValue2; |
| 146 | } |
| 147 | if (FXSYS_wcsicmp(sFuction, L"MIN") == 0) { |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 148 | return std::min(dValue1, dValue2); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 149 | } |
| 150 | if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 151 | return std::max(dValue1, dValue2); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | } |
| 153 | return dValue1; |
| 154 | } |
| 155 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 156 | CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | CJS_Value val) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 158 | CJS_Array StrArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 159 | if (val.IsArrayObject()) { |
| 160 | val.ConvertToArray(StrArray); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 161 | return StrArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | } |
| 163 | CFX_WideString wsStr = val.ToCFXWideString(); |
| 164 | CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 165 | const char* p = t.c_str(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | |
| 167 | int ch = ','; |
| 168 | int nIndex = 0; |
| 169 | |
| 170 | while (*p) { |
| 171 | const char* pTemp = strchr(p, ch); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 172 | if (!pTemp) { |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 173 | StrArray.SetElement( |
| 174 | nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | } |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 177 | |
| 178 | char* pSub = new char[pTemp - p + 1]; |
| 179 | strncpy(pSub, p, pTemp - p); |
| 180 | *(pSub + (pTemp - p)) = '\0'; |
| 181 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 182 | StrArray.SetElement( |
| 183 | nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str())); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 184 | delete[] pSub; |
| 185 | |
| 186 | nIndex++; |
| 187 | p = ++pTemp; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | } |
| 189 | return StrArray; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 192 | int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | int nStart, |
| 194 | int& nSkip, |
| 195 | int nMaxStep) { |
| 196 | int nRet = 0; |
| 197 | nSkip = 0; |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 198 | for (int i = nStart, sz = str.GetLength(); i < sz; i++) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 199 | if (i - nStart > 10) |
| 200 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 201 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 202 | FX_WCHAR c = str.GetAt(i); |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 203 | if (!FXSYS_iswdigit(c)) |
| 204 | break; |
| 205 | |
Dan Sinclair | 1c91537 | 2016-03-03 17:12:58 -0500 | [diff] [blame] | 206 | nRet = nRet * 10 + FXSYS_toDecimalDigit(c); |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 207 | nSkip = i - nStart + 1; |
| 208 | if (nSkip >= nMaxStep) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | break; |
| 210 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 211 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | return nRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 215 | CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& str, |
| 216 | int nStart, |
| 217 | int& nSkip) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 218 | CFX_WideString swRet; |
| 219 | nSkip = 0; |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 220 | for (int i = nStart, sz = str.GetLength(); i < sz; i++) { |
| 221 | FX_WCHAR c = str.GetAt(i); |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 222 | if (!FXSYS_iswdigit(c)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | break; |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 224 | |
| 225 | swRet += c; |
| 226 | nSkip = i - nStart + 1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 228 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | return swRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value, |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 233 | bool* bWrongFormat) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | double dt = JS_GetDateTime(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 235 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | int nYear = JS_GetYearFromTime(dt); |
| 237 | int nMonth = JS_GetMonthFromTime(dt) + 1; |
| 238 | int nDay = JS_GetDayFromTime(dt); |
| 239 | int nHour = JS_GetHourFromTime(dt); |
| 240 | int nMin = JS_GetMinFromTime(dt); |
| 241 | int nSec = JS_GetSecFromTime(dt); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 242 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | int number[3]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 244 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | int nSkip = 0; |
| 246 | int nLen = value.GetLength(); |
| 247 | int nIndex = 0; |
| 248 | int i = 0; |
| 249 | while (i < nLen) { |
| 250 | if (nIndex > 2) |
| 251 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | FX_WCHAR c = value.GetAt(i); |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 254 | if (FXSYS_iswdigit(c)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | number[nIndex++] = ParseStringInteger(value, i, nSkip, 4); |
| 256 | i += nSkip; |
| 257 | } else { |
| 258 | i++; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | if (nIndex == 2) { |
| 263 | // case2: month/day |
| 264 | // case3: day/month |
| 265 | if ((number[0] >= 1 && number[0] <= 12) && |
| 266 | (number[1] >= 1 && number[1] <= 31)) { |
| 267 | nMonth = number[0]; |
| 268 | nDay = number[1]; |
| 269 | } else if ((number[0] >= 1 && number[0] <= 31) && |
| 270 | (number[1] >= 1 && number[1] <= 12)) { |
| 271 | nDay = number[0]; |
| 272 | nMonth = number[1]; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 273 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 274 | |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 275 | if (bWrongFormat) |
| 276 | *bWrongFormat = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | } else if (nIndex == 3) { |
| 278 | // case1: year/month/day |
| 279 | // case2: month/day/year |
| 280 | // case3: day/month/year |
Tom Sepez | 5ffacd6 | 2014-07-18 14:42:12 -0700 | [diff] [blame] | 281 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && |
| 283 | (number[2] >= 1 && number[2] <= 31)) { |
| 284 | nYear = number[0]; |
| 285 | nMonth = number[1]; |
| 286 | nDay = number[2]; |
| 287 | } else if ((number[0] >= 1 && number[0] <= 12) && |
| 288 | (number[1] >= 1 && number[1] <= 31) && number[2] > 31) { |
| 289 | nMonth = number[0]; |
| 290 | nDay = number[1]; |
| 291 | nYear = number[2]; |
| 292 | } else if ((number[0] >= 1 && number[0] <= 31) && |
| 293 | (number[1] >= 1 && number[1] <= 12) && number[2] > 31) { |
| 294 | nDay = number[0]; |
| 295 | nMonth = number[1]; |
| 296 | nYear = number[2]; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 297 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 298 | |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 299 | if (bWrongFormat) |
| 300 | *bWrongFormat = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | } else { |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 302 | if (bWrongFormat) |
| 303 | *bWrongFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | return dt; |
| 305 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 306 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 307 | CFX_WideString swTemp; |
| 308 | swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec); |
tsepez | 018935c | 2016-04-15 13:15:12 -0700 | [diff] [blame^] | 309 | return JS_DateParse(swTemp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 312 | double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, |
| 313 | const CFX_WideString& format, |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 314 | bool* bWrongFormat) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | double dt = JS_GetDateTime(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 316 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | if (format.IsEmpty() || value.IsEmpty()) |
| 318 | return dt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 319 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | int nYear = JS_GetYearFromTime(dt); |
| 321 | int nMonth = JS_GetMonthFromTime(dt) + 1; |
| 322 | int nDay = JS_GetDayFromTime(dt); |
| 323 | int nHour = JS_GetHourFromTime(dt); |
| 324 | int nMin = JS_GetMinFromTime(dt); |
| 325 | int nSec = JS_GetSecFromTime(dt); |
| 326 | |
| 327 | int nYearSub = 99; // nYear - 2000; |
| 328 | |
| 329 | FX_BOOL bPm = FALSE; |
| 330 | FX_BOOL bExit = FALSE; |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 331 | bool bBadFormat = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | |
| 333 | int i = 0; |
| 334 | int j = 0; |
| 335 | |
| 336 | while (i < format.GetLength()) { |
| 337 | if (bExit) |
| 338 | break; |
| 339 | |
| 340 | FX_WCHAR c = format.GetAt(i); |
| 341 | switch (c) { |
| 342 | case ':': |
| 343 | case '.': |
| 344 | case '-': |
| 345 | case '\\': |
| 346 | case '/': |
| 347 | i++; |
| 348 | j++; |
| 349 | break; |
| 350 | |
| 351 | case 'y': |
| 352 | case 'm': |
| 353 | case 'd': |
| 354 | case 'H': |
| 355 | case 'h': |
| 356 | case 'M': |
| 357 | case 's': |
| 358 | case 't': { |
| 359 | int oldj = j; |
| 360 | int nSkip = 0; |
| 361 | int remaining = format.GetLength() - i - 1; |
| 362 | |
| 363 | if (remaining == 0 || format.GetAt(i + 1) != c) { |
| 364 | switch (c) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 365 | case 'y': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | i++; |
| 367 | j++; |
| 368 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 369 | case 'm': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | nMonth = ParseStringInteger(value, j, nSkip, 2); |
| 371 | i++; |
| 372 | j += nSkip; |
| 373 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 374 | case 'd': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 375 | nDay = ParseStringInteger(value, j, nSkip, 2); |
| 376 | i++; |
| 377 | j += nSkip; |
| 378 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 379 | case 'H': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | nHour = ParseStringInteger(value, j, nSkip, 2); |
| 381 | i++; |
| 382 | j += nSkip; |
| 383 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 384 | case 'h': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | nHour = ParseStringInteger(value, j, nSkip, 2); |
| 386 | i++; |
| 387 | j += nSkip; |
| 388 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 389 | case 'M': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | nMin = ParseStringInteger(value, j, nSkip, 2); |
| 391 | i++; |
| 392 | j += nSkip; |
| 393 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 394 | case 's': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | nSec = ParseStringInteger(value, j, nSkip, 2); |
| 396 | i++; |
| 397 | j += nSkip; |
| 398 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 399 | case 't': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | bPm = (j < value.GetLength() && value.GetAt(j) == 'p'); |
| 401 | i++; |
| 402 | j++; |
| 403 | break; |
| 404 | } |
| 405 | } else if (remaining == 1 || format.GetAt(i + 2) != c) { |
| 406 | switch (c) { |
| 407 | case 'y': |
| 408 | nYear = ParseStringInteger(value, j, nSkip, 4); |
| 409 | i += 2; |
| 410 | j += nSkip; |
| 411 | break; |
| 412 | case 'm': |
| 413 | nMonth = ParseStringInteger(value, j, nSkip, 2); |
| 414 | i += 2; |
| 415 | j += nSkip; |
| 416 | break; |
| 417 | case 'd': |
| 418 | nDay = ParseStringInteger(value, j, nSkip, 2); |
| 419 | i += 2; |
| 420 | j += nSkip; |
| 421 | break; |
| 422 | case 'H': |
| 423 | nHour = ParseStringInteger(value, j, nSkip, 2); |
| 424 | i += 2; |
| 425 | j += nSkip; |
| 426 | break; |
| 427 | case 'h': |
| 428 | nHour = ParseStringInteger(value, j, nSkip, 2); |
| 429 | i += 2; |
| 430 | j += nSkip; |
| 431 | break; |
| 432 | case 'M': |
| 433 | nMin = ParseStringInteger(value, j, nSkip, 2); |
| 434 | i += 2; |
| 435 | j += nSkip; |
| 436 | break; |
| 437 | case 's': |
| 438 | nSec = ParseStringInteger(value, j, nSkip, 2); |
| 439 | i += 2; |
| 440 | j += nSkip; |
| 441 | break; |
| 442 | case 't': |
| 443 | bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && |
| 444 | value.GetAt(j + 1) == 'm'); |
| 445 | i += 2; |
| 446 | j += 2; |
| 447 | break; |
| 448 | } |
| 449 | } else if (remaining == 2 || format.GetAt(i + 3) != c) { |
| 450 | switch (c) { |
| 451 | case 'm': { |
| 452 | CFX_WideString sMonth = ParseStringString(value, j, nSkip); |
| 453 | FX_BOOL bFind = FALSE; |
| 454 | for (int m = 0; m < 12; m++) { |
| 455 | if (sMonth.CompareNoCase(months[m]) == 0) { |
| 456 | nMonth = m + 1; |
| 457 | i += 3; |
| 458 | j += nSkip; |
| 459 | bFind = TRUE; |
| 460 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 461 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | if (!bFind) { |
| 465 | nMonth = ParseStringInteger(value, j, nSkip, 3); |
| 466 | i += 3; |
| 467 | j += nSkip; |
| 468 | } |
| 469 | } break; |
| 470 | case 'y': |
| 471 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 472 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | i += 3; |
| 474 | j += 3; |
| 475 | break; |
| 476 | } |
| 477 | } else if (remaining == 3 || format.GetAt(i + 4) != c) { |
| 478 | switch (c) { |
| 479 | case 'y': |
| 480 | nYear = ParseStringInteger(value, j, nSkip, 4); |
| 481 | j += nSkip; |
| 482 | i += 4; |
| 483 | break; |
| 484 | case 'm': { |
| 485 | FX_BOOL bFind = FALSE; |
| 486 | |
| 487 | CFX_WideString sMonth = ParseStringString(value, j, nSkip); |
| 488 | sMonth.MakeLower(); |
| 489 | |
| 490 | for (int m = 0; m < 12; m++) { |
| 491 | CFX_WideString sFullMonths = fullmonths[m]; |
| 492 | sFullMonths.MakeLower(); |
| 493 | |
| 494 | if (sFullMonths.Find(sMonth.c_str(), 0) != -1) { |
| 495 | nMonth = m + 1; |
| 496 | i += 4; |
| 497 | j += nSkip; |
| 498 | bFind = TRUE; |
| 499 | break; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | if (!bFind) { |
| 504 | nMonth = ParseStringInteger(value, j, nSkip, 4); |
| 505 | i += 4; |
| 506 | j += nSkip; |
| 507 | } |
| 508 | } break; |
| 509 | default: |
| 510 | i += 4; |
| 511 | j += 4; |
| 512 | break; |
| 513 | } |
| 514 | } else { |
| 515 | if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) { |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 516 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 517 | bExit = TRUE; |
| 518 | } |
| 519 | i++; |
| 520 | j++; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 521 | } |
Tom Sepez | 8538642 | 2014-07-23 10:28:37 -0700 | [diff] [blame] | 522 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 523 | if (oldj == j) { |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 524 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | bExit = TRUE; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | break; |
| 530 | default: |
| 531 | if (value.GetLength() <= j) { |
| 532 | bExit = TRUE; |
| 533 | } else if (format.GetAt(i) != value.GetAt(j)) { |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 534 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 535 | bExit = TRUE; |
| 536 | } |
| 537 | |
| 538 | i++; |
| 539 | j++; |
| 540 | break; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | if (bPm) |
| 545 | nHour += 12; |
| 546 | |
| 547 | if (nYear >= 0 && nYear <= nYearSub) |
| 548 | nYear += 2000; |
| 549 | |
| 550 | if (nMonth < 1 || nMonth > 12) |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 551 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | |
| 553 | if (nDay < 1 || nDay > 31) |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 554 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | |
| 556 | if (nHour < 0 || nHour > 24) |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 557 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 558 | |
| 559 | if (nMin < 0 || nMin > 60) |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 560 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | |
| 562 | if (nSec < 0 || nSec > 60) |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 563 | bBadFormat = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | |
| 565 | double dRet = 0; |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 566 | if (bBadFormat) { |
| 567 | dRet = ParseNormalDate(value, &bBadFormat); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | } else { |
| 569 | dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), |
| 570 | JS_MakeTime(nHour, nMin, nSec, 0)); |
tsepez | 018935c | 2016-04-15 13:15:12 -0700 | [diff] [blame^] | 571 | if (JS_PortIsNan(dRet)) |
| 572 | dRet = JS_DateParse(value); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 573 | } |
| 574 | |
tsepez | 018935c | 2016-04-15 13:15:12 -0700 | [diff] [blame^] | 575 | if (JS_PortIsNan(dRet)) |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 576 | dRet = ParseNormalDate(value, &bBadFormat); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 577 | |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 578 | if (bWrongFormat) |
| 579 | *bWrongFormat = bBadFormat; |
tsepez | 018935c | 2016-04-15 13:15:12 -0700 | [diff] [blame^] | 580 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | return dRet; |
| 582 | } |
| 583 | |
| 584 | CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, |
| 585 | const CFX_WideString& format) { |
| 586 | CFX_WideString sRet = L"", sPart = L""; |
| 587 | |
| 588 | int nYear = JS_GetYearFromTime(dDate); |
| 589 | int nMonth = JS_GetMonthFromTime(dDate) + 1; |
| 590 | int nDay = JS_GetDayFromTime(dDate); |
| 591 | int nHour = JS_GetHourFromTime(dDate); |
| 592 | int nMin = JS_GetMinFromTime(dDate); |
| 593 | int nSec = JS_GetSecFromTime(dDate); |
| 594 | |
| 595 | int i = 0; |
| 596 | while (i < format.GetLength()) { |
| 597 | FX_WCHAR c = format.GetAt(i); |
| 598 | int remaining = format.GetLength() - i - 1; |
| 599 | sPart = L""; |
| 600 | switch (c) { |
| 601 | case 'y': |
| 602 | case 'm': |
| 603 | case 'd': |
| 604 | case 'H': |
| 605 | case 'h': |
| 606 | case 'M': |
| 607 | case 's': |
| 608 | case 't': |
| 609 | if (remaining == 0 || format.GetAt(i + 1) != c) { |
| 610 | switch (c) { |
| 611 | case 'y': |
| 612 | sPart += c; |
| 613 | break; |
| 614 | case 'm': |
| 615 | sPart.Format(L"%d", nMonth); |
| 616 | break; |
| 617 | case 'd': |
| 618 | sPart.Format(L"%d", nDay); |
| 619 | break; |
| 620 | case 'H': |
| 621 | sPart.Format(L"%d", nHour); |
| 622 | break; |
| 623 | case 'h': |
| 624 | sPart.Format(L"%d", nHour > 12 ? nHour - 12 : nHour); |
| 625 | break; |
| 626 | case 'M': |
| 627 | sPart.Format(L"%d", nMin); |
| 628 | break; |
| 629 | case 's': |
| 630 | sPart.Format(L"%d", nSec); |
| 631 | break; |
| 632 | case 't': |
| 633 | sPart += nHour > 12 ? 'p' : 'a'; |
| 634 | break; |
| 635 | } |
| 636 | i++; |
| 637 | } else if (remaining == 1 || format.GetAt(i + 2) != c) { |
| 638 | switch (c) { |
| 639 | case 'y': |
| 640 | sPart.Format(L"%02d", nYear - (nYear / 100) * 100); |
| 641 | break; |
| 642 | case 'm': |
| 643 | sPart.Format(L"%02d", nMonth); |
| 644 | break; |
| 645 | case 'd': |
| 646 | sPart.Format(L"%02d", nDay); |
| 647 | break; |
| 648 | case 'H': |
| 649 | sPart.Format(L"%02d", nHour); |
| 650 | break; |
| 651 | case 'h': |
| 652 | sPart.Format(L"%02d", nHour > 12 ? nHour - 12 : nHour); |
| 653 | break; |
| 654 | case 'M': |
| 655 | sPart.Format(L"%02d", nMin); |
| 656 | break; |
| 657 | case 's': |
| 658 | sPart.Format(L"%02d", nSec); |
| 659 | break; |
| 660 | case 't': |
| 661 | sPart = nHour > 12 ? L"pm" : L"am"; |
| 662 | break; |
| 663 | } |
| 664 | i += 2; |
| 665 | } else if (remaining == 2 || format.GetAt(i + 3) != c) { |
| 666 | switch (c) { |
| 667 | case 'm': |
| 668 | i += 3; |
| 669 | if (nMonth > 0 && nMonth <= 12) |
| 670 | sPart += months[nMonth - 1]; |
| 671 | break; |
| 672 | default: |
| 673 | i += 3; |
| 674 | sPart += c; |
| 675 | sPart += c; |
| 676 | sPart += c; |
| 677 | break; |
| 678 | } |
| 679 | } else if (remaining == 3 || format.GetAt(i + 4) != c) { |
| 680 | switch (c) { |
| 681 | case 'y': |
| 682 | sPart.Format(L"%04d", nYear); |
| 683 | i += 4; |
| 684 | break; |
| 685 | case 'm': |
| 686 | i += 4; |
| 687 | if (nMonth > 0 && nMonth <= 12) |
| 688 | sPart += fullmonths[nMonth - 1]; |
| 689 | break; |
| 690 | default: |
| 691 | i += 4; |
| 692 | sPart += c; |
| 693 | sPart += c; |
| 694 | sPart += c; |
| 695 | sPart += c; |
| 696 | break; |
| 697 | } |
| 698 | } else { |
| 699 | i++; |
| 700 | sPart += c; |
| 701 | } |
| 702 | break; |
| 703 | default: |
| 704 | i++; |
| 705 | sPart += c; |
| 706 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 707 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 708 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | sRet += sPart; |
| 710 | } |
| 711 | |
| 712 | return sRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 715 | // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, |
| 716 | // bCurrencyPrepend) |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 717 | FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 718 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | CJS_Value& vRet, |
| 720 | CFX_WideString& sError) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 721 | #if _FX_OS_ != _FX_ANDROID_ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 722 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 723 | if (params.size() != 6) { |
| 724 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 725 | return FALSE; |
| 726 | } |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 727 | |
| 728 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 729 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 730 | if (!pEvent->m_pValue) |
| 731 | return FALSE; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 732 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 733 | CFX_WideString& Value = pEvent->Value(); |
| 734 | CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 735 | if (strValue.IsEmpty()) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 736 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | |
| 738 | int iDec = params[0].ToInt(); |
| 739 | int iSepStyle = params[1].ToInt(); |
| 740 | int iNegStyle = params[2].ToInt(); |
| 741 | // params[3] is iCurrStyle, it's not used. |
| 742 | std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); |
| 743 | FX_BOOL bCurrencyPrepend = params[5].ToBool(); |
| 744 | |
| 745 | if (iDec < 0) |
| 746 | iDec = -iDec; |
| 747 | |
| 748 | if (iSepStyle < 0 || iSepStyle > 3) |
| 749 | iSepStyle = 0; |
| 750 | |
| 751 | if (iNegStyle < 0 || iNegStyle > 3) |
| 752 | iNegStyle = 0; |
| 753 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 754 | // for processing decimal places |
| 755 | strValue.Replace(",", "."); |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 756 | double dValue = atof(strValue.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 757 | if (iDec > 0) |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 758 | dValue += DOUBLE_CORRECT; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 759 | |
| 760 | int iDec2; |
| 761 | int iNegative = 0; |
| 762 | |
| 763 | strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| 764 | if (strValue.IsEmpty()) { |
| 765 | dValue = 0; |
| 766 | strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| 767 | if (strValue.IsEmpty()) { |
| 768 | strValue = "0"; |
| 769 | iDec2 = 1; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | if (iDec2 < 0) { |
| 774 | for (int iNum = 0; iNum < abs(iDec2); iNum++) { |
| 775 | strValue = "0" + strValue; |
| 776 | } |
| 777 | iDec2 = 0; |
| 778 | } |
| 779 | int iMax = strValue.GetLength(); |
| 780 | if (iDec2 > iMax) { |
| 781 | for (int iNum = 0; iNum <= iDec2 - iMax; iNum++) { |
| 782 | strValue += "0"; |
| 783 | } |
| 784 | iMax = iDec2 + 1; |
| 785 | } |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 786 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 787 | // for processing seperator style |
| 788 | if (iDec2 < iMax) { |
| 789 | if (iSepStyle == 0 || iSepStyle == 1) { |
| 790 | strValue.Insert(iDec2, '.'); |
| 791 | iMax++; |
| 792 | } else if (iSepStyle == 2 || iSepStyle == 3) { |
| 793 | strValue.Insert(iDec2, ','); |
| 794 | iMax++; |
| 795 | } |
| 796 | |
| 797 | if (iDec2 == 0) |
| 798 | strValue.Insert(iDec2, '0'); |
| 799 | } |
| 800 | if (iSepStyle == 0 || iSepStyle == 2) { |
| 801 | char cSeperator; |
| 802 | if (iSepStyle == 0) |
| 803 | cSeperator = ','; |
| 804 | else |
| 805 | cSeperator = '.'; |
| 806 | |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 807 | for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 808 | strValue.Insert(iDecPositive, cSeperator); |
| 809 | iMax++; |
| 810 | } |
| 811 | } |
| 812 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 813 | // for processing currency string |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 814 | Value = CFX_WideString::FromLocal(strValue.AsStringC()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 815 | std::wstring strValue2 = Value.c_str(); |
| 816 | |
| 817 | if (bCurrencyPrepend) |
| 818 | strValue2 = wstrCurrency + strValue2; |
| 819 | else |
| 820 | strValue2 = strValue2 + wstrCurrency; |
| 821 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 822 | // for processing negative style |
| 823 | if (iNegative) { |
| 824 | if (iNegStyle == 0) { |
| 825 | strValue2.insert(0, L"-"); |
| 826 | } |
| 827 | if (iNegStyle == 2 || iNegStyle == 3) { |
| 828 | strValue2.insert(0, L"("); |
| 829 | strValue2.insert(strValue2.length(), L")"); |
| 830 | } |
| 831 | if (iNegStyle == 1 || iNegStyle == 3) { |
| 832 | if (Field* fTarget = pEvent->Target_Field()) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 833 | CJS_Array arColor(pRuntime); |
| 834 | CJS_Value vColElm(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 835 | vColElm = L"RGB"; |
| 836 | arColor.SetElement(0, vColElm); |
| 837 | vColElm = 1; |
| 838 | arColor.SetElement(1, vColElm); |
| 839 | vColElm = 0; |
| 840 | arColor.SetElement(2, vColElm); |
| 841 | |
| 842 | arColor.SetElement(3, vColElm); |
| 843 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 844 | CJS_PropValue vProp(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 845 | vProp.StartGetting(); |
| 846 | vProp << arColor; |
| 847 | vProp.StartSetting(); |
| 848 | fTarget->textColor(cc, vProp, sError); // red |
| 849 | } |
| 850 | } |
| 851 | } else { |
| 852 | if (iNegStyle == 1 || iNegStyle == 3) { |
| 853 | if (Field* fTarget = pEvent->Target_Field()) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 854 | CJS_Array arColor(pRuntime); |
| 855 | CJS_Value vColElm(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 856 | vColElm = L"RGB"; |
| 857 | arColor.SetElement(0, vColElm); |
| 858 | vColElm = 0; |
| 859 | arColor.SetElement(1, vColElm); |
| 860 | arColor.SetElement(2, vColElm); |
| 861 | arColor.SetElement(3, vColElm); |
| 862 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 863 | CJS_PropValue vProp(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 864 | vProp.StartGetting(); |
| 865 | fTarget->textColor(cc, vProp, sError); |
| 866 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 867 | CJS_Array aProp(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 868 | vProp.ConvertToArray(aProp); |
| 869 | |
| 870 | CPWL_Color crProp; |
| 871 | CPWL_Color crColor; |
| 872 | color::ConvertArrayToPWLColor(aProp, crProp); |
| 873 | color::ConvertArrayToPWLColor(arColor, crColor); |
| 874 | |
| 875 | if (crColor != crProp) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 876 | CJS_PropValue vProp2(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 877 | vProp2.StartGetting(); |
| 878 | vProp2 << arColor; |
| 879 | vProp2.StartSetting(); |
| 880 | fTarget->textColor(cc, vProp2, sError); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | Value = strValue2.c_str(); |
| 886 | #endif |
| 887 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 890 | // function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, |
| 891 | // bCurrencyPrepend) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 892 | FX_BOOL CJS_PublicMethods::AFNumber_Keystroke( |
| 893 | IJS_Context* cc, |
| 894 | const std::vector<CJS_Value>& params, |
| 895 | CJS_Value& vRet, |
| 896 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 897 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 898 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 899 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 900 | if (params.size() < 2) |
| 901 | return FALSE; |
| 902 | int iSepStyle = params[1].ToInt(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 903 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 904 | if (iSepStyle < 0 || iSepStyle > 3) |
| 905 | iSepStyle = 0; |
| 906 | if (!pEvent->m_pValue) |
| 907 | return FALSE; |
| 908 | CFX_WideString& val = pEvent->Value(); |
| 909 | CFX_WideString& w_strChange = pEvent->Change(); |
| 910 | CFX_WideString w_strValue = val; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 911 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 912 | if (pEvent->WillCommit()) { |
| 913 | CFX_WideString wstrChange = w_strChange; |
tsepez | 745611b | 2016-04-12 16:46:34 -0700 | [diff] [blame] | 914 | CFX_WideString wstrValue = StrTrim(w_strValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 915 | if (wstrValue.IsEmpty()) |
| 916 | return TRUE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 917 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 918 | CFX_WideString swTemp = wstrValue; |
| 919 | swTemp.Replace(L",", L"."); |
| 920 | if (!IsNumber(swTemp.c_str())) { |
| 921 | pEvent->Rc() = FALSE; |
| 922 | sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); |
| 923 | Alert(pContext, sError.c_str()); |
| 924 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 925 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 926 | return TRUE; // it happens after the last keystroke and before validating, |
| 927 | } |
Tom Sepez | 4f7bc04 | 2015-04-27 12:06:58 -0700 | [diff] [blame] | 928 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 929 | std::wstring w_strValue2 = w_strValue.c_str(); |
| 930 | std::wstring w_strChange2 = w_strChange.c_str(); |
| 931 | std::wstring w_strSelected; |
| 932 | if (-1 != pEvent->SelStart()) |
| 933 | w_strSelected = w_strValue2.substr(pEvent->SelStart(), |
| 934 | (pEvent->SelEnd() - pEvent->SelStart())); |
Lei Zhang | b9c3197 | 2015-08-11 14:09:35 -0700 | [diff] [blame] | 935 | bool bHasSign = (w_strValue2.find('-') != std::wstring::npos) && |
| 936 | (w_strSelected.find('-') == std::wstring::npos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 937 | if (bHasSign) { |
| 938 | // can't insert "change" in front to sign postion. |
| 939 | if (pEvent->SelStart() == 0) { |
| 940 | FX_BOOL& bRc = pEvent->Rc(); |
| 941 | bRc = FALSE; |
| 942 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 943 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 944 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 945 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 946 | char cSep = L'.'; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 947 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 948 | switch (iSepStyle) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 949 | case 0: |
| 950 | case 1: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 951 | cSep = L'.'; |
| 952 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 953 | case 2: |
| 954 | case 3: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | cSep = L','; |
| 956 | break; |
| 957 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 958 | |
Lei Zhang | b9c3197 | 2015-08-11 14:09:35 -0700 | [diff] [blame] | 959 | bool bHasSep = (w_strValue2.find(cSep) != std::wstring::npos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | for (std::wstring::iterator it = w_strChange2.begin(); |
| 961 | it != w_strChange2.end(); it++) { |
| 962 | if (*it == cSep) { |
| 963 | if (bHasSep) { |
| 964 | FX_BOOL& bRc = pEvent->Rc(); |
| 965 | bRc = FALSE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 966 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 967 | } |
| 968 | bHasSep = TRUE; |
| 969 | continue; |
| 970 | } |
| 971 | if (*it == L'-') { |
| 972 | if (bHasSign) { |
| 973 | FX_BOOL& bRc = pEvent->Rc(); |
| 974 | bRc = FALSE; |
| 975 | return TRUE; |
| 976 | } |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 977 | // sign's position is not correct |
| 978 | if (it != w_strChange2.begin()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 979 | FX_BOOL& bRc = pEvent->Rc(); |
| 980 | bRc = FALSE; |
| 981 | return TRUE; |
| 982 | } |
| 983 | if (pEvent->SelStart() != 0) { |
| 984 | FX_BOOL& bRc = pEvent->Rc(); |
| 985 | bRc = FALSE; |
| 986 | return TRUE; |
| 987 | } |
| 988 | bHasSign = TRUE; |
| 989 | continue; |
| 990 | } |
| 991 | |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 992 | if (!FXSYS_iswdigit(*it)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | FX_BOOL& bRc = pEvent->Rc(); |
| 994 | bRc = FALSE; |
| 995 | return TRUE; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | std::wstring w_prefix = w_strValue2.substr(0, pEvent->SelStart()); |
| 1000 | std::wstring w_postfix; |
| 1001 | if (pEvent->SelEnd() < (int)w_strValue2.length()) |
| 1002 | w_postfix = w_strValue2.substr(pEvent->SelEnd()); |
| 1003 | w_strValue2 = w_prefix + w_strChange2 + w_postfix; |
| 1004 | w_strValue = w_strValue2.c_str(); |
| 1005 | val = w_strValue; |
| 1006 | return TRUE; |
| 1007 | } |
| 1008 | |
| 1009 | // function AFPercent_Format(nDec, sepStyle) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1010 | FX_BOOL CJS_PublicMethods::AFPercent_Format( |
| 1011 | IJS_Context* cc, |
| 1012 | const std::vector<CJS_Value>& params, |
| 1013 | CJS_Value& vRet, |
| 1014 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1015 | #if _FX_OS_ != _FX_ANDROID_ |
| 1016 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1017 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | |
| 1019 | if (params.size() != 2) { |
| 1020 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1021 | return FALSE; |
| 1022 | } |
| 1023 | if (!pEvent->m_pValue) |
| 1024 | return FALSE; |
| 1025 | |
| 1026 | CFX_WideString& Value = pEvent->Value(); |
| 1027 | CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
| 1028 | if (strValue.IsEmpty()) |
| 1029 | return TRUE; |
| 1030 | |
| 1031 | int iDec = params[0].ToInt(); |
| 1032 | if (iDec < 0) |
| 1033 | iDec = -iDec; |
| 1034 | |
| 1035 | int iSepStyle = params[1].ToInt(); |
| 1036 | if (iSepStyle < 0 || iSepStyle > 3) |
| 1037 | iSepStyle = 0; |
| 1038 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1039 | // for processing decimal places |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 1040 | double dValue = atof(strValue.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1041 | dValue *= 100; |
| 1042 | if (iDec > 0) |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 1043 | dValue += DOUBLE_CORRECT; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1044 | |
| 1045 | int iDec2; |
| 1046 | int iNegative = 0; |
| 1047 | strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| 1048 | if (strValue.IsEmpty()) { |
| 1049 | dValue = 0; |
| 1050 | strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| 1051 | } |
| 1052 | |
| 1053 | if (iDec2 < 0) { |
| 1054 | for (int iNum = 0; iNum < abs(iDec2); iNum++) { |
| 1055 | strValue = "0" + strValue; |
| 1056 | } |
| 1057 | iDec2 = 0; |
| 1058 | } |
| 1059 | int iMax = strValue.GetLength(); |
| 1060 | if (iDec2 > iMax) { |
| 1061 | for (int iNum = 0; iNum <= iDec2 - iMax; iNum++) { |
| 1062 | strValue += "0"; |
| 1063 | } |
| 1064 | iMax = iDec2 + 1; |
| 1065 | } |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 1066 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1067 | // for processing seperator style |
| 1068 | if (iDec2 < iMax) { |
| 1069 | if (iSepStyle == 0 || iSepStyle == 1) { |
| 1070 | strValue.Insert(iDec2, '.'); |
| 1071 | iMax++; |
| 1072 | } else if (iSepStyle == 2 || iSepStyle == 3) { |
| 1073 | strValue.Insert(iDec2, ','); |
| 1074 | iMax++; |
| 1075 | } |
| 1076 | |
| 1077 | if (iDec2 == 0) |
| 1078 | strValue.Insert(iDec2, '0'); |
| 1079 | } |
| 1080 | if (iSepStyle == 0 || iSepStyle == 2) { |
| 1081 | char cSeperator; |
| 1082 | if (iSepStyle == 0) |
| 1083 | cSeperator = ','; |
| 1084 | else |
| 1085 | cSeperator = '.'; |
| 1086 | |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1087 | for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1088 | strValue.Insert(iDecPositive, cSeperator); |
| 1089 | iMax++; |
| 1090 | } |
| 1091 | } |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 1092 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1093 | // negative mark |
| 1094 | if (iNegative) |
| 1095 | strValue = "-" + strValue; |
| 1096 | strValue += "%"; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1097 | Value = CFX_WideString::FromLocal(strValue.AsStringC()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1098 | #endif |
| 1099 | return TRUE; |
| 1100 | } |
| 1101 | // AFPercent_Keystroke(nDec, sepStyle) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1102 | FX_BOOL CJS_PublicMethods::AFPercent_Keystroke( |
| 1103 | IJS_Context* cc, |
| 1104 | const std::vector<CJS_Value>& params, |
| 1105 | CJS_Value& vRet, |
| 1106 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | return AFNumber_Keystroke(cc, params, vRet, sError); |
| 1108 | } |
| 1109 | |
| 1110 | // function AFDate_FormatEx(cFormat) |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1111 | FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1112 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1113 | CJS_Value& vRet, |
| 1114 | CFX_WideString& sError) { |
| 1115 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1116 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1117 | |
| 1118 | if (params.size() != 1) { |
| 1119 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1120 | return FALSE; |
| 1121 | } |
| 1122 | if (!pEvent->m_pValue) |
| 1123 | return FALSE; |
| 1124 | |
| 1125 | CFX_WideString& val = pEvent->Value(); |
| 1126 | CFX_WideString strValue = val; |
| 1127 | if (strValue.IsEmpty()) |
| 1128 | return TRUE; |
| 1129 | |
| 1130 | CFX_WideString sFormat = params[0].ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1131 | double dDate = 0.0f; |
| 1132 | |
| 1133 | if (strValue.Find(L"GMT") != -1) { |
| 1134 | // for GMT format time |
| 1135 | // such as "Tue Aug 11 14:24:16 GMT+08002009" |
| 1136 | dDate = MakeInterDate(strValue); |
| 1137 | } else { |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 1138 | dDate = MakeRegularDate(strValue, sFormat, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | if (JS_PortIsNan(dDate)) { |
| 1142 | CFX_WideString swMsg; |
| 1143 | swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
| 1144 | sFormat.c_str()); |
| 1145 | Alert(pContext, swMsg.c_str()); |
| 1146 | return FALSE; |
| 1147 | } |
| 1148 | |
| 1149 | val = MakeFormatDate(dDate, sFormat); |
| 1150 | return TRUE; |
| 1151 | } |
| 1152 | |
tsepez | 745611b | 2016-04-12 16:46:34 -0700 | [diff] [blame] | 1153 | double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 1154 | std::vector<CFX_WideString> wsArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1155 | CFX_WideString sTemp = L""; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1156 | for (int i = 0; i < strValue.GetLength(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1157 | FX_WCHAR c = strValue.GetAt(i); |
| 1158 | if (c == L' ' || c == L':') { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 1159 | wsArray.push_back(sTemp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1160 | sTemp = L""; |
| 1161 | continue; |
| 1162 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1163 | sTemp += c; |
| 1164 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 1165 | wsArray.push_back(sTemp); |
| 1166 | if (wsArray.size() != 8) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1167 | return 0; |
| 1168 | |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1169 | int nMonth = 1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1170 | sTemp = wsArray[1]; |
| 1171 | if (sTemp.Compare(L"Jan") == 0) |
| 1172 | nMonth = 1; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1173 | else if (sTemp.Compare(L"Feb") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1174 | nMonth = 2; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1175 | else if (sTemp.Compare(L"Mar") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1176 | nMonth = 3; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1177 | else if (sTemp.Compare(L"Apr") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1178 | nMonth = 4; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1179 | else if (sTemp.Compare(L"May") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1180 | nMonth = 5; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1181 | else if (sTemp.Compare(L"Jun") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1182 | nMonth = 6; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1183 | else if (sTemp.Compare(L"Jul") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | nMonth = 7; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1185 | else if (sTemp.Compare(L"Aug") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1186 | nMonth = 8; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1187 | else if (sTemp.Compare(L"Sep") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1188 | nMonth = 9; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1189 | else if (sTemp.Compare(L"Oct") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1190 | nMonth = 10; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1191 | else if (sTemp.Compare(L"Nov") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1192 | nMonth = 11; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1193 | else if (sTemp.Compare(L"Dec") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1194 | nMonth = 12; |
| 1195 | |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1196 | int nDay = FX_atof(wsArray[2].AsStringC()); |
| 1197 | int nHour = FX_atof(wsArray[3].AsStringC()); |
| 1198 | int nMin = FX_atof(wsArray[4].AsStringC()); |
| 1199 | int nSec = FX_atof(wsArray[5].AsStringC()); |
| 1200 | int nYear = FX_atof(wsArray[7].AsStringC()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1201 | double dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), |
| 1202 | JS_MakeTime(nHour, nMin, nSec, 0)); |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1203 | if (JS_PortIsNan(dRet)) |
tsepez | 018935c | 2016-04-15 13:15:12 -0700 | [diff] [blame^] | 1204 | dRet = JS_DateParse(strValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1205 | |
| 1206 | return dRet; |
| 1207 | } |
| 1208 | |
| 1209 | // AFDate_KeystrokeEx(cFormat) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1210 | FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( |
| 1211 | IJS_Context* cc, |
| 1212 | const std::vector<CJS_Value>& params, |
| 1213 | CJS_Value& vRet, |
| 1214 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1215 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1216 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1217 | |
| 1218 | if (params.size() != 1) { |
| 1219 | sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; |
| 1220 | return FALSE; |
| 1221 | } |
| 1222 | |
| 1223 | if (pEvent->WillCommit()) { |
| 1224 | if (!pEvent->m_pValue) |
| 1225 | return FALSE; |
| 1226 | CFX_WideString strValue = pEvent->Value(); |
| 1227 | if (strValue.IsEmpty()) |
| 1228 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1229 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1230 | CFX_WideString sFormat = params[0].ToCFXWideString(); |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 1231 | bool bWrongFormat = FALSE; |
| 1232 | double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1233 | if (bWrongFormat || JS_PortIsNan(dRet)) { |
| 1234 | CFX_WideString swMsg; |
| 1235 | swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
| 1236 | sFormat.c_str()); |
| 1237 | Alert(pContext, swMsg.c_str()); |
| 1238 | pEvent->Rc() = FALSE; |
| 1239 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1240 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1241 | } |
| 1242 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1245 | FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1246 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1247 | CJS_Value& vRet, |
| 1248 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1249 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1250 | if (params.size() != 1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1251 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1252 | return FALSE; |
| 1253 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1254 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1255 | int iIndex = params[0].ToInt(); |
| 1256 | const FX_WCHAR* cFormats[] = {L"m/d", |
| 1257 | L"m/d/yy", |
| 1258 | L"mm/dd/yy", |
| 1259 | L"mm/yy", |
| 1260 | L"d-mmm", |
| 1261 | L"d-mmm-yy", |
| 1262 | L"dd-mmm-yy", |
| 1263 | L"yy-mm-dd", |
| 1264 | L"mmm-yy", |
| 1265 | L"mmmm-yy", |
| 1266 | L"mmm d, yyyy", |
| 1267 | L"mmmm d, yyyy", |
| 1268 | L"m/d/yy h:MM tt", |
| 1269 | L"m/d/yy HH:MM"}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1270 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1271 | if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1272 | iIndex = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1273 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1274 | std::vector<CJS_Value> newParams; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1275 | newParams.push_back( |
| 1276 | CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1277 | return AFDate_FormatEx(cc, newParams, vRet, sError); |
| 1278 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 1279 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1280 | // AFDate_KeystrokeEx(cFormat) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1281 | FX_BOOL CJS_PublicMethods::AFDate_Keystroke( |
| 1282 | IJS_Context* cc, |
| 1283 | const std::vector<CJS_Value>& params, |
| 1284 | CJS_Value& vRet, |
| 1285 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1286 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1287 | if (params.size() != 1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1288 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1289 | return FALSE; |
| 1290 | } |
| 1291 | |
| 1292 | int iIndex = params[0].ToInt(); |
| 1293 | const FX_WCHAR* cFormats[] = {L"m/d", |
| 1294 | L"m/d/yy", |
| 1295 | L"mm/dd/yy", |
| 1296 | L"mm/yy", |
| 1297 | L"d-mmm", |
| 1298 | L"d-mmm-yy", |
| 1299 | L"dd-mmm-yy", |
| 1300 | L"yy-mm-dd", |
| 1301 | L"mmm-yy", |
| 1302 | L"mmmm-yy", |
| 1303 | L"mmm d, yyyy", |
| 1304 | L"mmmm d, yyyy", |
| 1305 | L"m/d/yy h:MM tt", |
| 1306 | L"m/d/yy HH:MM"}; |
| 1307 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1308 | if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1309 | iIndex = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1310 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1311 | std::vector<CJS_Value> newParams; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1312 | newParams.push_back( |
| 1313 | CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1314 | return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
| 1315 | } |
| 1316 | |
| 1317 | // function AFTime_Format(ptf) |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1318 | FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1319 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1320 | CJS_Value& vRet, |
| 1321 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1322 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1323 | if (params.size() != 1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1324 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1325 | return FALSE; |
| 1326 | } |
| 1327 | |
| 1328 | int iIndex = params[0].ToInt(); |
| 1329 | const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| 1330 | L"h:MM:ss tt"}; |
| 1331 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1332 | if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1333 | iIndex = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1334 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1335 | std::vector<CJS_Value> newParams; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1336 | newParams.push_back( |
| 1337 | CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1338 | return AFDate_FormatEx(cc, newParams, vRet, sError); |
| 1339 | } |
| 1340 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1341 | FX_BOOL CJS_PublicMethods::AFTime_Keystroke( |
| 1342 | IJS_Context* cc, |
| 1343 | const std::vector<CJS_Value>& params, |
| 1344 | CJS_Value& vRet, |
| 1345 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1346 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1347 | if (params.size() != 1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1348 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1349 | return FALSE; |
| 1350 | } |
| 1351 | |
| 1352 | int iIndex = params[0].ToInt(); |
| 1353 | const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| 1354 | L"h:MM:ss tt"}; |
| 1355 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1356 | if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1357 | iIndex = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1358 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1359 | std::vector<CJS_Value> newParams; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1360 | newParams.push_back( |
| 1361 | CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1362 | return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
| 1363 | } |
| 1364 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1365 | FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1366 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1367 | CJS_Value& vRet, |
| 1368 | CFX_WideString& sError) { |
| 1369 | return AFDate_FormatEx(cc, params, vRet, sError); |
| 1370 | } |
| 1371 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1372 | FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx( |
| 1373 | IJS_Context* cc, |
| 1374 | const std::vector<CJS_Value>& params, |
| 1375 | CJS_Value& vRet, |
| 1376 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1377 | return AFDate_KeystrokeEx(cc, params, vRet, sError); |
| 1378 | } |
| 1379 | |
| 1380 | // function AFSpecial_Format(psf) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1381 | FX_BOOL CJS_PublicMethods::AFSpecial_Format( |
| 1382 | IJS_Context* cc, |
| 1383 | const std::vector<CJS_Value>& params, |
| 1384 | CJS_Value& vRet, |
| 1385 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1386 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1387 | |
| 1388 | if (params.size() != 1) { |
| 1389 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1390 | return FALSE; |
| 1391 | } |
| 1392 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1393 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1394 | if (!pEvent->m_pValue) |
| 1395 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1396 | |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1397 | CFX_WideString wsSource = pEvent->Value(); |
| 1398 | CFX_WideString wsFormat; |
| 1399 | switch (params[0].ToInt()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1400 | case 0: |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1401 | wsFormat = L"99999"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1402 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1403 | case 1: |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1404 | wsFormat = L"99999-9999"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1405 | break; |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1406 | case 2: |
| 1407 | if (util::printx(L"9999999999", wsSource).GetLength() >= 10) |
| 1408 | wsFormat = L"(999) 999-9999"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1409 | else |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1410 | wsFormat = L"999-9999"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1411 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1412 | case 3: |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1413 | wsFormat = L"999-99-9999"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1414 | break; |
| 1415 | } |
| 1416 | |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1417 | pEvent->Value() = util::printx(wsFormat, wsSource); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1418 | return TRUE; |
| 1419 | } |
| 1420 | |
| 1421 | // function AFSpecial_KeystrokeEx(mask) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1422 | FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( |
| 1423 | IJS_Context* cc, |
| 1424 | const std::vector<CJS_Value>& params, |
| 1425 | CJS_Value& vRet, |
| 1426 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1427 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1428 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1429 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1430 | if (params.size() < 1) { |
| 1431 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1432 | return FALSE; |
| 1433 | } |
| 1434 | |
| 1435 | if (!pEvent->m_pValue) |
| 1436 | return FALSE; |
| 1437 | CFX_WideString& valEvent = pEvent->Value(); |
| 1438 | |
| 1439 | CFX_WideString wstrMask = params[0].ToCFXWideString(); |
| 1440 | if (wstrMask.IsEmpty()) |
| 1441 | return TRUE; |
| 1442 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1443 | const size_t wstrMaskLen = wstrMask.GetLength(); |
| 1444 | const std::wstring wstrValue = valEvent.c_str(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1445 | |
| 1446 | if (pEvent->WillCommit()) { |
| 1447 | if (wstrValue.empty()) |
| 1448 | return TRUE; |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1449 | size_t iIndexMask = 0; |
| 1450 | for (const auto& w_Value : wstrValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1451 | if (!maskSatisfied(w_Value, wstrMask[iIndexMask])) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1452 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1453 | iIndexMask++; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1454 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 1455 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1456 | if (iIndexMask != wstrMaskLen || |
| 1457 | (iIndexMask != wstrValue.size() && wstrMaskLen != 0)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1458 | Alert( |
| 1459 | pContext, |
| 1460 | JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); |
| 1461 | pEvent->Rc() = FALSE; |
| 1462 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1463 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | CFX_WideString& wideChange = pEvent->Change(); |
| 1467 | std::wstring wChange = wideChange.c_str(); |
| 1468 | if (wChange.empty()) |
| 1469 | return TRUE; |
| 1470 | |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 1471 | size_t iIndexMask = pEvent->SelStart(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1472 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1473 | size_t combined_len = wstrValue.length() + wChange.length() - |
| 1474 | (pEvent->SelEnd() - pEvent->SelStart()); |
| 1475 | if (combined_len > wstrMaskLen) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1476 | Alert(pContext, |
| 1477 | JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
| 1478 | pEvent->Rc() = FALSE; |
| 1479 | return TRUE; |
| 1480 | } |
| 1481 | |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1482 | if (iIndexMask >= wstrMaskLen && (!wChange.empty())) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1483 | Alert(pContext, |
| 1484 | JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
| 1485 | pEvent->Rc() = FALSE; |
| 1486 | return TRUE; |
| 1487 | } |
| 1488 | |
| 1489 | for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) { |
Lei Zhang | a0f6724 | 2015-08-17 15:39:30 -0700 | [diff] [blame] | 1490 | if (iIndexMask >= wstrMaskLen) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1491 | Alert(pContext, |
| 1492 | JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
| 1493 | pEvent->Rc() = FALSE; |
| 1494 | return TRUE; |
| 1495 | } |
| 1496 | wchar_t w_Mask = wstrMask[iIndexMask]; |
| 1497 | if (!isReservedMaskChar(w_Mask)) { |
| 1498 | *it = w_Mask; |
| 1499 | } |
| 1500 | wchar_t w_Change = *it; |
| 1501 | if (!maskSatisfied(w_Change, w_Mask)) { |
| 1502 | pEvent->Rc() = FALSE; |
| 1503 | return TRUE; |
| 1504 | } |
| 1505 | iIndexMask++; |
| 1506 | } |
| 1507 | |
| 1508 | wideChange = wChange.c_str(); |
| 1509 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1512 | // function AFSpecial_Keystroke(psf) |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1513 | FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke( |
| 1514 | IJS_Context* cc, |
| 1515 | const std::vector<CJS_Value>& params, |
| 1516 | CJS_Value& vRet, |
| 1517 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1518 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1519 | if (params.size() != 1) { |
| 1520 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1521 | return FALSE; |
| 1522 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1523 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1524 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1525 | if (!pEvent->m_pValue) |
| 1526 | return FALSE; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1527 | |
| 1528 | std::string cFormat; |
| 1529 | int iIndex = params[0].ToInt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1530 | CFX_WideString& val = pEvent->Value(); |
| 1531 | std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); |
| 1532 | std::wstring wstrChange = pEvent->Change().c_str(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1533 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1534 | switch (iIndex) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1535 | case 0: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1536 | cFormat = "99999"; |
| 1537 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1538 | case 1: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1539 | cFormat = "999999999"; |
| 1540 | break; |
tsepez | 4f1f41f | 2016-03-28 14:13:16 -0700 | [diff] [blame] | 1541 | case 2: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1542 | if (strSrc.length() + wstrChange.length() > 7) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1543 | cFormat = "9999999999"; |
| 1544 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1545 | cFormat = "9999999"; |
| 1546 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1547 | case 3: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1548 | cFormat = "999999999"; |
| 1549 | break; |
| 1550 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 1551 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1552 | std::vector<CJS_Value> params2; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1553 | params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1554 | return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1557 | FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1558 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1559 | CJS_Value& vRet, |
| 1560 | CFX_WideString& sError) { |
| 1561 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1562 | CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1563 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1564 | if (params.size() != 1) { |
| 1565 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1566 | return FALSE; |
| 1567 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1568 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1569 | CFX_WideString swValue; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 1570 | if (pEventHandler->m_pValue) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1571 | swValue = pEventHandler->Value(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1572 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1573 | if (pEventHandler->WillCommit()) { |
| 1574 | vRet = swValue.c_str(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1575 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | CFX_WideString prefix, postfix; |
| 1579 | |
| 1580 | if (pEventHandler->SelStart() >= 0) |
| 1581 | prefix = swValue.Mid(0, pEventHandler->SelStart()); |
| 1582 | else |
| 1583 | prefix = L""; |
| 1584 | |
| 1585 | if (pEventHandler->SelEnd() >= 0 && |
| 1586 | pEventHandler->SelEnd() <= swValue.GetLength()) |
| 1587 | postfix = swValue.Mid(pEventHandler->SelEnd(), |
| 1588 | swValue.GetLength() - pEventHandler->SelEnd()); |
| 1589 | else |
| 1590 | postfix = L""; |
| 1591 | |
| 1592 | vRet = (prefix + pEventHandler->Change() + postfix).c_str(); |
| 1593 | |
| 1594 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1597 | FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1598 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1599 | CJS_Value& vRet, |
| 1600 | CFX_WideString& sError) { |
| 1601 | CJS_Context* pContext = (CJS_Context*)cc; |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1602 | ASSERT(pContext); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1603 | |
| 1604 | if (params.size() != 2) { |
| 1605 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1606 | return FALSE; |
| 1607 | } |
| 1608 | |
| 1609 | CFX_WideString sValue = params[0].ToCFXWideString(); |
| 1610 | CFX_WideString sFormat = params[1].ToCFXWideString(); |
| 1611 | |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 1612 | double dDate = MakeRegularDate(sValue, sFormat, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1613 | |
| 1614 | if (JS_PortIsNan(dDate)) { |
| 1615 | CFX_WideString swMsg; |
| 1616 | swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
| 1617 | sFormat.c_str()); |
| 1618 | Alert((CJS_Context*)cc, swMsg.c_str()); |
| 1619 | return FALSE; |
| 1620 | } |
| 1621 | |
| 1622 | vRet = dDate; |
| 1623 | return TRUE; |
| 1624 | } |
| 1625 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1626 | FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1627 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1628 | CJS_Value& vRet, |
| 1629 | CFX_WideString& sError) { |
| 1630 | if (params.size() != 3) { |
| 1631 | CJS_Context* pContext = (CJS_Context*)cc; |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1632 | ASSERT(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1633 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1634 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1635 | return FALSE; |
| 1636 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1637 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1638 | vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), |
| 1639 | params[1].ToDouble(), params[2].ToDouble()); |
| 1640 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1641 | } |
| 1642 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1643 | FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1644 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1645 | CJS_Value& vRet, |
| 1646 | CFX_WideString& sError) { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1647 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1648 | if (params.size() != 1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1649 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1650 | return FALSE; |
| 1651 | } |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1652 | CFX_WideString ws = params[0].ToCFXWideString(); |
| 1653 | ws.Replace(L",", L"."); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1654 | vRet = ws.c_str(); |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1655 | vRet.MaybeCoerceToNumber(); |
| 1656 | if (vRet.GetType() != CJS_Value::VT_number) |
| 1657 | vRet = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1658 | return TRUE; |
| 1659 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1660 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1661 | FX_BOOL CJS_PublicMethods::AFSimple_Calculate( |
| 1662 | IJS_Context* cc, |
| 1663 | const std::vector<CJS_Value>& params, |
| 1664 | CJS_Value& vRet, |
| 1665 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1666 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1667 | if (params.size() != 2) { |
| 1668 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1669 | return FALSE; |
| 1670 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1671 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1672 | CJS_Value params1 = params[1]; |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1673 | if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1674 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1675 | return FALSE; |
| 1676 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1677 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1678 | CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1679 | CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1680 | CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1681 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1682 | CFX_WideString sFunction = params[0].ToCFXWideString(); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1683 | double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1684 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1685 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1686 | CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1687 | int nFieldsCount = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1688 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1689 | for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1690 | CJS_Value jsValue(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1691 | FieldNameArray.GetElement(i, jsValue); |
| 1692 | CFX_WideString wsFieldName = jsValue.ToCFXWideString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1693 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1694 | for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { |
| 1695 | if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { |
| 1696 | double dTemp = 0.0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1697 | switch (pFormField->GetFieldType()) { |
| 1698 | case FIELDTYPE_TEXTFIELD: |
| 1699 | case FIELDTYPE_COMBOBOX: { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1700 | CFX_WideString trimmed = pFormField->GetValue(); |
| 1701 | trimmed.TrimRight(); |
| 1702 | trimmed.TrimLeft(); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1703 | dTemp = FX_atof(trimmed.AsStringC()); |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1704 | } break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1705 | case FIELDTYPE_PUSHBUTTON: { |
| 1706 | dTemp = 0.0; |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1707 | } break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1708 | case FIELDTYPE_CHECKBOX: |
| 1709 | case FIELDTYPE_RADIOBUTTON: { |
| 1710 | dTemp = 0.0; |
| 1711 | for (int c = 0, csz = pFormField->CountControls(); c < csz; c++) { |
| 1712 | if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c)) { |
| 1713 | if (pFormCtrl->IsChecked()) { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1714 | CFX_WideString trimmed = pFormCtrl->GetExportValue(); |
| 1715 | trimmed.TrimRight(); |
| 1716 | trimmed.TrimLeft(); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1717 | dTemp = FX_atof(trimmed.AsStringC()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1718 | break; |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 1719 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1720 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1721 | } |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1722 | } break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1723 | case FIELDTYPE_LISTBOX: { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1724 | if (pFormField->CountSelectedItems() <= 1) { |
| 1725 | CFX_WideString trimmed = pFormField->GetValue(); |
| 1726 | trimmed.TrimRight(); |
| 1727 | trimmed.TrimLeft(); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1728 | dTemp = FX_atof(trimmed.AsStringC()); |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 1729 | } |
| 1730 | } break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1731 | default: |
| 1732 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1733 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1734 | |
| 1735 | if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || |
| 1736 | wcscmp(sFunction.c_str(), L"MAX") == 0)) |
| 1737 | dValue = dTemp; |
| 1738 | |
| 1739 | dValue = AF_Simple(sFunction.c_str(), dValue, dTemp); |
| 1740 | |
| 1741 | nFieldsCount++; |
| 1742 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1743 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1744 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1745 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1746 | if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) |
| 1747 | dValue /= nFieldsCount; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1748 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1749 | dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / |
| 1750 | FXSYS_pow((double)10, (double)6); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1751 | CJS_Value jsValue(pRuntime, dValue); |
foxit | 8b544ed | 2015-09-10 14:57:54 +0800 | [diff] [blame] | 1752 | if (pContext->GetEventHandler()->m_pValue) |
| 1753 | pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1754 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1755 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 1758 | /* This function validates the current event to ensure that its value is |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1759 | ** within the specified range. */ |
| 1760 | |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1761 | FX_BOOL CJS_PublicMethods::AFRange_Validate( |
| 1762 | IJS_Context* cc, |
| 1763 | const std::vector<CJS_Value>& params, |
| 1764 | CJS_Value& vRet, |
| 1765 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1766 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1767 | CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1768 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1769 | if (params.size() != 4) { |
| 1770 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1771 | return FALSE; |
| 1772 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1773 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1774 | if (!pEvent->m_pValue) |
| 1775 | return FALSE; |
| 1776 | if (pEvent->Value().IsEmpty()) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1777 | return TRUE; |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 1778 | double dEentValue = |
| 1779 | atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1780 | FX_BOOL bGreaterThan = params[0].ToBool(); |
| 1781 | double dGreaterThan = params[1].ToDouble(); |
| 1782 | FX_BOOL bLessThan = params[2].ToBool(); |
| 1783 | double dLessThan = params[3].ToDouble(); |
| 1784 | CFX_WideString swMsg; |
| 1785 | |
| 1786 | if (bGreaterThan && bLessThan) { |
| 1787 | if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
| 1788 | swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), |
| 1789 | params[1].ToCFXWideString().c_str(), |
| 1790 | params[3].ToCFXWideString().c_str()); |
| 1791 | } else if (bGreaterThan) { |
| 1792 | if (dEentValue < dGreaterThan) |
| 1793 | swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), |
| 1794 | params[1].ToCFXWideString().c_str()); |
| 1795 | } else if (bLessThan) { |
| 1796 | if (dEentValue > dLessThan) |
| 1797 | swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), |
| 1798 | params[3].ToCFXWideString().c_str()); |
| 1799 | } |
| 1800 | |
| 1801 | if (!swMsg.IsEmpty()) { |
| 1802 | Alert(pContext, swMsg.c_str()); |
| 1803 | pEvent->Rc() = FALSE; |
| 1804 | } |
| 1805 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1808 | FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1809 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1810 | CJS_Value& vRet, |
| 1811 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1812 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1813 | if (params.size() != 1) { |
| 1814 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1815 | return FALSE; |
| 1816 | } |
| 1817 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1818 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1819 | CJS_Array nums(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1820 | |
| 1821 | CFX_WideString str = params[0].ToCFXWideString(); |
| 1822 | CFX_WideString sPart; |
| 1823 | |
| 1824 | if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
| 1825 | str = L"0" + str; |
| 1826 | |
| 1827 | int nIndex = 0; |
| 1828 | for (int i = 0, sz = str.GetLength(); i < sz; i++) { |
| 1829 | FX_WCHAR wc = str.GetAt(i); |
Lei Zhang | 9559b7a | 2015-12-21 11:12:20 -0800 | [diff] [blame] | 1830 | if (FXSYS_iswdigit(wc)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1831 | sPart += wc; |
| 1832 | } else { |
| 1833 | if (sPart.GetLength() > 0) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1834 | nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1835 | sPart = L""; |
| 1836 | nIndex++; |
| 1837 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1838 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1839 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1840 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1841 | if (sPart.GetLength() > 0) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1842 | nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1843 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1844 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1845 | if (nums.GetLength() > 0) |
| 1846 | vRet = nums; |
| 1847 | else |
| 1848 | vRet.SetNull(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1849 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1850 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1851 | } |