Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: fpdfsdk/src/javascript/PublicMethods.cpp

Issue 1239313005: Merge to XFA - else after returns. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Fix issues. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | fpdfsdk/src/javascript/global.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
11 #include "../../include/javascript/JS_Value.h" 11 #include "../../include/javascript/JS_Value.h"
12 #include "../../include/javascript/PublicMethods.h" 12 #include "../../include/javascript/PublicMethods.h"
13 #include "../../include/javascript/JS_EventHandler.h" 13 #include "../../include/javascript/JS_EventHandler.h"
14 #include "../../include/javascript/resource.h" 14 #include "../../include/javascript/resource.h"
15 #include "../../include/javascript/JS_Context.h" 15 #include "../../include/javascript/JS_Context.h"
16 #include "../../include/javascript/JS_Value.h" 16 #include "../../include/javascript/JS_Value.h"
17 #include "../../include/javascript/util.h" 17 #include "../../include/javascript/util.h"
18 #include "../../include/javascript/Field.h" 18 #include "../../include/javascript/Field.h"
19 #include "../../include/javascript/color.h" 19 #include "../../include/javascript/color.h"
20 #include "../../include/javascript/JS_Runtime.h" 20 #include "../../include/javascript/JS_Runtime.h"
21 21
22 static v8::Isolate* GetIsolate(IFXJS_Context* cc) 22 static v8::Isolate* GetIsolate(IFXJS_Context* cc)
23 { 23 {
24 » CJS_Context* pContext = (CJS_Context *)cc; 24 CJS_Context* pContext = (CJS_Context *)cc;
25 » ASSERT(pContext != NULL); 25 ASSERT(pContext != NULL);
26 26
27 » CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 27 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
28 » ASSERT(pRuntime != NULL); 28 ASSERT(pRuntime != NULL);
29 29
30 » return pRuntime->GetIsolate(); 30 return pRuntime->GetIsolate();
31 } 31 }
32 32
33 33
34 /* -------------------------------- CJS_PublicMethods -------------------------- ------ */ 34 /* -------------------------------- CJS_PublicMethods -------------------------- ------ */
35 35
36 #define DOUBLE_CORRECT» 0.000000000000001 36 #define DOUBLE_CORRECT 0.000000000000001
37 37
38 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) 38 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
39 » JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) 39 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format)
40 » JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) 40 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke)
41 » JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) 41 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format)
42 » JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke) 42 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke)
43 » JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx) 43 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx)
44 » JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx) 44 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx)
45 » JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format) 45 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format)
46 » JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke) 46 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke)
47 » JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx) 47 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx)
48 » JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx) 48 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx)
49 » JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format) 49 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format)
50 » JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke) 50 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke)
51 » JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format) 51 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format)
52 » JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke) 52 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke)
53 » JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx) 53 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx)
54 » JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple) 54 JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple)
55 » JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber) 55 JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber)
56 » JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate) 56 JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate)
57 » JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate) 57 JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate)
58 » JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange) 58 JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange)
59 » JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx) 59 JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx)
60 » JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums) 60 JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums)
61 END_JS_STATIC_GLOBAL_FUN() 61 END_JS_STATIC_GLOBAL_FUN()
62 62
63 IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) 63 IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
64 64
65 static const FX_WCHAR* months[] = 65 static const FX_WCHAR* months[] =
66 { 66 {
67 » L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" 67 L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oc t", L"Nov", L"Dec"
68 }; 68 };
69 69
70 static const FX_WCHAR* const fullmonths[] = 70 static const FX_WCHAR* const fullmonths[] =
71 { 71 {
72 » L"January", L"February", L"March", L"April", L"May", L"June", L"July", L "August", L"September", L"October", L"November", L"December" 72 L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"Aug ust", L"September", L"October", L"November", L"December"
73 }; 73 };
74 74
75 FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string) 75 FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string)
76 { 76 {
77 » CFX_WideString sTrim = StrTrim(string); 77 CFX_WideString sTrim = StrTrim(string);
78 » const FX_WCHAR* pTrim = sTrim.c_str(); 78 const FX_WCHAR* pTrim = sTrim.c_str();
79 » const FX_WCHAR* p = pTrim; 79 const FX_WCHAR* p = pTrim;
80 80
81 81
82 » FX_BOOL bDot = FALSE; 82 FX_BOOL bDot = FALSE;
83 » FX_BOOL bKXJS = FALSE; 83 FX_BOOL bKXJS = FALSE;
84 84
85 » wchar_t c; 85 wchar_t c;
86 » while ((c = *p)) 86 while ((c = *p))
87 » { 87 {
88 » » if (c == '.' || c == ',') 88 if (c == '.' || c == ',')
89 » » { 89 {
90 » » » if (bDot) return FALSE; 90 if (bDot) return FALSE;
91 » » » bDot = TRUE; 91 bDot = TRUE;
92 » » } 92 }
93 » » else if (c == '-' || c == '+') 93 else if (c == '-' || c == '+')
94 » » { 94 {
95 » » » if (p != pTrim) 95 if (p != pTrim)
96 » » » » return FALSE; 96 return FALSE;
97 » » } 97 }
98 » » else if (c == 'e' || c == 'E') 98 else if (c == 'e' || c == 'E')
99 » » { 99 {
100 » » » if (bKXJS) return FALSE; 100 if (bKXJS)
101 return FALSE;
101 102
102 » » » p++; 103 p++;
103 » » » c = *p; 104 c = *p;
104 » » » if (c == '+' || c == '-') 105 if (c == '+' || c == '-')
105 » » » { 106 {
106 » » » » bKXJS = TRUE; 107 bKXJS = TRUE;
107 » » » } 108 }
108 » » » else 109 else
109 » » » { 110 {
110 » » » » return FALSE; 111 return FALSE;
111 » » » } 112 }
112 » » } 113 }
113 » » else if (!IsDigit(c)) 114 else if (!IsDigit(c))
114 » » { 115 {
115 » » » return FALSE; 116 return FALSE;
116 » » } 117 }
117 » » p++; 118 p++;
118 » } 119 }
119 120
120 » return TRUE; 121 return TRUE;
121 } 122 }
122 123
123 FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) 124 FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch)
124 { 125 {
125 » return (ch >= L'0' && ch <= L'9'); 126 return (ch >= L'0' && ch <= L'9');
126 } 127 }
127 128
128 FX_BOOL CJS_PublicMethods::IsDigit(char ch) 129 FX_BOOL CJS_PublicMethods::IsDigit(char ch)
129 { 130 {
130 » return (ch >= '0' && ch <= '9'); 131 return (ch >= '0' && ch <= '9');
131 } 132 }
132 133
133 FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) 134 FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch)
134 { 135 {
135 » return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z')); 136 return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
136 } 137 }
137 138
138 FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch) 139 FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch)
139 { 140 {
140 » return (IsDigit(ch) || IsAlphabetic(ch)); 141 return (IsDigit(ch) || IsAlphabetic(ch));
141 } 142 }
142 143
143 FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask) 144 FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
144 { 145 {
145 » switch (c_Mask) 146 switch (c_Mask)
146 » { 147 {
147 » case L'9': 148 case L'9':
148 return IsDigit(c_Change); 149 return IsDigit(c_Change);
149 case L'A': 150 case L'A':
150 return IsAlphabetic(c_Change); 151 return IsAlphabetic(c_Change);
151 case L'O': 152 case L'O':
152 return IsAlphaNumeric(c_Change); 153 return IsAlphaNumeric(c_Change);
153 case L'X': 154 case L'X':
154 return TRUE; 155 return TRUE;
155 » default: 156 default:
156 return (c_Change == c_Mask); 157 return (c_Change == c_Mask);
157 » } 158 }
158 } 159 }
159 160
160 FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch) 161 FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch)
161 { 162 {
162 » return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X'; 163 return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
163 } 164 }
164 165
165 double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, double dValue1, do uble dValue2) 166 double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, double dValue1, do uble dValue2)
166 { 167 {
167 » if (FXSYS_wcsicmp(sFuction,L"AVG") == 0 || FXSYS_wcsicmp(sFuction,L"SUM" ) == 0) 168 if (FXSYS_wcsicmp(sFuction,L"AVG") == 0 || FXSYS_wcsicmp(sFuction,L"SUM") == 0)
168 » { 169 {
169 » » return dValue1 + dValue2; 170 return dValue1 + dValue2;
170 » } 171 }
171 » else if (FXSYS_wcsicmp(sFuction, L"PRD") == 0) 172 if (FXSYS_wcsicmp(sFuction, L"PRD") == 0)
172 » { 173 {
173 » » return dValue1 * dValue2; 174 return dValue1 * dValue2;
174 » } 175 }
175 » else if (FXSYS_wcsicmp(sFuction,L"MIN") == 0) 176 if (FXSYS_wcsicmp(sFuction,L"MIN") == 0)
176 » { 177 {
177 » » return FX_MIN(dValue1, dValue2); 178 return FX_MIN(dValue1, dValue2);
178 » } 179 }
179 » else if (FXSYS_wcsicmp(sFuction,L"MAX") == 0) 180 if (FXSYS_wcsicmp(sFuction,L"MAX") == 0)
180 » { 181 {
181 » » return FX_MAX(dValue1, dValue2); 182 return FX_MAX(dValue1, dValue2);
182 » } 183 }
183 184 return dValue1;
184 » return dValue1;
185 } 185 }
186 186
187 CFX_WideString CJS_PublicMethods::StrLTrim(const FX_WCHAR* pStr) 187 CFX_WideString CJS_PublicMethods::StrLTrim(const FX_WCHAR* pStr)
188 { 188 {
189 » while (*pStr && *pStr == L' ') pStr++; 189 while (*pStr && *pStr == L' ') pStr++;
190 190
191 » return pStr; 191 return pStr;
192 } 192 }
193 193
194 CFX_WideString CJS_PublicMethods::StrRTrim(const FX_WCHAR* pStr) 194 CFX_WideString CJS_PublicMethods::StrRTrim(const FX_WCHAR* pStr)
195 { 195 {
196 » const FX_WCHAR* p = pStr; 196 const FX_WCHAR* p = pStr;
197 » while (*p) p++; 197 while (*p) p++;
198 » while (p > pStr && *(p - 1) == L' ') p--; 198 while (p > pStr && *(p - 1) == L' ') p--;
199 199
200 » return CFX_WideString(pStr, p - pStr); 200 return CFX_WideString(pStr, p - pStr);
201 } 201 }
202 202
203 CFX_WideString CJS_PublicMethods::StrTrim(const FX_WCHAR* pStr) 203 CFX_WideString CJS_PublicMethods::StrTrim(const FX_WCHAR* pStr)
204 { 204 {
205 » return StrRTrim(StrLTrim(pStr).c_str()); 205 return StrRTrim(StrLTrim(pStr).c_str());
206 } 206 }
207 207
208 CFX_ByteString CJS_PublicMethods::StrLTrim(const FX_CHAR* pStr) 208 CFX_ByteString CJS_PublicMethods::StrLTrim(const FX_CHAR* pStr)
209 { 209 {
210 » while (*pStr && *pStr == ' ') pStr++; 210 while (*pStr && *pStr == ' ') pStr++;
211 211
212 return pStr; 212 return pStr;
213 } 213 }
214 214
215 CFX_ByteString CJS_PublicMethods::StrRTrim(const FX_CHAR* pStr) 215 CFX_ByteString CJS_PublicMethods::StrRTrim(const FX_CHAR* pStr)
216 { 216 {
217 » const FX_CHAR* p = pStr; 217 const FX_CHAR* p = pStr;
218 » while (*p) p++; 218 while (*p) p++;
219 » while (p > pStr && *(p - 1) == L' ') p--; 219 while (p > pStr && *(p - 1) == L' ') p--;
220 220
221 » return CFX_ByteString(pStr,p-pStr); 221 return CFX_ByteString(pStr,p-pStr);
222 } 222 }
223 223
224 CFX_ByteString CJS_PublicMethods::StrTrim(const FX_CHAR* pStr) 224 CFX_ByteString CJS_PublicMethods::StrTrim(const FX_CHAR* pStr)
225 { 225 {
226 » return StrRTrim(StrLTrim(pStr)); 226 return StrRTrim(StrLTrim(pStr));
227 } 227 }
228 228
229 double CJS_PublicMethods::ParseNumber(const FX_WCHAR* swSource, FX_BOOL& bAllDig its, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS) 229 double CJS_PublicMethods::ParseNumber(const FX_WCHAR* swSource, FX_BOOL& bAllDig its, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
230 { 230 {
231 » bDot = FALSE; 231 bDot = FALSE;
232 » bSign = FALSE; 232 bSign = FALSE;
233 » bKXJS = FALSE; 233 bKXJS = FALSE;
234 234
235 » FX_BOOL bDigitExist = FALSE; 235 FX_BOOL bDigitExist = FALSE;
236 236
237 » const FX_WCHAR* p = swSource; 237 const FX_WCHAR* p = swSource;
238 » wchar_t c; 238 wchar_t c;
239 239
240 » const FX_WCHAR* pStart = NULL; 240 const FX_WCHAR* pStart = NULL;
241 » const FX_WCHAR* pEnd = NULL; 241 const FX_WCHAR* pEnd = NULL;
242 242
243 » while ((c = *p)) 243 while ((c = *p))
244 » { 244 {
245 » » if (!pStart && c != L' ') 245 if (!pStart && c != L' ')
246 » » { 246 {
247 » » » pStart = p; 247 pStart = p;
248 » » } 248 }
249 249
250 » » pEnd = p; 250 pEnd = p;
251 » » p++; 251 p++;
252 » } 252 }
253 253
254 » if (!pStart) 254 if (!pStart)
255 » { 255 {
256 » » bAllDigits = FALSE; 256 bAllDigits = FALSE;
257 » » return 0; 257 return 0;
258 » } 258 }
259 259
260 » while (pEnd != pStart) 260 while (pEnd != pStart)
261 » { 261 {
262 » » if (*pEnd == L' ') 262 if (*pEnd == L' ')
263 » » » pEnd --; 263 pEnd --;
264 » » else 264 else
265 » » » break; 265 break;
266 » } 266 }
267 267
268 » double dRet = 0; 268 double dRet = 0;
269 » p = pStart; 269 p = pStart;
270 » bAllDigits = TRUE; 270 bAllDigits = TRUE;
271 » CFX_WideString swDigits; 271 CFX_WideString swDigits;
272 272
273 » while (p <= pEnd) 273 while (p <= pEnd)
274 » { 274 {
275 » » c = *p; 275 c = *p;
276 276
277 » » if (IsDigit(c)) 277 if (IsDigit(c))
278 » » { 278 {
279 » » » swDigits += c; 279 swDigits += c;
280 » » » bDigitExist = TRUE; 280 bDigitExist = TRUE;
281 » » } 281 }
282 » » else 282 else
283 » » { 283 {
284 » » » switch (c) 284 switch (c)
285 » » » { 285 {
286 » » » case L' ': 286 case L' ':
287 » » » » bAllDigits = FALSE; 287 bAllDigits = FALSE;
288 » » » » break; 288 break;
289 » » » case L'.': 289 case L'.':
290 » » » case L',': 290 case L',':
291 » » » » if (!bDot) 291 if (!bDot)
292 » » » » { 292 {
293 » » » » » if (bDigitExist) 293 if (bDigitExist)
294 » » » » » { 294 {
295 » » » » » » swDigits += L'.'; 295 swDigits += L'.';
296 » » » » » } 296 }
297 » » » » » else 297 else
298 » » » » » { 298 {
299 » » » » » » swDigits += L'0'; 299 swDigits += L'0';
300 » » » » » » swDigits += L'.'; 300 swDigits += L'.';
301 » » » » » » bDigitExist = TRUE; 301 bDigitExist = TRUE;
302 » » » » » } 302 }
303 303
304 » » » » » bDot = TRUE; 304 bDot = TRUE;
305 » » » » » break; 305 break;
306 » » » » } 306 }
307 » » » case 'e': 307 case 'e':
308 » » » case 'E': 308 case 'E':
309 » » » » if (!bKXJS) 309 if (!bKXJS)
310 » » » » { 310 {
311 » » » » » p++; 311 p++;
312 » » » » » c = *p; 312 c = *p;
313 » » » » » if (c == '+' || c == '-') 313 if (c == '+' || c == '-')
314 » » » » » { 314 {
315 » » » » » » bKXJS = TRUE; 315 bKXJS = TRUE;
316 » » » » » » swDigits += 'e'; 316 swDigits += 'e';
317 » » » » » » swDigits += c; 317 swDigits += c;
318 » » » » » } 318 }
319 » » » » » break; 319 break;
320 » » » » } 320 }
321 » » » case L'-': 321 case L'-':
322 » » » » if (!bDigitExist && !bSign) 322 if (!bDigitExist && !bSign)
323 » » » » { 323 {
324 » » » » » swDigits += c; 324 swDigits += c;
325 » » » » » bSign = TRUE; 325 bSign = TRUE;
326 » » » » » break; 326 break;
327 » » » » } 327 }
328 » » » default: 328 default:
329 » » » » bAllDigits = FALSE; 329 bAllDigits = FALSE;
330 330
331 » » » » if (p != pStart && !bDot && bDigitExist) 331 if (p != pStart && !bDot && bDigitExist)
332 » » » » { 332 {
333 » » » » » swDigits += L'.'; 333 swDigits += L'.';
334 » » » » » bDot = TRUE; 334 bDot = TRUE;
335 » » » » } 335 }
336 » » » » else 336 else
337 » » » » { 337 {
338 » » » » » bDot = FALSE; 338 bDot = FALSE;
339 » » » » » bDigitExist = FALSE; 339 bDigitExist = FALSE;
340 » » » » » swDigits = L""; 340 swDigits = L"";
341 » » » » } 341 }
342 » » » » break; 342 break;
343 » » » } 343 }
344 » » } 344 }
345 345
346 » » p++; 346 p++;
347 » } 347 }
348 348
349 » if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17) 349 if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
350 » { 350 {
351 » » CFX_ByteString sDigits = swDigits.UTF8Encode(); 351 CFX_ByteString sDigits = swDigits.UTF8Encode();
352 352
353 » » if (bKXJS) 353 if (bKXJS)
354 » » { 354 {
355 » » » dRet = atof(sDigits); 355 dRet = atof(sDigits);
356 » » } 356 }
357 » » else 357 else
358 » » { 358 {
359 » » » if (bDot) 359 if (bDot)
360 » » » { 360 {
361 » » » » char* pStopString; 361 char* pStopString;
362 » » » » dRet = ::strtod(sDigits, &pStopString); 362 dRet = ::strtod(sDigits, &pStopString);
363 » » » } 363 }
364 » » » else 364 else
365 » » » { 365 {
366 » » » » dRet = atol(sDigits); 366 dRet = atol(sDigits);
367 » » » } 367 }
368 » » } 368 }
369 369
370 » } 370 }
371 371
372 » return dRet; 372 return dRet;
373 } 373 }
374 374
375 double CJS_PublicMethods::ParseStringToNumber(const FX_WCHAR* swSource) 375 double CJS_PublicMethods::ParseStringToNumber(const FX_WCHAR* swSource)
376 { 376 {
377 » FX_BOOL bAllDigits = FALSE; 377 FX_BOOL bAllDigits = FALSE;
378 » FX_BOOL bDot = FALSE; 378 FX_BOOL bDot = FALSE;
379 » FX_BOOL bSign = FALSE; 379 FX_BOOL bSign = FALSE;
380 » FX_BOOL bKXJS = FALSE; 380 FX_BOOL bKXJS = FALSE;
381 381
382 » return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); 382 return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
383 } 383 }
384 384
385 FX_BOOL»CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource, doubl e & dRet, FX_BOOL & bDot) 385 FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource, doubl e & dRet, FX_BOOL & bDot)
386 { 386 {
387 » FX_BOOL bAllDigits = FALSE; 387 FX_BOOL bAllDigits = FALSE;
388 » FX_BOOL bSign = FALSE; 388 FX_BOOL bSign = FALSE;
389 » FX_BOOL bKXJS = FALSE; 389 FX_BOOL bKXJS = FALSE;
390 390
391 » dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); 391 dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
392 392
393 » return bAllDigits; 393 return bAllDigits;
394 } 394 }
395 395
396 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Valu e val) 396 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Valu e val)
397 { 397 {
398 » CJS_Array StrArray(isolate); 398 CJS_Array StrArray(isolate);
399 » if(val.IsArrayObject()) 399 if(val.IsArrayObject())
400 » { 400 {
401 » » val.ConvertToArray(StrArray); 401 val.ConvertToArray(StrArray);
402 » » return StrArray; 402 return StrArray;
403 » } 403 }
404 » CFX_WideString wsStr = val.ToCFXWideString(); 404 CFX_WideString wsStr = val.ToCFXWideString();
405 » CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); 405 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
406 » const char * p = (const char *)t; 406 const char * p = (const char *)t;
407 407
408 408
409 » int ch = ',' ; 409 int ch = ',' ;
410 » int nIndex = 0; 410 int nIndex = 0;
411 411
412 » while (*p) 412 while (*p)
413 » { 413 {
414 » » const char * pTemp = strchr(p, ch); 414 const char * pTemp = strchr(p, ch);
415 » » if (pTemp == NULL) 415 if (pTemp == NULL)
416 » » { 416 {
417 » » » StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p ).c_str())); 417 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str()));
418 » » » break; 418 break;
419 » » } 419 }
420 » » else 420 else
421 » » { 421 {
422 » » » char * pSub = new char[pTemp - p + 1]; 422 char * pSub = new char[pTemp - p + 1];
423 » » » strncpy(pSub, p, pTemp - p); 423 strncpy(pSub, p, pTemp - p);
424 » » » *(pSub + (pTemp - p)) = '\0'; 424 *(pSub + (pTemp - p)) = '\0';
425 425
426 » » » StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p Sub).c_str())); 426 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str() ));
427 » » » delete []pSub; 427 delete []pSub;
428 428
429 » » » nIndex ++; 429 nIndex ++;
430 » » » p = ++pTemp; 430 p = ++pTemp;
431 » » } 431 }
432 432
433 » } 433 }
434 » return StrArray; 434 return StrArray;
435 } 435 }
436 436
437 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStar t,int& nSkip, int nMaxStep) 437 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStar t,int& nSkip, int nMaxStep)
438 { 438 {
439 » int nRet = 0; 439 int nRet = 0;
440 » nSkip = 0; 440 nSkip = 0;
441 » for (int i=nStart, sz=string.GetLength(); i < sz; i++) 441 for (int i=nStart, sz=string.GetLength(); i < sz; i++)
442 » { 442 {
443 » » if (i-nStart > 10) 443 if (i-nStart > 10)
444 » » » break; 444 break;
445 445
446 » » FX_WCHAR c = string.GetAt(i); 446 FX_WCHAR c = string.GetAt(i);
447 » » if (IsDigit((wchar_t)c)) 447 if (IsDigit((wchar_t)c))
448 » » { 448 {
449 » » » nRet = nRet * 10 + (c - '0'); 449 nRet = nRet * 10 + (c - '0');
450 » » » nSkip = i - nStart + 1; 450 nSkip = i - nStart + 1;
451 » » » if (nSkip >= nMaxStep) 451 if (nSkip >= nMaxStep)
452 » » » » break; 452 break;
453 » » } 453 }
454 » » else 454 else
455 » » » break; 455 break;
456 » } 456 }
457 457
458 » return nRet; 458 return nRet;
459 } 459 }
460 460
461 CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string , int nStart, int& nSkip) 461 CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string , int nStart, int& nSkip)
462 { 462 {
463 » CFX_WideString swRet; 463 CFX_WideString swRet;
464 » nSkip = 0; 464 nSkip = 0;
465 » for (int i=nStart, sz=string.GetLength(); i < sz; i++) 465 for (int i=nStart, sz=string.GetLength(); i < sz; i++)
466 » { 466 {
467 » » FX_WCHAR c = string.GetAt(i); 467 FX_WCHAR c = string.GetAt(i);
468 » » if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z')) 468 if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
469 » » { 469 {
470 » » » swRet += c; 470 swRet += c;
471 » » » nSkip = i - nStart + 1; 471 nSkip = i - nStart + 1;
472 » » } 472 }
473 » » else 473 else
474 » » » break; 474 break;
475 » } 475 }
476 476
477 » return swRet; 477 return swRet;
478 } 478 }
479 479
480 double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat) 480 double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat)
481 { 481 {
482 » double dt = JS_GetDateTime(); 482 double dt = JS_GetDateTime();
483 483
484 » int nYear = JS_GetYearFromTime(dt); 484 int nYear = JS_GetYearFromTime(dt);
485 » int nMonth = JS_GetMonthFromTime(dt) + 1; 485 int nMonth = JS_GetMonthFromTime(dt) + 1;
486 » int nDay = JS_GetDayFromTime(dt); 486 int nDay = JS_GetDayFromTime(dt);
487 » int nHour = JS_GetHourFromTime(dt); 487 int nHour = JS_GetHourFromTime(dt);
488 » int nMin = JS_GetMinFromTime(dt); 488 int nMin = JS_GetMinFromTime(dt);
489 » int nSec = JS_GetSecFromTime(dt); 489 int nSec = JS_GetSecFromTime(dt);
490 490
491 » int number[3]; 491 int number[3];
492 492
493 » int nSkip = 0; 493 int nSkip = 0;
494 » int nLen = value.GetLength(); 494 int nLen = value.GetLength();
495 » int nIndex = 0; 495 int nIndex = 0;
496 » int i = 0; 496 int i = 0;
497 » while (i < nLen) 497 while (i < nLen)
498 » { 498 {
499 » » if (nIndex > 2) break; 499 if (nIndex > 2) break;
500 500
501 » » FX_WCHAR c = value.GetAt(i); 501 FX_WCHAR c = value.GetAt(i);
502 » » if (IsDigit((wchar_t)c)) 502 if (IsDigit((wchar_t)c))
503 » » { 503 {
504 » » » number[nIndex++] = ParseStringInteger(value, i, nSkip, 4 ); 504 number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
505 » » » i += nSkip; 505 i += nSkip;
506 » » } 506 }
507 » » else 507 else
508 » » { 508 {
509 » » » i ++; 509 i ++;
510 » » } 510 }
511 » } 511 }
512 512
513 » if (nIndex == 2) 513 if (nIndex == 2)
514 » { 514 {
515 » » // case2: month/day 515 // case2: month/day
516 » » // case3: day/month 516 // case3: day/month
517 » » if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && nu mber[1] <= 31)) 517 if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
518 » » { 518 {
519 » » » nMonth = number[0]; 519 nMonth = number[0];
520 » » » nDay = number[1]; 520 nDay = number[1];
521 » » } 521 }
522 » » else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12)) 522 else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && numbe r[1] <= 12))
523 » » { 523 {
524 » » » nDay = number[0]; 524 nDay = number[0];
525 » » » nMonth = number[1]; 525 nMonth = number[1];
526 » » } 526 }
527 527
528 » » bWrongFormat = FALSE; 528 bWrongFormat = FALSE;
529 » } 529 }
530 » else if (nIndex == 3) 530 else if (nIndex == 3)
531 » { 531 {
532 » » // case1: year/month/day 532 // case1: year/month/day
533 » » // case2: month/day/year 533 // case2: month/day/year
534 » » // case3: day/month/year 534 // case3: day/month/year
535 535
536 » » if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (nu mber[2] >= 1 && number[2] <= 31)) 536 if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
537 » » { 537 {
538 » » » nYear = number[0]; 538 nYear = number[0];
539 » » » nMonth = number[1]; 539 nMonth = number[1];
540 » » » nDay = number[2]; 540 nDay = number[2];
541 » » } 541 }
542 » » else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31) 542 else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && numbe r[1] <= 31) && number[2] > 31)
543 » » { 543 {
544 » » » nMonth = number[0]; 544 nMonth = number[0];
545 » » » nDay = number[1]; 545 nDay = number[1];
546 » » » nYear = number[2]; 546 nYear = number[2];
547 » » } 547 }
548 » » else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31) 548 else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && numbe r[1] <= 12) && number[2] > 31)
549 » » { 549 {
550 » » » nDay = number[0]; 550 nDay = number[0];
551 » » » nMonth = number[1]; 551 nMonth = number[1];
552 » » » nYear = number[2]; 552 nYear = number[2];
553 » » } 553 }
554 554
555 » » bWrongFormat = FALSE; 555 bWrongFormat = FALSE;
556 » } 556 }
557 » else 557 else
558 » { 558 {
559 » » bWrongFormat = TRUE; 559 bWrongFormat = TRUE;
560 » » return dt; 560 return dt;
561 » } 561 }
562 562
563 » CFX_WideString swTemp; 563 CFX_WideString swTemp;
564 » swTemp.Format(L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec); 564 swTemp.Format(L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
565 » return JS_DateParse(swTemp.c_str()); 565 return JS_DateParse(swTemp.c_str());
566 } 566 }
567 567
568 double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CF X_WideString & format, FX_BOOL& bWrongFormat) 568 double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CF X_WideString & format, FX_BOOL& bWrongFormat)
569 { 569 {
570 double dt = JS_GetDateTime(); 570 double dt = JS_GetDateTime();
571 571
572 if (format.IsEmpty() || value.IsEmpty()) 572 if (format.IsEmpty() || value.IsEmpty())
573 return dt; 573 return dt;
574 574
575 int nYear = JS_GetYearFromTime(dt); 575 int nYear = JS_GetYearFromTime(dt);
576 int nMonth = JS_GetMonthFromTime(dt) + 1; 576 int nMonth = JS_GetMonthFromTime(dt) + 1;
577 int nDay = JS_GetDayFromTime(dt); 577 int nDay = JS_GetDayFromTime(dt);
578 int nHour = JS_GetHourFromTime(dt); 578 int nHour = JS_GetHourFromTime(dt);
579 int nMin = JS_GetMinFromTime(dt); 579 int nMin = JS_GetMinFromTime(dt);
580 int nSec = JS_GetSecFromTime(dt); 580 int nSec = JS_GetSecFromTime(dt);
581 581
582 int nYearSub = 99; //nYear - 2000; 582 int nYearSub = 99; //nYear - 2000;
583 583
584 FX_BOOL bPm = FALSE; 584 FX_BOOL bPm = FALSE;
585 FX_BOOL bExit = FALSE; 585 FX_BOOL bExit = FALSE;
586 bWrongFormat = FALSE; 586 bWrongFormat = FALSE;
587 587
588 int i=0; 588 int i=0;
589 int j=0; 589 int j=0;
590 590
591 while (i < format.GetLength()) 591 while (i < format.GetLength())
592 { 592 {
593 if (bExit) break; 593 if (bExit) break;
594 594
595 FX_WCHAR c = format.GetAt(i); 595 FX_WCHAR c = format.GetAt(i);
596 switch (c) 596 switch (c)
597 { 597 {
598 case ':': 598 case ':':
599 case '.': 599 case '.':
600 case '-': 600 case '-':
601 case '\\': 601 case '\\':
602 case '/': 602 case '/':
603 i++; 603 i++;
604 j++; 604 j++;
605 break; 605 break;
606 606
607 case 'y': 607 case 'y':
608 case 'm': 608 case 'm':
609 case 'd': 609 case 'd':
610 case 'H': 610 case 'H':
611 case 'h': 611 case 'h':
612 case 'M': 612 case 'M':
613 case 's': 613 case 's':
614 case 't': 614 case 't':
615 { 615 {
616 int oldj = j; 616 int oldj = j;
617 int nSkip = 0; 617 int nSkip = 0;
618 int remaining = format.GetLength() - i - 1; 618 int remaining = format.GetLength() - i - 1;
619 619
620 if (remaining == 0 || format.GetAt(i+1) != c) 620 if (remaining == 0 || format.GetAt(i+1) != c)
621 { 621 {
622 switch (c) 622 switch (c)
623 { 623 {
624 case 'y': 624 case 'y':
625 i++; 625 i++;
626 j++; 626 j++;
627 break; 627 break;
628 case 'm': 628 case 'm':
629 nMonth = ParseSt ringInteger(value, j, nSkip, 2); 629 nMonth = ParseStringInteger(value, j, nSkip, 2);
630 i++; 630 i++;
631 j += nSkip; 631 j += nSkip;
632 break; 632 break;
633 case 'd': 633 case 'd':
634 nDay = ParseStri ngInteger(value, j, nSkip, 2); 634 nDay = ParseStringInteger(value, j, nSkip, 2);
635 i++; 635 i++;
636 j += nSkip; 636 j += nSkip;
637 break; 637 break;
638 case 'H': 638 case 'H':
639 nHour = ParseStr ingInteger(value, j, nSkip, 2); 639 nHour = ParseStringInteger(value, j, nSkip, 2);
640 i++; 640 i++;
641 j += nSkip; 641 j += nSkip;
642 break; 642 break;
643 case 'h': 643 case 'h':
644 nHour = ParseStr ingInteger(value, j, nSkip, 2); 644 nHour = ParseStringInteger(value, j, nSkip, 2);
645 i++; 645 i++;
646 j += nSkip; 646 j += nSkip;
647 break; 647 break;
648 case 'M': 648 case 'M':
649 nMin = ParseStri ngInteger(value, j, nSkip, 2); 649 nMin = ParseStringInteger(value, j, nSkip, 2);
650 i++; 650 i++;
651 j += nSkip; 651 j += nSkip;
652 break; 652 break;
653 case 's': 653 case 's':
654 nSec = ParseStri ngInteger(value, j, nSkip, 2); 654 nSec = ParseStringInteger(value, j, nSkip, 2);
655 i++; 655 i++;
656 j += nSkip; 656 j += nSkip;
657 break; 657 break;
658 case 't': 658 case 't':
659 bPm = (j < value .GetLength() && value.GetAt(j) == 'p'); 659 bPm = (j < value.GetLength() && value.GetAt(j) = = 'p');
660 i++; 660 i++;
661 j++; 661 j++;
662 break; 662 break;
663 } 663 }
664 } 664 }
665 else if (remaining == 1 || format.GetAt( i+2) != c) 665 else if (remaining == 1 || format.GetAt(i+2) != c)
666 { 666 {
667 switch (c) 667 switch (c)
668 { 668 {
669 case 'y': 669 case 'y':
670 nYear = ParseStr ingInteger(value, j, nSkip, 4); 670 nYear = ParseStringInteger(value, j, nSkip, 4);
671 i += 2; 671 i += 2;
672 j += nSkip; 672 j += nSkip;
673 break; 673 break;
674 case 'm': 674 case 'm':
675 nMonth = ParseSt ringInteger(value, j, nSkip, 2); 675 nMonth = ParseStringInteger(value, j, nSkip, 2);
676 i += 2; 676 i += 2;
677 j += nSkip; 677 j += nSkip;
678 break; 678 break;
679 case 'd': 679 case 'd':
680 nDay = ParseStri ngInteger(value, j, nSkip, 2); 680 nDay = ParseStringInteger(value, j, nSkip, 2);
681 i += 2; 681 i += 2;
682 j += nSkip; 682 j += nSkip;
683 break; 683 break;
684 case 'H': 684 case 'H':
685 nHour = ParseStr ingInteger(value, j, nSkip, 2); 685 nHour = ParseStringInteger(value, j, nSkip, 2);
686 i += 2; 686 i += 2;
687 j += nSkip; 687 j += nSkip;
688 break; 688 break;
689 case 'h': 689 case 'h':
690 nHour = ParseStr ingInteger(value, j, nSkip, 2); 690 nHour = ParseStringInteger(value, j, nSkip, 2);
691 i += 2; 691 i += 2;
692 j += nSkip; 692 j += nSkip;
693 break; 693 break;
694 case 'M': 694 case 'M':
695 nMin = ParseStri ngInteger(value, j, nSkip, 2); 695 nMin = ParseStringInteger(value, j, nSkip, 2);
696 i += 2; 696 i += 2;
697 j += nSkip; 697 j += nSkip;
698 break; 698 break;
699 case 's': 699 case 's':
700 nSec = ParseStri ngInteger(value, j, nSkip, 2); 700 nSec = ParseStringInteger(value, j, nSkip, 2);
701 i += 2; 701 i += 2;
702 j += nSkip; 702 j += nSkip;
703 break; 703 break;
704 case 't': 704 case 't':
705 bPm = (j + 1 < v alue.GetLength() && value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm'); 705 bPm = (j + 1 < value.GetLength() && value.GetAt( j) == 'p' && value.GetAt(j+1) == 'm');
706 i += 2; 706 i += 2;
707 j += 2; 707 j += 2;
708 break; 708 break;
709 } 709 }
710 } 710 }
711 else if (remaining == 2 || format.GetAt( i+3) != c) 711 else if (remaining == 2 || format.GetAt(i+3) != c)
712 { 712 {
713 switch (c) 713 switch (c)
714 { 714 {
715 case 'm': 715 case 'm':
716 { 716 {
717 CFX_Wide String sMonth = ParseStringString(value, j, nSkip); 717 CFX_WideString sMonth = ParseStringString(va lue, j, nSkip);
718 FX_BOOL bFind = FALSE; 718 FX_BOOL bFind = FALSE;
719 for (int m = 0; m < 12; m++) 719 for (int m = 0; m < 12; m++)
720 { 720 {
721 if (sMonth.CompareNoCase(months[m]) == 0) 721 if (sMonth.CompareNoCase(months[m]) == 0 )
722 { 722 {
723 nMonth = m + 1; 723 nMonth = m + 1;
724 i+=3; 724 i+=3;
725 j+=nSkip; 725 j+=nSkip;
726 bFind = TRUE; 726 bFind = TRUE;
727 break; 727 break;
728 } 728 }
729 } 729 }
730 730
731 if (!bFi nd) 731 if (!bFind)
732 { 732 {
733 nMonth = ParseStringInteger(value, j, nSkip, 3); 733 nMonth = ParseStringInteger(value, j, nS kip, 3);
734 i+=3; 734 i+=3;
735 j += nSkip; 735 j += nSkip;
736 } 736 }
737 } 737 }
738 break; 738 break;
739 case 'y': 739 case 'y':
740 break; 740 break;
741 default: 741 default:
742 i+=3; 742 i+=3;
743 j+=3; 743 j+=3;
744 break; 744 break;
745 } 745 }
746 } 746 }
747 else if (remaining == 3 || format.GetAt( i+4) != c) 747 else if (remaining == 3 || format.GetAt(i+4) != c)
748 { 748 {
749 switch (c) 749 switch (c)
750 { 750 {
751 751
752 752
753 case 'y': 753 case 'y':
754 nYear = ParseStr ingInteger(value, j, nSkip, 4); 754 nYear = ParseStringInteger(value, j, nSkip, 4);
755 j += nSkip; 755 j += nSkip;
756 i += 4; 756 i += 4;
757 break; 757 break;
758 case 'm': 758 case 'm':
759 { 759 {
760 FX_BOOL bFind = FALSE; 760 FX_BOOL bFind = FALSE;
761 761
762 CFX_Wide String sMonth = ParseStringString(value, j, nSkip); 762 CFX_WideString sMonth = ParseStringString(va lue, j, nSkip);
763 sMonth.M akeLower(); 763 sMonth.MakeLower();
764 764
765 for (int m = 0; m < 12; m++) 765 for (int m = 0; m < 12; m++)
766 { 766 {
767 CFX_WideString sFullMonths = fullmonths[m]; 767 CFX_WideString sFullMonths = fullmonths[ m];
768 sFullMonths.MakeLower(); 768 sFullMonths.MakeLower();
769 769
770 if (sFullMonths.Find(sMonth.c_str(), 0) != -1) 770 if (sFullMonths.Find(sMonth.c_str(), 0) != -1)
771 { 771 {
772 nMonth = m + 1; 772 nMonth = m + 1;
773 i += 4; 773 i += 4;
774 j += nSkip; 774 j += nSkip;
775 bFind = TRUE; 775 bFind = TRUE;
776 break; 776 break;
777 } 777 }
778 } 778 }
779 779
780 if (!bFi nd) 780 if (!bFind)
781 { 781 {
782 nMonth = ParseStringInteger(value, j, nSkip, 4); 782 nMonth = ParseStringInteger(value, j, nS kip, 4);
783 i+=4; 783 i+=4;
784 j += nSkip; 784 j += nSkip;
785 } 785 }
786 } 786 }
787 break; 787 break;
788 default: 788 default:
789 i += 4; 789 i += 4;
790 j += 4; 790 j += 4;
791 break; 791 break;
792 } 792 }
793 } 793 }
794 else 794 else
795 { 795 {
796 if (j >= value.GetLength() || fo rmat.GetAt(i) != value.GetAt(j)) 796 if (j >= value.GetLength() || format.GetAt(i) != value.G etAt(j))
797 { 797 {
798 bWrongFormat = TRUE; 798 bWrongFormat = TRUE;
799 bExit = TRUE; 799 bExit = TRUE;
800 } 800 }
801 i++; 801 i++;
802 j++; 802 j++;
803 } 803 }
804 804
805 if (oldj == j) 805 if (oldj == j)
806 { 806 {
807 bWrongFormat = TRUE; 807 bWrongFormat = TRUE;
808 bExit = TRUE; 808 bExit = TRUE;
809 } 809 }
810 } 810 }
811 811
812 break; 812 break;
813 default: 813 default:
814 if (value.GetLength() <= j) 814 if (value.GetLength() <= j)
815 { 815 {
816 bExit = TRUE; 816 bExit = TRUE;
817 } 817 }
818 else if (format.GetAt(i) != value.GetAt(j)) 818 else if (format.GetAt(i) != value.GetAt(j))
819 { 819 {
820 bWrongFormat = TRUE; 820 bWrongFormat = TRUE;
821 bExit = TRUE; 821 bExit = TRUE;
822 } 822 }
823 823
824 i++; 824 i++;
825 j++; 825 j++;
826 break; 826 break;
827 } 827 }
828 } 828 }
829 829
830 if (bPm) nHour += 12; 830 if (bPm) nHour += 12;
831 831
832 if (nYear >= 0 && nYear <= nYearSub) 832 if (nYear >= 0 && nYear <= nYearSub)
833 nYear += 2000; 833 nYear += 2000;
834 834
835 if (nMonth < 1 || nMonth > 12) 835 if (nMonth < 1 || nMonth > 12)
836 bWrongFormat = TRUE; 836 bWrongFormat = TRUE;
837 837
838 if (nDay < 1 || nDay > 31) 838 if (nDay < 1 || nDay > 31)
839 bWrongFormat = TRUE; 839 bWrongFormat = TRUE;
840 840
841 if (nHour < 0 || nHour > 24) 841 if (nHour < 0 || nHour > 24)
842 bWrongFormat = TRUE; 842 bWrongFormat = TRUE;
843 843
844 if (nMin < 0 || nMin > 60) 844 if (nMin < 0 || nMin > 60)
845 bWrongFormat = TRUE; 845 bWrongFormat = TRUE;
846 846
847 if (nSec < 0 || nSec > 60) 847 if (nSec < 0 || nSec > 60)
848 bWrongFormat = TRUE; 848 bWrongFormat = TRUE;
849 849
850 double dRet = 0; 850 double dRet = 0;
851 851
852 if (bWrongFormat) 852 if (bWrongFormat)
853 { 853 {
854 dRet = ParseNormalDate(value, bWrongFormat); 854 dRet = ParseNormalDate(value, bWrongFormat);
855 } 855 }
856 else 856 else
857 { 857 {
858 dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime (nHour, nMin, nSec, 0)); 858 dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
859 859
860 if (JS_PortIsNan(dRet)) 860 if (JS_PortIsNan(dRet))
861 { 861 {
862 dRet = JS_DateParse(value.c_str()); 862 dRet = JS_DateParse(value.c_str());
863 } 863 }
864 } 864 }
865 865
866 if (JS_PortIsNan(dRet)) 866 if (JS_PortIsNan(dRet))
867 { 867 {
868 dRet = ParseNormalDate(value, bWrongFormat); 868 dRet = ParseNormalDate(value, bWrongFormat);
869 } 869 }
870 870
871 return dRet; 871 return dRet;
872 872
873 } 873 }
874 874
875 CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr ing & format) 875 CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr ing & format)
876 { 876 {
877 » CFX_WideString sRet = L"",sPart = L""; 877 CFX_WideString sRet = L"",sPart = L"";
878 878
879 » int nYear = JS_GetYearFromTime(dDate); 879 int nYear = JS_GetYearFromTime(dDate);
880 » int nMonth = JS_GetMonthFromTime(dDate) + 1; 880 int nMonth = JS_GetMonthFromTime(dDate) + 1;
881 » int nDay = JS_GetDayFromTime(dDate); 881 int nDay = JS_GetDayFromTime(dDate);
882 » int nHour = JS_GetHourFromTime(dDate); 882 int nHour = JS_GetHourFromTime(dDate);
883 » int nMin = JS_GetMinFromTime(dDate); 883 int nMin = JS_GetMinFromTime(dDate);
884 » int nSec = JS_GetSecFromTime(dDate); 884 int nSec = JS_GetSecFromTime(dDate);
885 885
886 » int i = 0; 886 int i = 0;
887 » while (i < format.GetLength()) 887 while (i < format.GetLength())
888 » { 888 {
889 » FX_WCHAR c = format.GetAt(i); 889 FX_WCHAR c = format.GetAt(i);
890 int remaining = format.GetLength() - i - 1; 890 int remaining = format.GetLength() - i - 1;
891 » » sPart = L""; 891 sPart = L"";
892 » » switch (c) 892 switch (c)
893 » » { 893 {
894 » » » case 'y': 894 case 'y':
895 » » » case 'm': 895 case 'm':
896 » » » case 'd': 896 case 'd':
897 » » » case 'H': 897 case 'H':
898 » » » case 'h': 898 case 'h':
899 » » » case 'M': 899 case 'M':
900 » » » case 's': 900 case 's':
901 » » » case 't': 901 case 't':
902 » » » » if (remaining == 0 || format.GetAt(i+1) != c) 902 if (remaining == 0 || format.GetAt(i+1) != c)
903 » » » » { 903 {
904 » » » » » switch (c) 904 switch (c)
905 » » » » » { 905 {
906 » » » » » » case 'y': 906 case 'y':
907 » » » » » » » sPart += c; 907 sPart += c;
908 » » » » » » » break; 908 break;
909 » » » » » » case 'm': 909 case 'm':
910 » » » » » » » sPart.Format(L"%d",nMont h); 910 sPart.Format(L"%d",nMonth);
911 » » » » » » » break; 911 break;
912 » » » » » » case 'd': 912 case 'd':
913 » » » » » » » sPart.Format(L"%d",nDay) ; 913 sPart.Format(L"%d",nDay);
914 » » » » » » » break; 914 break;
915 » » » » » » case 'H': 915 case 'H':
916 » » » » » » » sPart.Format(L"%d",nHour ); 916 sPart.Format(L"%d",nHour);
917 » » » » » » » break; 917 break;
918 » » » » » » case 'h': 918 case 'h':
919 » » » » » » » sPart.Format(L"%d",nHour >12?nHour - 12:nHour); 919 sPart.Format(L"%d",nHour>12?nHour - 12:nHour);
920 » » » » » » » break; 920 break;
921 » » » » » » case 'M': 921 case 'M':
922 » » » » » » » sPart.Format(L"%d",nMin) ; 922 sPart.Format(L"%d",nMin);
923 » » » » » » » break; 923 break;
924 » » » » » » case 's': 924 case 's':
925 » » » » » » » sPart.Format(L"%d",nSec) ; 925 sPart.Format(L"%d",nSec);
926 » » » » » » » break; 926 break;
927 » » » » » » case 't': 927 case 't':
928 » » » » » » » sPart += nHour>12?'p':'a '; 928 sPart += nHour>12?'p':'a';
929 » » » » » » » break; 929 break;
930 » » » » » } 930 }
931 » » » » » i++; 931 i++;
932 » » » » } 932 }
933 » » » » else if (remaining == 1 || format.GetAt(i+2) != c) 933 else if (remaining == 1 || format.GetAt(i+2) != c)
934 » » » » { 934 {
935 » » » » » switch (c) 935 switch (c)
936 » » » » » { 936 {
937 » » » » » » case 'y': 937 case 'y':
938 » » » » » » » sPart.Format(L"%02d",nYe ar - (nYear / 100) * 100); 938 sPart.Format(L"%02d",nYear - (nYear / 100) * 100);
939 » » » » » » » break; 939 break;
940 » » » » » » case 'm': 940 case 'm':
941 » » » » » » » sPart.Format(L"%02d",nMo nth); 941 sPart.Format(L"%02d",nMonth);
942 » » » » » » » break; 942 break;
943 » » » » » » case 'd': 943 case 'd':
944 » » » » » » » sPart.Format(L"%02d",nDa y); 944 sPart.Format(L"%02d",nDay);
945 » » » » » » » break; 945 break;
946 » » » » » » case 'H': 946 case 'H':
947 » » » » » » » sPart.Format(L"%02d",nHo ur); 947 sPart.Format(L"%02d",nHour);
948 » » » » » » » break; 948 break;
949 » » » » » » case 'h': 949 case 'h':
950 » » » » » » » sPart.Format(L"%02d",nHo ur>12?nHour - 12:nHour); 950 sPart.Format(L"%02d",nHour>12?nHour - 12:nHour);
951 » » » » » » » break; 951 break;
952 » » » » » » case 'M': 952 case 'M':
953 » » » » » » » sPart.Format(L"%02d",nMi n); 953 sPart.Format(L"%02d",nMin);
954 » » » » » » » break; 954 break;
955 » » » » » » case 's': 955 case 's':
956 » » » » » » » sPart.Format(L"%02d",nSe c); 956 sPart.Format(L"%02d",nSec);
957 » » » » » » » break; 957 break;
958 » » » » » » case 't': 958 case 't':
959 » » » » » » » sPart = nHour>12? L"pm": L"am"; 959 sPart = nHour>12? L"pm": L"am";
960 » » » » » » » break; 960 break;
961 » » » » » } 961 }
962 » » » » » i+=2; 962 i+=2;
963 » » » » } 963 }
964 » » » » else if (remaining == 2 || format.GetAt(i+3) != c) 964 else if (remaining == 2 || format.GetAt(i+3) != c)
965 » » » » { 965 {
966 » » » » » switch (c) 966 switch (c)
967 » » » » » { 967 {
968 » » » » » » case 'm': 968 case 'm':
969 » » » » » » » i+=3; 969 i+=3;
970 » » » » » » » if (nMonth > 0&&nMonth < = 12) 970 if (nMonth > 0&&nMonth <= 12)
971 » » » » » » » » sPart += months[ nMonth - 1]; 971 sPart += months[nMonth - 1];
972 » » » » » » » break; 972 break;
973 » » » » » » default: 973 default:
974 » » » » » » » i+=3; 974 i+=3;
975 » » » » » » » sPart += c; 975 sPart += c;
976 » » » » » » » sPart += c; 976 sPart += c;
977 » » » » » » » sPart += c; 977 sPart += c;
978 » » » » » » » break; 978 break;
979 » » » » » } 979 }
980 » » » » } 980 }
981 » » » » else if (remaining == 3 || format.GetAt(i+4) != c) 981 else if (remaining == 3 || format.GetAt(i+4) != c)
982 » » » » { 982 {
983 » » » » » switch (c) 983 switch (c)
984 » » » » » { 984 {
985 » » » » » » case 'y': 985 case 'y':
986 » » » » » » » sPart.Format(L"%04d",nYe ar); 986 sPart.Format(L"%04d",nYear);
987 » » » » » » » i += 4; 987 i += 4;
988 » » » » » » » break; 988 break;
989 » » » » » » case 'm': 989 case 'm':
990 » » » » » » » i+=4; 990 i+=4;
991 » » » » » » » if (nMonth > 0&&nMonth < = 12) 991 if (nMonth > 0&&nMonth <= 12)
992 » » » » » » » » sPart += fullmon ths[nMonth - 1]; 992 sPart += fullmonths[nMonth - 1];
993 » » » » » » » break; 993 break;
994 » » » » » » default: 994 default:
995 » » » » » » » i += 4; 995 i += 4;
996 » » » » » » » sPart += c; 996 sPart += c;
997 » » » » » » » sPart += c; 997 sPart += c;
998 » » » » » » » sPart += c; 998 sPart += c;
999 » » » » » » » sPart += c; 999 sPart += c;
1000 » » » » » » » break; 1000 break;
1001 » » » » » } 1001 }
1002 » » » » } 1002 }
1003 » » » » else 1003 else
1004 » » » » { 1004 {
1005 » » » » » i++; 1005 i++;
1006 » » » » » sPart += c; 1006 sPart += c;
1007 » » » » } 1007 }
1008 » » » » break; 1008 break;
1009 » » » default: 1009 default:
1010 » » » » i++; 1010 i++;
1011 » » » » sPart += c; 1011 sPart += c;
1012 » » » » break; 1012 break;
1013 » » } 1013 }
1014 1014
1015 » » sRet += sPart; 1015 sRet += sPart;
1016 » } 1016 }
1017 1017
1018 » return sRet; 1018 return sRet;
1019 } 1019 }
1020 1020
1021 /* -------------------------------------------------------------------------- */ 1021 /* -------------------------------------------------------------------------- */
1022 1022
1023 //function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCu rrencyPrepend) 1023 //function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCu rrencyPrepend)
1024 FX_BOOL CJS_PublicMethods::AFNumber_Format(IFXJS_Context* cc, const CJS_Paramete rs& params, CJS_Value& vRet, CFX_WideString& sError) 1024 FX_BOOL CJS_PublicMethods::AFNumber_Format(IFXJS_Context* cc, const CJS_Paramete rs& params, CJS_Value& vRet, CFX_WideString& sError)
1025 { 1025 {
1026 #if _FX_OS_ != _FX_ANDROID_ 1026 #if _FX_OS_ != _FX_ANDROID_
1027 v8::Isolate* isolate = ::GetIsolate(cc); 1027 v8::Isolate* isolate = ::GetIsolate(cc);
1028 CJS_Context* pContext = (CJS_Context *)cc; 1028 CJS_Context* pContext = (CJS_Context *)cc;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 vProp2.StartGetting(); 1218 vProp2.StartGetting();
1219 vProp2<<arColor; 1219 vProp2<<arColor;
1220 vProp2.StartSetting(); 1220 vProp2.StartSetting();
1221 fTarget->textColor(cc,vProp2,sError); 1221 fTarget->textColor(cc,vProp2,sError);
1222 } 1222 }
1223 } 1223 }
1224 } 1224 }
1225 } 1225 }
1226 Value = strValue2.c_str(); 1226 Value = strValue2.c_str();
1227 #endif 1227 #endif
1228 » return TRUE; 1228 return TRUE;
1229 } 1229 }
1230 1230
1231 //function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) 1231 //function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
1232 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError) 1232 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError)
1233 { 1233 {
1234 » CJS_Context* pContext = (CJS_Context *)cc; 1234 CJS_Context* pContext = (CJS_Context *)cc;
1235 » ASSERT(pContext != NULL); 1235 ASSERT(pContext != NULL);
1236 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1236 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1237 » ASSERT(pEvent != NULL); 1237 ASSERT(pEvent != NULL);
1238 1238
1239 » if(params.size() < 2) 1239 if(params.size() < 2)
1240 » » return FALSE; 1240 return FALSE;
1241 » int iSepStyle = params[1].ToInt(); 1241 int iSepStyle = params[1].ToInt();
1242 1242
1243 » if (iSepStyle < 0 || iSepStyle > 3) 1243 if (iSepStyle < 0 || iSepStyle > 3)
1244 » » iSepStyle = 0; 1244 iSepStyle = 0;
1245 » if(!pEvent->m_pValue) 1245 if(!pEvent->m_pValue)
1246 » » return FALSE; 1246 return FALSE;
1247 » CFX_WideString & val = pEvent->Value(); 1247 CFX_WideString & val = pEvent->Value();
1248 » CFX_WideString & w_strChange = pEvent->Change(); 1248 CFX_WideString & w_strChange = pEvent->Change();
1249 CFX_WideString w_strValue = val; 1249 CFX_WideString w_strValue = val;
1250 1250
1251 » if (pEvent->WillCommit()) 1251 if (pEvent->WillCommit())
1252 » { 1252 {
1253 » » CFX_WideString wstrChange = w_strChange; 1253 CFX_WideString wstrChange = w_strChange;
1254 » » CFX_WideString wstrValue = StrLTrim(w_strValue.c_str()); 1254 CFX_WideString wstrValue = StrLTrim(w_strValue.c_str());
1255 » » if (wstrValue.IsEmpty()) 1255 if (wstrValue.IsEmpty())
1256 » » » return TRUE; 1256 return TRUE;
1257 1257
1258 » » CFX_WideString swTemp = wstrValue; 1258 CFX_WideString swTemp = wstrValue;
1259 » » swTemp.Replace(L",", L"."); 1259 swTemp.Replace(L",", L".");
1260 » » if (!IsNumber(swTemp.c_str())) 1260 if (!IsNumber(swTemp.c_str()))
1261 » » { 1261 {
1262 » » » pEvent->Rc() = FALSE; 1262 pEvent->Rc() = FALSE;
1263 » » » sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMB ER_KEYSTROKE); 1263 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE );
1264 » » » Alert(pContext, sError.c_str()); 1264 Alert(pContext, sError.c_str());
1265 » » » return TRUE; 1265 return TRUE;
1266 » » } 1266 }
1267 » » return TRUE; // it happens after the last keystroke and before v alidating, 1267 return TRUE; // it happens after the last keystroke and before validatin g,
1268 » } 1268 }
1269 1269
1270 » std::wstring w_strValue2 = w_strValue.c_str(); 1270 std::wstring w_strValue2 = w_strValue.c_str();
1271 » std::wstring w_strChange2 = w_strChange.c_str(); 1271 std::wstring w_strChange2 = w_strChange.c_str();
1272 » std::wstring w_strSelected; 1272 std::wstring w_strSelected;
1273 » if(-1 != pEvent->SelStart()) 1273 if(-1 != pEvent->SelStart())
1274 » » w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->S elEnd() - pEvent->SelStart())); 1274 w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
1275 » FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find( '-') == -1); 1275 FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
1276 » if (bHasSign) 1276 if (bHasSign)
1277 » { 1277 {
1278 » » //can't insert "change" in front to sign postion. 1278 //can't insert "change" in front to sign postion.
1279 » » if (pEvent->SelStart() == 0) 1279 if (pEvent->SelStart() == 0)
1280 » » { 1280 {
1281 FX_BOOL &bRc = pEvent->Rc(); 1281 FX_BOOL &bRc = pEvent->Rc();
1282 » » » bRc = FALSE; 1282 bRc = FALSE;
1283 » » » return TRUE; 1283 return TRUE;
1284 » » } 1284 }
1285 » } 1285 }
1286 1286
1287 » char cSep = L'.'; 1287 char cSep = L'.';
1288 1288
1289 » switch (iSepStyle) 1289 switch (iSepStyle)
1290 » { 1290 {
1291 » case 0: 1291 case 0:
1292 » case 1: 1292 case 1:
1293 » » cSep = L'.'; 1293 cSep = L'.';
1294 » » break; 1294 break;
1295 » case 2: 1295 case 2:
1296 » case 3: 1296 case 3:
1297 » » cSep = L','; 1297 cSep = L',';
1298 » » break; 1298 break;
1299 » } 1299 }
1300 1300
1301 » FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1); 1301 FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
1302 » for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange 2.end(); it++) 1302 for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.en d(); it++)
1303 » { 1303 {
1304 » » if (*it == cSep) 1304 if (*it == cSep)
1305 » » { 1305 {
1306 » » » if (bHasSep) 1306 if (bHasSep)
1307 » » » { 1307 {
1308 » » » » FX_BOOL &bRc = pEvent->Rc(); 1308 FX_BOOL &bRc = pEvent->Rc();
1309 » » » » bRc = FALSE; 1309 bRc = FALSE;
1310 » » » » return TRUE; 1310 return TRUE;
1311 » » » } 1311 }
1312 » » » else 1312 bHasSep = TRUE;
1313 » » » { 1313 continue;
1314 » » » » bHasSep = TRUE; 1314 }
1315 » » » » continue; 1315 if (*it == L'-')
1316 » » » } 1316 {
1317 » » } 1317 if (bHasSign)
1318 » » if (*it == L'-') 1318 {
1319 » » { 1319 FX_BOOL &bRc = pEvent->Rc();
1320 » » » if (bHasSign) 1320 bRc = FALSE;
1321 » » » { 1321 return TRUE;
1322 » » » » FX_BOOL &bRc = pEvent->Rc(); 1322 }
1323 » » » » bRc = FALSE; 1323 if (it != w_strChange2.begin()) //sign's position is not correct
1324 » » » » return TRUE; 1324 {
1325 » » » } 1325 FX_BOOL &bRc = pEvent->Rc();
1326 » » » else if (it != w_strChange2.begin()) //sign's position i s not correct 1326 bRc = FALSE;
1327 » » » { 1327 return TRUE;
1328 » » » » FX_BOOL &bRc = pEvent->Rc(); 1328 }
1329 » » » » bRc = FALSE; 1329 if (pEvent->SelStart() != 0)
1330 » » » » return TRUE; 1330 {
1331 » » » } 1331 FX_BOOL &bRc = pEvent->Rc();
1332 » » » else if (pEvent->SelStart() != 0) 1332 bRc = FALSE;
1333 » » » { 1333 return TRUE;
1334 » » » » FX_BOOL &bRc = pEvent->Rc(); 1334 }
1335 » » » » bRc = FALSE; 1335 bHasSign = TRUE;
1336 » » » » return TRUE; 1336 continue;
1337 » » » } 1337 }
1338 » » » bHasSign = TRUE;
1339 » » » continue;
1340 » » }
1341 1338
1342 » » if (!IsDigit(*it)) 1339 if (!IsDigit(*it))
1343 » » { 1340 {
1344 » » » FX_BOOL &bRc = pEvent->Rc(); 1341 FX_BOOL &bRc = pEvent->Rc();
1345 » » » bRc = FALSE; 1342 bRc = FALSE;
1346 » » » return TRUE; 1343 return TRUE;
1347 » » } 1344 }
1348 » } 1345 }
1349 1346
1350 1347
1351 » std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart()); 1348 std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
1352 » std::wstring w_postfix; 1349 std::wstring w_postfix;
1353 » if (pEvent->SelEnd()<(int)w_strValue2.length()) 1350 if (pEvent->SelEnd()<(int)w_strValue2.length())
1354 » » w_postfix = w_strValue2.substr(pEvent->SelEnd()); 1351 w_postfix = w_strValue2.substr(pEvent->SelEnd());
1355 » w_strValue2 = w_prefix + w_strChange2 + w_postfix; 1352 w_strValue2 = w_prefix + w_strChange2 + w_postfix;
1356 » w_strValue = w_strValue2.c_str(); 1353 w_strValue = w_strValue2.c_str();
1357 » val = w_strValue; 1354 val = w_strValue;
1358 » return TRUE; 1355 return TRUE;
1359 1356
1360 } 1357 }
1361 1358
1362 //function AFPercent_Format(nDec, sepStyle) 1359 //function AFPercent_Format(nDec, sepStyle)
1363 FX_BOOL CJS_PublicMethods::AFPercent_Format(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError) 1360 FX_BOOL CJS_PublicMethods::AFPercent_Format(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError)
1364 { 1361 {
1365 #if _FX_OS_ != _FX_ANDROID_ 1362 #if _FX_OS_ != _FX_ANDROID_
1366 » CJS_Context* pContext = (CJS_Context *)cc; 1363 CJS_Context* pContext = (CJS_Context *)cc;
1367 » ASSERT(pContext != NULL); 1364 ASSERT(pContext != NULL);
1368 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1365 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1369 » ASSERT(pEvent != NULL); 1366 ASSERT(pEvent != NULL);
1370 1367
1371 if (params.size() != 2) 1368 if (params.size() != 2)
1372 { 1369 {
1373 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1370 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1374 return FALSE; 1371 return FALSE;
1375 } 1372 }
1376 if(!pEvent->m_pValue) 1373 if(!pEvent->m_pValue)
1377 return FALSE; 1374 return FALSE;
1378 1375
1379 CFX_WideString& Value = pEvent->Value(); 1376 CFX_WideString& Value = pEvent->Value();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 iMax++; 1456 iMax++;
1460 } 1457 }
1461 } 1458 }
1462 //////////////////////////////////////////////////////////////////// 1459 ////////////////////////////////////////////////////////////////////
1463 //nagative mark 1460 //nagative mark
1464 if(bNagative) 1461 if(bNagative)
1465 strValue = "-" + strValue; 1462 strValue = "-" + strValue;
1466 strValue += "%"; 1463 strValue += "%";
1467 Value = CFX_WideString::FromLocal(strValue); 1464 Value = CFX_WideString::FromLocal(strValue);
1468 #endif 1465 #endif
1469 » return TRUE; 1466 return TRUE;
1470 } 1467 }
1471 //AFPercent_Keystroke(nDec, sepStyle) 1468 //AFPercent_Keystroke(nDec, sepStyle)
1472 FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Para meters& params, CJS_Value& vRet, CFX_WideString& sError) 1469 FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Para meters& params, CJS_Value& vRet, CFX_WideString& sError)
1473 { 1470 {
1474 » return AFNumber_Keystroke(cc,params,vRet,sError); 1471 return AFNumber_Keystroke(cc,params,vRet,sError);
1475 } 1472 }
1476 1473
1477 //function AFDate_FormatEx(cFormat) 1474 //function AFDate_FormatEx(cFormat)
1478 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, const CJS_Paramete rs& params, CJS_Value& vRet, CFX_WideString& sError) 1475 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, const CJS_Paramete rs& params, CJS_Value& vRet, CFX_WideString& sError)
1479 { 1476 {
1480 » CJS_Context* pContext = (CJS_Context *)cc; 1477 CJS_Context* pContext = (CJS_Context *)cc;
1481 » ASSERT(pContext != NULL); 1478 ASSERT(pContext != NULL);
1482 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1479 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1483 » ASSERT(pEvent != NULL); 1480 ASSERT(pEvent != NULL);
1484 1481
1485 » if (params.size() != 1) 1482 if (params.size() != 1)
1486 » { 1483 {
1487 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1484 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1488 » » return FALSE; 1485 return FALSE;
1489 » } 1486 }
1490 » if(!pEvent->m_pValue) 1487 if(!pEvent->m_pValue)
1491 » » return FALSE; 1488 return FALSE;
1492 1489
1493 » CFX_WideString& val = pEvent->Value(); 1490 CFX_WideString& val = pEvent->Value();
1494 » CFX_WideString strValue = val; 1491 CFX_WideString strValue = val;
1495 » if (strValue.IsEmpty()) 1492 if (strValue.IsEmpty())
1496 » » return TRUE; 1493 return TRUE;
1497 1494
1498 » CFX_WideString sFormat = params[0].ToCFXWideString(); 1495 CFX_WideString sFormat = params[0].ToCFXWideString();
1499 » FX_BOOL bWrongFormat = FALSE; 1496 FX_BOOL bWrongFormat = FALSE;
1500 » double dDate = 0.0f; 1497 double dDate = 0.0f;
1501 1498
1502 » if(strValue.Find(L"GMT") != -1) 1499 if(strValue.Find(L"GMT") != -1)
1503 » { 1500 {
1504 » » //for GMT format time 1501 //for GMT format time
1505 » » //such as "Tue Aug 11 14:24:16 GMT+08002009" 1502 //such as "Tue Aug 11 14:24:16 GMT+08002009"
1506 » » dDate = MakeInterDate(strValue); 1503 dDate = MakeInterDate(strValue);
1507 » } 1504 }
1508 » else 1505 else
1509 » { 1506 {
1510 » » dDate = MakeRegularDate(strValue,sFormat,bWrongFormat); 1507 dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
1511 » } 1508 }
1512 1509
1513 » if (JS_PortIsNan(dDate)) 1510 if (JS_PortIsNan(dDate))
1514 » { 1511 {
1515 » » CFX_WideString swMsg; 1512 CFX_WideString swMsg;
1516 » » swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE) .c_str(), sFormat.c_str()); 1513 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str() , sFormat.c_str());
1517 » » Alert(pContext, swMsg.c_str()); 1514 Alert(pContext, swMsg.c_str());
1518 » » return FALSE; 1515 return FALSE;
1519 » } 1516 }
1520 1517
1521 » val = MakeFormatDate(dDate,sFormat); 1518 val = MakeFormatDate(dDate,sFormat);
1522 » return TRUE; 1519 return TRUE;
1523 } 1520 }
1524 1521
1525 double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue) 1522 double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue)
1526 { 1523 {
1527 » int nHour; 1524 int nHour;
1528 » int nMin; 1525 int nMin;
1529 » int nSec; 1526 int nSec;
1530 » int nYear; 1527 int nYear;
1531 » int nMonth; 1528 int nMonth;
1532 » int nDay; 1529 int nDay;
1533 1530
1534 » CFX_WideStringArray wsArray; 1531 CFX_WideStringArray wsArray;
1535 » CFX_WideString sMonth = L""; 1532 CFX_WideString sMonth = L"";
1536 » CFX_WideString sTemp = L""; 1533 CFX_WideString sTemp = L"";
1537 » int nSize = strValue.GetLength(); 1534 int nSize = strValue.GetLength();
1538 1535
1539 » for(int i = 0; i < nSize; i++) 1536 for(int i = 0; i < nSize; i++)
1540 » { 1537 {
1541 » » FX_WCHAR c = strValue.GetAt(i); 1538 FX_WCHAR c = strValue.GetAt(i);
1542 » » if(c == L' ' || c == L':') 1539 if(c == L' ' || c == L':')
1543 » » { 1540 {
1544 » » » wsArray.Add(sTemp); 1541 wsArray.Add(sTemp);
1545 » » » sTemp = L""; 1542 sTemp = L"";
1546 » » » continue; 1543 continue;
1547 » » } 1544 }
1548 1545
1549 » » sTemp += c; 1546 sTemp += c;
1550 » } 1547 }
1551 1548
1552 » wsArray.Add(sTemp); 1549 wsArray.Add(sTemp);
1553 » if(wsArray.GetSize() != 8)return 0; 1550 if(wsArray.GetSize() != 8)return 0;
1554 1551
1555 » sTemp = wsArray[1]; 1552 sTemp = wsArray[1];
1556 » if(sTemp.Compare(L"Jan") == 0) nMonth = 1; 1553 if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
1557 » if(sTemp.Compare(L"Feb") == 0) nMonth = 2; 1554 if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
1558 » if(sTemp.Compare(L"Mar") == 0) nMonth = 3; 1555 if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
1559 » if(sTemp.Compare(L"Apr") == 0) nMonth = 4; 1556 if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
1560 » if(sTemp.Compare(L"May") == 0) nMonth = 5; 1557 if(sTemp.Compare(L"May") == 0) nMonth = 5;
1561 » if(sTemp.Compare(L"Jun") == 0) nMonth = 6; 1558 if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
1562 » if(sTemp.Compare(L"Jul") == 0) nMonth = 7; 1559 if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
1563 » if(sTemp.Compare(L"Aug") == 0) nMonth = 8; 1560 if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
1564 » if(sTemp.Compare(L"Sep") == 0) nMonth = 9; 1561 if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
1565 » if(sTemp.Compare(L"Oct") == 0) nMonth = 10; 1562 if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
1566 » if(sTemp.Compare(L"Nov") == 0) nMonth = 11; 1563 if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
1567 » if(sTemp.Compare(L"Dec") == 0) nMonth = 12; 1564 if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
1568 1565
1569 » nDay = (int)ParseStringToNumber(wsArray[2].c_str()); 1566 nDay = (int)ParseStringToNumber(wsArray[2].c_str());
1570 » nHour = (int)ParseStringToNumber(wsArray[3].c_str()); 1567 nHour = (int)ParseStringToNumber(wsArray[3].c_str());
1571 » nMin = (int)ParseStringToNumber(wsArray[4].c_str()); 1568 nMin = (int)ParseStringToNumber(wsArray[4].c_str());
1572 » nSec = (int)ParseStringToNumber(wsArray[5].c_str()); 1569 nSec = (int)ParseStringToNumber(wsArray[5].c_str());
1573 » nYear = (int)ParseStringToNumber(wsArray[7].c_str()); 1570 nYear = (int)ParseStringToNumber(wsArray[7].c_str());
1574 1571
1575 » double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime( nHour, nMin, nSec, 0)); 1572 double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHou r, nMin, nSec, 0));
1576 1573
1577 » if (JS_PortIsNan(dRet)) 1574 if (JS_PortIsNan(dRet))
1578 » { 1575 {
1579 » » dRet = JS_DateParse(strValue.c_str()); 1576 dRet = JS_DateParse(strValue.c_str());
1580 » } 1577 }
1581 1578
1582 » return dRet; 1579 return dRet;
1583 } 1580 }
1584 1581
1585 //AFDate_KeystrokeEx(cFormat) 1582 //AFDate_KeystrokeEx(cFormat)
1586 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError) 1583 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError)
1587 { 1584 {
1588 » CJS_Context* pContext = (CJS_Context *)cc; 1585 CJS_Context* pContext = (CJS_Context *)cc;
1589 » ASSERT(pContext != NULL); 1586 ASSERT(pContext != NULL);
1590 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1587 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1591 » ASSERT(pEvent != NULL); 1588 ASSERT(pEvent != NULL);
1592 1589
1593 » if (params.size() != 1) 1590 if (params.size() != 1)
1594 » { 1591 {
1595 » » sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; 1592 sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
1596 » » return FALSE; 1593 return FALSE;
1597 » } 1594 }
1598 1595
1599 » if (pEvent->WillCommit()) 1596 if (pEvent->WillCommit())
1600 » { 1597 {
1601 » » if(!pEvent->m_pValue) 1598 if(!pEvent->m_pValue)
1602 » » » return FALSE; 1599 return FALSE;
1603 » » CFX_WideString strValue = pEvent->Value(); 1600 CFX_WideString strValue = pEvent->Value();
1604 » » if (strValue.IsEmpty()) 1601 if (strValue.IsEmpty())
1605 » » » return TRUE; 1602 return TRUE;
1606 1603
1607 » » CFX_WideString sFormat = params[0].ToCFXWideString(); 1604 CFX_WideString sFormat = params[0].ToCFXWideString();
1608 » » FX_BOOL bWrongFormat = FALSE; 1605 FX_BOOL bWrongFormat = FALSE;
1609 » » double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat); 1606 double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
1610 » » if (bWrongFormat || JS_PortIsNan(dRet)) 1607 if (bWrongFormat || JS_PortIsNan(dRet))
1611 » » { 1608 {
1612 » » » CFX_WideString swMsg; 1609 CFX_WideString swMsg;
1613 » » » swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPA RSEDATE).c_str(), sFormat.c_str()); 1610 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_s tr(), sFormat.c_str());
1614 » » » Alert(pContext, swMsg.c_str()); 1611 Alert(pContext, swMsg.c_str());
1615 » » » pEvent->Rc() = FALSE; 1612 pEvent->Rc() = FALSE;
1616 » » » return TRUE; 1613 return TRUE;
1617 » » } 1614 }
1618 » } 1615 }
1619 » return TRUE; 1616 return TRUE;
1620 } 1617 }
1621 1618
1622 FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError) 1619 FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError)
1623 { 1620 {
1624 » v8::Isolate* isolate = ::GetIsolate(cc); 1621 v8::Isolate* isolate = ::GetIsolate(cc);
1625 1622
1626 » if (params.size() != 1) 1623 if (params.size() != 1)
1627 » { 1624 {
1628 » » CJS_Context* pContext = (CJS_Context*)cc; 1625 CJS_Context* pContext = (CJS_Context*)cc;
1629 » » ASSERT(pContext != NULL); 1626 ASSERT(pContext != NULL);
1630 1627
1631 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1628 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1632 » » return FALSE; 1629 return FALSE;
1633 » } 1630 }
1634 1631
1635 » int iIndex = params[0].ToInt(); 1632 int iIndex = params[0].ToInt();
1636 » const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy", 1633 const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d -mmm", L"d-mmm-yy", L"dd-mmm-yy",
1637 » » L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yy yy", 1634 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
1638 » » L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; 1635 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
1639 1636
1640 » ASSERT(iIndex < FX_ArraySize(cFormats)); 1637 ASSERT(iIndex < FX_ArraySize(cFormats));
1641 1638
1642 » if (iIndex < 0) 1639 if (iIndex < 0)
1643 » » iIndex = 0; 1640 iIndex = 0;
1644 » if (iIndex >= FX_ArraySize(cFormats)) 1641 if (iIndex >= FX_ArraySize(cFormats))
1645 » » iIndex = 0; 1642 iIndex = 0;
1646 » CJS_Parameters newParams; 1643 CJS_Parameters newParams;
1647 » CJS_Value val(isolate,cFormats[iIndex]); 1644 CJS_Value val(isolate,cFormats[iIndex]);
1648 » newParams.push_back(val); 1645 newParams.push_back(val);
1649 » return AFDate_FormatEx(cc,newParams,vRet,sError); 1646 return AFDate_FormatEx(cc,newParams,vRet,sError);
1650 } 1647 }
1651 1648
1652 //AFDate_KeystrokeEx(cFormat) 1649 //AFDate_KeystrokeEx(cFormat)
1653 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError) 1650 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError)
1654 { 1651 {
1655 » v8::Isolate* isolate = ::GetIsolate(cc); 1652 v8::Isolate* isolate = ::GetIsolate(cc);
1656 1653
1657 » if (params.size() != 1) 1654 if (params.size() != 1)
1658 » { 1655 {
1659 » » CJS_Context* pContext = (CJS_Context*)cc; 1656 CJS_Context* pContext = (CJS_Context*)cc;
1660 » » ASSERT(pContext != NULL); 1657 ASSERT(pContext != NULL);
1661 1658
1662 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1659 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1663 » » return FALSE; 1660 return FALSE;
1664 » } 1661 }
1665 1662
1666 » int iIndex = params[0].ToInt(); 1663 int iIndex = params[0].ToInt();
1667 » const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy", 1664 const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d -mmm", L"d-mmm-yy", L"dd-mmm-yy",
1668 » » L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yy yy", 1665 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy",
1669 » » L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; 1666 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" };
1670 1667
1671 » ASSERT(iIndex<FX_ArraySize(cFormats)); 1668 ASSERT(iIndex<FX_ArraySize(cFormats));
1672 1669
1673 » if (iIndex < 0) 1670 if (iIndex < 0)
1674 » » iIndex = 0; 1671 iIndex = 0;
1675 » if (iIndex >= FX_ArraySize(cFormats)) 1672 if (iIndex >= FX_ArraySize(cFormats))
1676 » » iIndex = 0; 1673 iIndex = 0;
1677 » CJS_Parameters newParams; 1674 CJS_Parameters newParams;
1678 » CJS_Value val(isolate,cFormats[iIndex]); 1675 CJS_Value val(isolate,cFormats[iIndex]);
1679 » newParams.push_back(val); 1676 newParams.push_back(val);
1680 » return AFDate_KeystrokeEx(cc,newParams,vRet,sError); 1677 return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
1681 } 1678 }
1682 1679
1683 //function AFTime_Format(ptf) 1680 //function AFTime_Format(ptf)
1684 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError) 1681 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError)
1685 { 1682 {
1686 » v8::Isolate* isolate = ::GetIsolate(cc); 1683 v8::Isolate* isolate = ::GetIsolate(cc);
1687 1684
1688 » if (params.size() != 1) 1685 if (params.size() != 1)
1689 » { 1686 {
1690 » » CJS_Context* pContext = (CJS_Context*)cc; 1687 CJS_Context* pContext = (CJS_Context*)cc;
1691 » » ASSERT(pContext != NULL); 1688 ASSERT(pContext != NULL);
1692 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1689 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1693 » » return FALSE; 1690 return FALSE;
1694 » } 1691 }
1695 1692
1696 » int iIndex = params[0].ToInt(); 1693 int iIndex = params[0].ToInt();
1697 » const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM: ss tt"}; 1694 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss t t"};
1698 1695
1699 » ASSERT(iIndex<FX_ArraySize(cFormats)); 1696 ASSERT(iIndex<FX_ArraySize(cFormats));
1700 1697
1701 » if (iIndex < 0) 1698 if (iIndex < 0)
1702 » » iIndex = 0; 1699 iIndex = 0;
1703 » if (iIndex >= FX_ArraySize(cFormats)) 1700 if (iIndex >= FX_ArraySize(cFormats))
1704 » » iIndex = 0; 1701 iIndex = 0;
1705 » CJS_Parameters newParams; 1702 CJS_Parameters newParams;
1706 » CJS_Value val(isolate,cFormats[iIndex]); 1703 CJS_Value val(isolate,cFormats[iIndex]);
1707 » newParams.push_back(val); 1704 newParams.push_back(val);
1708 » return AFDate_FormatEx(cc,newParams,vRet,sError); 1705 return AFDate_FormatEx(cc,newParams,vRet,sError);
1709 } 1706 }
1710 1707
1711 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError) 1708 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError)
1712 { 1709 {
1713 » v8::Isolate* isolate = ::GetIsolate(cc); 1710 v8::Isolate* isolate = ::GetIsolate(cc);
1714 » if (params.size() != 1) 1711 if (params.size() != 1)
1715 » { 1712 {
1716 » » CJS_Context* pContext = (CJS_Context*)cc; 1713 CJS_Context* pContext = (CJS_Context*)cc;
1717 » » ASSERT(pContext != NULL); 1714 ASSERT(pContext != NULL);
1718 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1715 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1719 » » return FALSE; 1716 return FALSE;
1720 » } 1717 }
1721 1718
1722 » int iIndex = params[0].ToInt(); 1719 int iIndex = params[0].ToInt();
1723 » const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM: ss tt"}; 1720 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss t t"};
1724 1721
1725 » ASSERT(iIndex<FX_ArraySize(cFormats)); 1722 ASSERT(iIndex<FX_ArraySize(cFormats));
1726 1723
1727 » if (iIndex < 0) 1724 if (iIndex < 0)
1728 » » iIndex = 0; 1725 iIndex = 0;
1729 » if (iIndex >= FX_ArraySize(cFormats)) 1726 if (iIndex >= FX_ArraySize(cFormats))
1730 » » iIndex = 0; 1727 iIndex = 0;
1731 » CJS_Parameters newParams; 1728 CJS_Parameters newParams;
1732 » CJS_Value val(isolate,cFormats[iIndex]); 1729 CJS_Value val(isolate,cFormats[iIndex]);
1733 » newParams.push_back(val); 1730 newParams.push_back(val);
1734 » return AFDate_KeystrokeEx(cc,newParams,vRet,sError); 1731 return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
1735 } 1732 }
1736 1733
1737 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, const CJS_Paramete rs& params, CJS_Value& vRet, CFX_WideString& sError) 1734 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, const CJS_Paramete rs& params, CJS_Value& vRet, CFX_WideString& sError)
1738 { 1735 {
1739 » return AFDate_FormatEx(cc,params,vRet,sError); 1736 return AFDate_FormatEx(cc,params,vRet,sError);
1740 } 1737 }
1741 1738
1742 FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError) 1739 FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError)
1743 { 1740 {
1744 » return AFDate_KeystrokeEx(cc,params,vRet,sError); 1741 return AFDate_KeystrokeEx(cc,params,vRet,sError);
1745 } 1742 }
1746 1743
1747 //function AFSpecial_Format(psf) 1744 //function AFSpecial_Format(psf)
1748 FX_BOOL CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError) 1745 FX_BOOL CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError)
1749 { 1746 {
1750 » CJS_Context* pContext = (CJS_Context *)cc; 1747 CJS_Context* pContext = (CJS_Context *)cc;
1751 » ASSERT(pContext != NULL); 1748 ASSERT(pContext != NULL);
1752 1749
1753 » if (params.size() != 1) 1750 if (params.size() != 1)
1754 » { 1751 {
1755 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1752 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1756 » » return FALSE; 1753 return FALSE;
1757 » } 1754 }
1758 1755
1759 » std::string cFormat; 1756 std::string cFormat;
1760 » int iIndex = params[0].ToInt(); 1757 int iIndex = params[0].ToInt();
1761 1758
1762 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1759 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1763 » ASSERT(pEvent != NULL); 1760 ASSERT(pEvent != NULL);
1764 1761
1765 » if(!pEvent->m_pValue) 1762 if(!pEvent->m_pValue)
1766 » » return FALSE; 1763 return FALSE;
1767 » CFX_WideString& Value = pEvent->Value(); 1764 CFX_WideString& Value = pEvent->Value();
1768 » std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str(); 1765 std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str();
1769 1766
1770 » switch (iIndex) 1767 switch (iIndex)
1771 » { 1768 {
1772 » case 0: 1769 case 0:
1773 » » cFormat = "99999"; 1770 cFormat = "99999";
1774 » » break; 1771 break;
1775 » case 1: 1772 case 1:
1776 » » cFormat = "99999-9999"; 1773 cFormat = "99999-9999";
1777 » » break; 1774 break;
1778 » case 2: 1775 case 2:
1779 » » { 1776 {
1780 » » » std::string NumberStr; 1777 std::string NumberStr;
1781 » » » util::printx("9999999999", strSrc,NumberStr); 1778 util::printx("9999999999", strSrc,NumberStr);
1782 » » » if (NumberStr.length() >= 10 ) 1779 if (NumberStr.length() >= 10 )
1783 » » » » cFormat = "(999) 999-9999"; 1780 cFormat = "(999) 999-9999";
1784 » » » else 1781 else
1785 » » » » cFormat = "999-9999"; 1782 cFormat = "999-9999";
1786 » » » break; 1783 break;
1787 » » } 1784 }
1788 » case 3: 1785 case 3:
1789 » » cFormat = "999-99-9999"; 1786 cFormat = "999-99-9999";
1790 » » break; 1787 break;
1791 » } 1788 }
1792 1789
1793 » std::string strDes; 1790 std::string strDes;
1794 » util::printx(cFormat,strSrc,strDes); 1791 util::printx(cFormat,strSrc,strDes);
1795 » Value = CFX_WideString::FromLocal(strDes.c_str()); 1792 Value = CFX_WideString::FromLocal(strDes.c_str());
1796 » return TRUE; 1793 return TRUE;
1797 } 1794 }
1798 1795
1799 1796
1800 //function AFSpecial_KeystrokeEx(mask) 1797 //function AFSpecial_KeystrokeEx(mask)
1801 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Pa rameters& params, CJS_Value& vRet, CFX_WideString& sError) 1798 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Pa rameters& params, CJS_Value& vRet, CFX_WideString& sError)
1802 { 1799 {
1803 » CJS_Context* pContext = (CJS_Context *)cc; 1800 CJS_Context* pContext = (CJS_Context *)cc;
1804 » ASSERT(pContext != NULL); 1801 ASSERT(pContext != NULL);
1805 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1802 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1806 1803
1807 » ASSERT(pEvent != NULL); 1804 ASSERT(pEvent != NULL);
1808 1805
1809 » if (params.size() < 1) 1806 if (params.size() < 1)
1810 » { 1807 {
1811 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1808 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1812 » » return FALSE; 1809 return FALSE;
1813 » } 1810 }
1814 1811
1815 » if(!pEvent->m_pValue) 1812 if(!pEvent->m_pValue)
1816 » » return FALSE; 1813 return FALSE;
1817 » CFX_WideString& valEvent = pEvent->Value(); 1814 CFX_WideString& valEvent = pEvent->Value();
1818 1815
1819 » CFX_WideString wstrMask = params[0].ToCFXWideString(); 1816 CFX_WideString wstrMask = params[0].ToCFXWideString();
1820 » if (wstrMask.IsEmpty()) 1817 if (wstrMask.IsEmpty())
1821 » » return TRUE; 1818 return TRUE;
1822 1819
1823 » std::wstring wstrValue = valEvent.c_str(); 1820 std::wstring wstrValue = valEvent.c_str();
1824 1821
1825 » if (pEvent->WillCommit()) 1822 if (pEvent->WillCommit())
1826 » { 1823 {
1827 » » if (wstrValue.empty()) 1824 if (wstrValue.empty())
1828 » » » return TRUE; 1825 return TRUE;
1829 » » int iIndexMask = 0; 1826 int iIndexMask = 0;
1830 » » for (std::wstring::iterator it = wstrValue.begin(); it != wstrVa lue.end(); it++) 1827 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end( ); it++)
1831 » » { 1828 {
1832 » » » wchar_t w_Value = *it; 1829 wchar_t w_Value = *it;
1833 » » » if (!maskSatisfied(w_Value,wstrMask[iIndexMask])) 1830 if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
1834 » » » » break; 1831 break;
1835 » » » iIndexMask++; 1832 iIndexMask++;
1836 » » } 1833 }
1837 1834
1838 » » if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrVal ue.size() && wstrMask.GetLength() != 0)) 1835 if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size( ) && wstrMask.GetLength() != 0))
1839 » » { 1836 {
1840 » » » Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_J SAFNUMBER_KEYSTROKE).c_str()); 1837 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KE YSTROKE).c_str());
1841 » » » pEvent->Rc() = FALSE; 1838 pEvent->Rc() = FALSE;
1842 » » } 1839 }
1843 » » return TRUE; 1840 return TRUE;
1844 » } 1841 }
1845 1842
1846 » CFX_WideString &wideChange = pEvent->Change(); 1843 CFX_WideString &wideChange = pEvent->Change();
1847 » std::wstring wChange = wideChange.c_str(); 1844 std::wstring wChange = wideChange.c_str();
1848 » if (wChange.empty()) 1845 if (wChange.empty())
1849 » » return TRUE; 1846 return TRUE;
1850 1847
1851 » int iIndexMask = pEvent->SelStart(); 1848 int iIndexMask = pEvent->SelStart();
1852 1849
1853 » if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange .length() > (FX_DWORD)wstrMask.GetLength()) 1850 if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.len gth() > (FX_DWORD)wstrMask.GetLength())
1854 » { 1851 {
1855 » » Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_T OOLONG).c_str()); 1852 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG). c_str());
1856 » » pEvent->Rc() = FALSE; 1853 pEvent->Rc() = FALSE;
1857 » » return TRUE; 1854 return TRUE;
1858 » } 1855 }
1859 1856
1860 » if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) 1857 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
1861 » { 1858 {
1862 » » Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_T OOLONG).c_str()); 1859 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG). c_str());
1863 » » pEvent->Rc() = FALSE; 1860 pEvent->Rc() = FALSE;
1864 » » return TRUE; 1861 return TRUE;
1865 » } 1862 }
1866 1863
1867 » for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); i t++) 1864 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
1868 » { 1865 {
1869 » » if (iIndexMask >= wstrMask.GetLength()) 1866 if (iIndexMask >= wstrMask.GetLength())
1870 » » { 1867 {
1871 » » » Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_J SPARAM_TOOLONG).c_str()); 1868 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLO NG).c_str());
1872 » » » pEvent->Rc() = FALSE; 1869 pEvent->Rc() = FALSE;
1873 » » » return TRUE; 1870 return TRUE;
1874 » » } 1871 }
1875 » » wchar_t w_Mask = wstrMask[iIndexMask]; 1872 wchar_t w_Mask = wstrMask[iIndexMask];
1876 » » if (!isReservedMaskChar(w_Mask)) 1873 if (!isReservedMaskChar(w_Mask))
1877 » » { 1874 {
1878 » » » *it = w_Mask; 1875 *it = w_Mask;
1879 » » } 1876 }
1880 » » wchar_t w_Change = *it; 1877 wchar_t w_Change = *it;
1881 » » if (!maskSatisfied(w_Change,w_Mask)) 1878 if (!maskSatisfied(w_Change,w_Mask))
1882 » » { 1879 {
1883 » » » pEvent->Rc() = FALSE; 1880 pEvent->Rc() = FALSE;
1884 » » » return TRUE; 1881 return TRUE;
1885 » » } 1882 }
1886 » » iIndexMask++; 1883 iIndexMask++;
1887 » } 1884 }
1888 1885
1889 » wideChange = wChange.c_str(); 1886 wideChange = wChange.c_str();
1890 » return TRUE; 1887 return TRUE;
1891 } 1888 }
1892 1889
1893 1890
1894 //function AFSpecial_Keystroke(psf) 1891 //function AFSpecial_Keystroke(psf)
1895 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Para meters& params, CJS_Value& vRet, CFX_WideString& sError) 1892 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Para meters& params, CJS_Value& vRet, CFX_WideString& sError)
1896 { 1893 {
1897 » v8::Isolate* isolate = ::GetIsolate(cc); 1894 v8::Isolate* isolate = ::GetIsolate(cc);
1898 1895
1899 » CJS_Context* pContext = (CJS_Context *)cc; 1896 CJS_Context* pContext = (CJS_Context *)cc;
1900 » ASSERT(pContext != NULL); 1897 ASSERT(pContext != NULL);
1901 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1898 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1902 » ASSERT(pEvent != NULL); 1899 ASSERT(pEvent != NULL);
1903 1900
1904 » if (params.size() != 1) 1901 if (params.size() != 1)
1905 » { 1902 {
1906 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1903 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1907 » » return FALSE; 1904 return FALSE;
1908 » } 1905 }
1909 1906
1910 » std::string cFormat; 1907 std::string cFormat;
1911 » int iIndex = params[0].ToInt(); 1908 int iIndex = params[0].ToInt();
1912 1909
1913 » if(!pEvent->m_pValue) 1910 if(!pEvent->m_pValue)
1914 » » return FALSE; 1911 return FALSE;
1915 » //CJS_Value val = pEvent->Value(); 1912 //CJS_Value val = pEvent->Value();
1916 » CFX_WideString& val = pEvent->Value(); 1913 CFX_WideString& val = pEvent->Value();
1917 » std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); 1914 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str();
1918 » std::wstring wstrChange = pEvent->Change().c_str(); 1915 std::wstring wstrChange = pEvent->Change().c_str();
1919 1916
1920 » switch (iIndex) 1917 switch (iIndex)
1921 » { 1918 {
1922 » case 0: 1919 case 0:
1923 » » cFormat = "99999"; 1920 cFormat = "99999";
1924 » » break; 1921 break;
1925 » case 1: 1922 case 1:
1926 » » //cFormat = "99999-9999"; 1923 //cFormat = "99999-9999";
1927 » » cFormat = "999999999"; 1924 cFormat = "999999999";
1928 » » break; 1925 break;
1929 » case 2: 1926 case 2:
1930 » » { 1927 {
1931 » » » std::string NumberStr; 1928 std::string NumberStr;
1932 » » » util::printx("9999999999", strSrc,NumberStr); 1929 util::printx("9999999999", strSrc,NumberStr);
1933 » » » if (strSrc.length() + wstrChange.length() > 7 ) 1930 if (strSrc.length() + wstrChange.length() > 7 )
1934 » » » » //cFormat = "(999) 999-9999"; 1931 //cFormat = "(999) 999-9999";
1935 » » » » cFormat = "9999999999"; 1932 cFormat = "9999999999";
1936 » » » else 1933 else
1937 » » » » //cFormat = "999-9999"; 1934 //cFormat = "999-9999";
1938 » » » » cFormat = "9999999"; 1935 cFormat = "9999999";
1939 » » » break; 1936 break;
1940 » » } 1937 }
1941 » case 3: 1938 case 3:
1942 » » //cFormat = "999-99-9999"; 1939 //cFormat = "999-99-9999";
1943 » » cFormat = "999999999"; 1940 cFormat = "999999999";
1944 » » break; 1941 break;
1945 » } 1942 }
1946 1943
1947 » CJS_Parameters params2; 1944 CJS_Parameters params2;
1948 » CJS_Value vMask(isolate, cFormat.c_str()); 1945 CJS_Value vMask(isolate, cFormat.c_str());
1949 » params2.push_back(vMask); 1946 params2.push_back(vMask);
1950 1947
1951 return AFSpecial_KeystrokeEx(cc,params2,vRet,sError); 1948 return AFSpecial_KeystrokeEx(cc,params2,vRet,sError);
1952 } 1949 }
1953 1950
1954 FX_BOOL CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError) 1951 FX_BOOL CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError)
1955 { 1952 {
1956 » CJS_Context* pContext = (CJS_Context *)cc; 1953 CJS_Context* pContext = (CJS_Context *)cc;
1957 » ASSERT(pContext != NULL); 1954 ASSERT(pContext != NULL);
1958 » CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); 1955 CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
1959 » ASSERT(pEventHandler != NULL); 1956 ASSERT(pEventHandler != NULL);
1960 1957
1961 » if (params.size() != 1) 1958 if (params.size() != 1)
1962 » { 1959 {
1963 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1960 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1964 » » return FALSE; 1961 return FALSE;
1965 » } 1962 }
1966 1963
1967 » CFX_WideString swValue; 1964 CFX_WideString swValue;
1968 » if (pEventHandler->m_pValue != NULL) 1965 if (pEventHandler->m_pValue != NULL)
1969 » » swValue = pEventHandler->Value(); 1966 swValue = pEventHandler->Value();
1970 1967
1971 » if (pEventHandler->WillCommit()) 1968 if (pEventHandler->WillCommit())
1972 » { 1969 {
1973 » » vRet = swValue.c_str(); 1970 vRet = swValue.c_str();
1974 » » return TRUE; 1971 return TRUE;
1975 » } 1972 }
1976 1973
1977 » CFX_WideString prefix,postfix; 1974 CFX_WideString prefix,postfix;
1978 1975
1979 » if (pEventHandler->SelStart() >= 0) 1976 if (pEventHandler->SelStart() >= 0)
1980 » » prefix = swValue.Mid(0,pEventHandler->SelStart()); 1977 prefix = swValue.Mid(0,pEventHandler->SelStart());
1981 » else 1978 else
1982 » » prefix = L""; 1979 prefix = L"";
1983 1980
1984 1981
1985 » if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.G etLength()) 1982 if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLe ngth())
1986 » » postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength () - pEventHandler->SelEnd()); 1983 postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEv entHandler->SelEnd());
1987 » else postfix = L""; 1984 else postfix = L"";
1988 1985
1989 » vRet = (prefix + pEventHandler->Change() + postfix).c_str(); 1986 vRet = (prefix + pEventHandler->Change() + postfix).c_str();
1990 1987
1991 » return TRUE; 1988 return TRUE;
1992 } 1989 }
1993 1990
1994 FX_BOOL CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError) 1991 FX_BOOL CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError)
1995 { 1992 {
1996 » CJS_Context* pContext = (CJS_Context *)cc; 1993 CJS_Context* pContext = (CJS_Context *)cc;
1997 » ASSERT(pContext != NULL); 1994 ASSERT(pContext != NULL);
1998 1995
1999 » if (params.size() != 2) 1996 if (params.size() != 2)
2000 » { 1997 {
2001 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1998 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2002 » » return FALSE; 1999 return FALSE;
2003 » } 2000 }
2004 2001
2005 » CFX_WideString sValue = params[0].ToCFXWideString(); 2002 CFX_WideString sValue = params[0].ToCFXWideString();
2006 » CFX_WideString sFormat = params[1].ToCFXWideString(); 2003 CFX_WideString sFormat = params[1].ToCFXWideString();
2007 2004
2008 » FX_BOOL bWrongFormat = FALSE; 2005 FX_BOOL bWrongFormat = FALSE;
2009 » double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat); 2006 double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
2010 2007
2011 » if (JS_PortIsNan(dDate)) 2008 if (JS_PortIsNan(dDate))
2012 » { 2009 {
2013 » » CFX_WideString swMsg; 2010 CFX_WideString swMsg;
2014 » » swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE) .c_str(), sFormat.c_str()); 2011 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str() , sFormat.c_str());
2015 » » Alert((CJS_Context *)cc, swMsg.c_str()); 2012 Alert((CJS_Context *)cc, swMsg.c_str());
2016 » » return FALSE; 2013 return FALSE;
2017 » } 2014 }
2018 2015
2019 » vRet = dDate; 2016 vRet = dDate;
2020 » return TRUE; 2017 return TRUE;
2021 } 2018 }
2022 2019
2023 FX_BOOL CJS_PublicMethods::AFSimple(IFXJS_Context* cc, const CJS_Parameters& par ams, CJS_Value& vRet, CFX_WideString& sError) 2020 FX_BOOL CJS_PublicMethods::AFSimple(IFXJS_Context* cc, const CJS_Parameters& par ams, CJS_Value& vRet, CFX_WideString& sError)
2024 { 2021 {
2025 » if (params.size() != 3) 2022 if (params.size() != 3)
2026 » { 2023 {
2027 » » CJS_Context* pContext = (CJS_Context *)cc; 2024 CJS_Context* pContext = (CJS_Context *)cc;
2028 » » ASSERT(pContext != NULL); 2025 ASSERT(pContext != NULL);
2029 2026
2030 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2027 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2031 » » return FALSE; 2028 return FALSE;
2032 » } 2029 }
2033 2030
2034 » vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1]. ToDouble(), params[2].ToDouble()); 2031 vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1].ToDo uble(), params[2].ToDouble());
2035 » return TRUE; 2032 return TRUE;
2036 } 2033 }
2037 2034
2038 FX_BOOL CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 2035 FX_BOOL CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
2039 { 2036 {
2040 » if (params.size() != 1) 2037 if (params.size() != 1)
2041 » { 2038 {
2042 » » CJS_Context* pContext = (CJS_Context *)cc; 2039 CJS_Context* pContext = (CJS_Context *)cc;
2043 » » ASSERT(pContext != NULL); 2040 ASSERT(pContext != NULL);
2044 2041
2045 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2042 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2046 » » return FALSE; 2043 return FALSE;
2047 » } 2044 }
2048 » vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); 2045 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str());
2049 » return TRUE; 2046 return TRUE;
2050 } 2047 }
2051 2048
2052 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError) 2049 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Param eters& params, CJS_Value& vRet, CFX_WideString& sError)
2053 { 2050 {
2054 » v8::Isolate* isolate = ::GetIsolate(cc); 2051 v8::Isolate* isolate = ::GetIsolate(cc);
2055 2052
2056 » CJS_Context* pContext = (CJS_Context *)cc; 2053 CJS_Context* pContext = (CJS_Context *)cc;
2057 » ASSERT(pContext != NULL); 2054 ASSERT(pContext != NULL);
2058 2055
2059 » if (params.size() != 2) 2056 if (params.size() != 2)
2060 » { 2057 {
2061 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2058 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2062 » » return FALSE; 2059 return FALSE;
2063 » } 2060 }
2064 2061
2065 » CJS_Value params1 = params[1]; 2062 CJS_Value params1 = params[1];
2066 2063
2067 » if (!params1.IsArrayObject() && params1.GetType() != VT_string) 2064 if (!params1.IsArrayObject() && params1.GetType() != VT_string)
2068 » { 2065 {
2069 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2066 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2070 » » return FALSE; 2067 return FALSE;
2071 » } 2068 }
2072 2069
2073 » CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); 2070 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
2074 ASSERT(pReaderDoc != NULL); 2071 ASSERT(pReaderDoc != NULL);
2075 2072
2076 » CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); 2073 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
2077 » ASSERT(pReaderInterForm != NULL); 2074 ASSERT(pReaderInterForm != NULL);
2078 2075
2079 » CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); 2076 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
2080 » ASSERT(pInterForm != NULL); 2077 ASSERT(pInterForm != NULL);
2081 2078
2082 » double dValue; 2079 double dValue;
2083 » CFX_WideString sFunction = params[0].ToCFXWideString(); 2080 CFX_WideString sFunction = params[0].ToCFXWideString();
2084 » if (wcscmp(sFunction.c_str(), L"PRD") == 0) 2081 if (wcscmp(sFunction.c_str(), L"PRD") == 0)
2085 » dValue = 1.0; 2082 dValue = 1.0;
2086 » else 2083 else
2087 » » dValue = 0.0; 2084 dValue = 0.0;
2088 2085
2089 » CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1); 2086 CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
2090 2087
2091 » int nFieldsCount = 0; 2088 int nFieldsCount = 0;
2092 2089
2093 » for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++) 2090 for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
2094 » { 2091 {
2095 » » CJS_Value jsValue(isolate); 2092 CJS_Value jsValue(isolate);
2096 » » FieldNameArray.GetElement(i,jsValue); 2093 FieldNameArray.GetElement(i,jsValue);
2097 » » CFX_WideString wsFieldName = jsValue.ToCFXWideString(); 2094 CFX_WideString wsFieldName = jsValue.ToCFXWideString();
2098 2095
2099 for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++) 2096 for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++)
2100 » » { 2097 {
2101 » » » if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) 2098 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName ))
2102 » » » { 2099 {
2103 » » » » double dTemp = 0.0; 2100 double dTemp = 0.0;
2104 2101
2105 » » » » switch (pFormField->GetFieldType()) 2102 switch (pFormField->GetFieldType())
2106 » » » » { 2103 {
2107 » » » » case FIELDTYPE_TEXTFIELD: 2104 case FIELDTYPE_TEXTFIELD:
2108 » » » » case FIELDTYPE_COMBOBOX: 2105 case FIELDTYPE_COMBOBOX:
2109 » » » » » { 2106 {
2110 » » » » » » dTemp = ParseStringToNumber(pFor mField->GetValue().c_str()); 2107 dTemp = ParseStringToNumber(pFormField->GetValue().c_str ());
2111 » » » » » » break; 2108 break;
2112 » » » » » } 2109 }
2113 » » » » case FIELDTYPE_PUSHBUTTON: 2110 case FIELDTYPE_PUSHBUTTON:
2114 » » » » » { 2111 {
2115 » » » » » » dTemp = 0.0; 2112 dTemp = 0.0;
2116 » » » » » » break; 2113 break;
2117 » » » » » } 2114 }
2118 » » » » case FIELDTYPE_CHECKBOX: 2115 case FIELDTYPE_CHECKBOX:
2119 » » » » case FIELDTYPE_RADIOBUTTON: 2116 case FIELDTYPE_RADIOBUTTON:
2120 » » » » » { 2117 {
2121 » » » » » » dTemp = 0.0; 2118 dTemp = 0.0;
2122 » » » » » » for (int c=0,csz=pFormField->Cou ntControls(); c<csz; c++) 2119 for (int c=0,csz=pFormField->CountControls(); c<csz; c++ )
2123 » » » » » » { 2120 {
2124 » » » » » » » if (CPDF_FormControl* pF ormCtrl = pFormField->GetControl(c)) 2121 if (CPDF_FormControl* pFormCtrl = pFormField->GetCon trol(c))
2125 » » » » » » » { 2122 {
2126 » » » » » » » » if (pFormCtrl->I sChecked()) 2123 if (pFormCtrl->IsChecked())
2127 » » » » » » » » { 2124 {
2128 » » » » » » » » » dTemp += ParseStringToNumber(pFormCtrl->GetExportValue().c_str()); 2125 dTemp += ParseStringToNumber(pFormCtrl->GetE xportValue().c_str());
2129 » » » » » » » » » break; 2126 break;
2130 » » » » » » » » } 2127 }
2131 » » » » » » » » else 2128 else
2132 » » » » » » » » » continue ; 2129 continue;
2133 » » » » » » » } 2130 }
2134 » » » » » » } 2131 }
2135 » » » » » » break; 2132 break;
2136 » » » » » } 2133 }
2137 » » » » case FIELDTYPE_LISTBOX: 2134 case FIELDTYPE_LISTBOX:
2138 » » » » » { 2135 {
2139 » » » » » » dTemp = 0.0; 2136 dTemp = 0.0;
2140 » » » » » » if (pFormField->CountSelectedIte ms() > 1) 2137 if (pFormField->CountSelectedItems() > 1)
2141 » » » » » » » break; 2138 break;
2142 » » » » » » else 2139 else
2143 » » » » » » { 2140 {
2144 » » » » » » » dTemp = ParseStringToNum ber(pFormField->GetValue().c_str()); 2141 dTemp = ParseStringToNumber(pFormField->GetValue().c _str());
2145 » » » » » » » break; 2142 break;
2146 » » » » » » } 2143 }
2147 » » » » » } 2144 }
2148 » » » » default: 2145 default:
2149 » » » » » break; 2146 break;
2150 » » » » } 2147 }
2151 2148
2152 » » » » if (i == 0 && j == 0 && (wcscmp(sFunction.c_str( ), L"MIN") == 0 || wcscmp(sFunction.c_str(), L"MAX") == 0)) 2149 if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || wcscmp(sFunction.c_str(), L"MAX") == 0))
2153 » » » » » dValue = dTemp; 2150 dValue = dTemp;
2154 2151
2155 » » » » dValue = AF_Simple(sFunction.c_str(), dValue, dT emp); 2152 dValue = AF_Simple(sFunction.c_str(), dValue, dTemp);
2156 2153
2157 » » » » nFieldsCount++; 2154 nFieldsCount++;
2158 » » » } 2155 }
2159 » » } 2156 }
2160 » } 2157 }
2161 2158
2162 » if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) 2159 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0)
2163 » » dValue /= nFieldsCount; 2160 dValue /= nFieldsCount;
2164 2161
2165 » dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6); 2162 dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FX SYS_pow((double)10,(double)6);
2166 » CJS_Value jsValue(isolate,dValue); 2163 CJS_Value jsValue(isolate,dValue);
2167 » if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue) 2164 if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
2168 » » ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsVa lue.ToCFXWideString(); 2165 ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue.ToCF XWideString();
2169 2166
2170 » return TRUE; 2167 return TRUE;
2171 } 2168 }
2172 2169
2173 /* This function validates the current event to ensure that its value is 2170 /* This function validates the current event to ensure that its value is
2174 ** within the specified range. */ 2171 ** within the specified range. */
2175 2172
2176 FX_BOOL CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError) 2173 FX_BOOL CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, const CJS_Paramet ers& params, CJS_Value& vRet, CFX_WideString& sError)
2177 { 2174 {
2178 » CJS_Context* pContext = (CJS_Context *)cc; 2175 CJS_Context* pContext = (CJS_Context *)cc;
2179 » ASSERT(pContext != NULL); 2176 ASSERT(pContext != NULL);
2180 » CJS_EventHandler* pEvent = pContext->GetEventHandler(); 2177 CJS_EventHandler* pEvent = pContext->GetEventHandler();
2181 » ASSERT(pEvent != NULL); 2178 ASSERT(pEvent != NULL);
2182 2179
2183 » if (params.size() != 4) 2180 if (params.size() != 4)
2184 » { 2181 {
2185 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2182 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2186 » » return FALSE; 2183 return FALSE;
2187 » } 2184 }
2188 2185
2189 » if(!pEvent->m_pValue) 2186 if(!pEvent->m_pValue)
2190 » » return FALSE; 2187 return FALSE;
2191 » if (pEvent->Value().IsEmpty() ) 2188 if (pEvent->Value().IsEmpty() )
2192 » » return TRUE; 2189 return TRUE;
2193 » double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value())); 2190 double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
2194 » FX_BOOL bGreaterThan = params[0].ToBool(); 2191 FX_BOOL bGreaterThan = params[0].ToBool();
2195 » double dGreaterThan = params[1].ToDouble(); 2192 double dGreaterThan = params[1].ToDouble();
2196 » FX_BOOL bLessThan = params[2].ToBool(); 2193 FX_BOOL bLessThan = params[2].ToBool();
2197 » double dLessThan = params[3].ToDouble(); 2194 double dLessThan = params[3].ToDouble();
2198 » CFX_WideString swMsg; 2195 CFX_WideString swMsg;
2199 2196
2200 » if (bGreaterThan && bLessThan) 2197 if (bGreaterThan && bLessThan)
2201 » { 2198 {
2202 » » if (dEentValue < dGreaterThan || dEentValue > dLessThan) 2199 if (dEentValue < dGreaterThan || dEentValue > dLessThan)
2203 » » » swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRA NGE1).c_str(), 2200 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str( ),
2204 » » » » » » params[1].ToCFXWideString().c_s tr(), 2201 params[1].ToCFXWideString().c_str(),
2205 » » » » » » params[3].ToCFXWideString().c_s tr()); 2202 params[3].ToCFXWideString().c_str());
2206 » } 2203 }
2207 » else if (bGreaterThan) 2204 else if (bGreaterThan)
2208 » { 2205 {
2209 » » if (dEentValue < dGreaterThan) 2206 if (dEentValue < dGreaterThan)
2210 » » » swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRA NGE2).c_str(), 2207 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str( ),
2211 » » » » » » params[1].ToCFXWideString().c_s tr()); 2208 params[1].ToCFXWideString().c_str());
2212 » } 2209 }
2213 » else if (bLessThan) 2210 else if (bLessThan)
2214 » { 2211 {
2215 » » if (dEentValue > dLessThan) 2212 if (dEentValue > dLessThan)
2216 » » » swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRA NGE3).c_str(), 2213 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str( ),
2217 » » » » » » params[3].ToCFXWideString().c_s tr()); 2214 params[3].ToCFXWideString().c_str());
2218 » } 2215 }
2219 2216
2220 » if (!swMsg.IsEmpty()) 2217 if (!swMsg.IsEmpty())
2221 » { 2218 {
2222 » » Alert(pContext, swMsg.c_str()); 2219 Alert(pContext, swMsg.c_str());
2223 » » pEvent->Rc() = FALSE; 2220 pEvent->Rc() = FALSE;
2224 » } 2221 }
2225 » return TRUE; 2222 return TRUE;
2226 } 2223 }
2227 2224
2228 FX_BOOL CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError) 2225 FX_BOOL CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, const CJS_Parameters & params, CJS_Value& vRet, CFX_WideString& sError)
2229 { 2226 {
2230 » v8::Isolate* isolate = ::GetIsolate(cc); 2227 v8::Isolate* isolate = ::GetIsolate(cc);
2231 » CJS_Context* pContext = (CJS_Context*)cc; 2228 CJS_Context* pContext = (CJS_Context*)cc;
2232 » ASSERT(pContext != NULL); 2229 ASSERT(pContext != NULL);
2233 2230
2234 » if (params.size() != 1) 2231 if (params.size() != 1)
2235 » { 2232 {
2236 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2233 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2237 » » return FALSE; 2234 return FALSE;
2238 » } 2235 }
2239 2236
2240 » CJS_Array nums(isolate); 2237 CJS_Array nums(isolate);
2241 2238
2242 » CFX_WideString str = params[0].ToCFXWideString(); 2239 CFX_WideString str = params[0].ToCFXWideString();
2243 » CFX_WideString sPart; 2240 CFX_WideString sPart;
2244 2241
2245 » if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') 2242 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
2246 » » str = L"0" + str; 2243 str = L"0" + str;
2247 2244
2248 » int nIndex = 0; 2245 int nIndex = 0;
2249 » for (int i=0, sz=str.GetLength(); i<sz; i++) 2246 for (int i=0, sz=str.GetLength(); i<sz; i++)
2250 » { 2247 {
2251 » » FX_WCHAR wc = str.GetAt(i); 2248 FX_WCHAR wc = str.GetAt(i);
2252 » » if (IsDigit((wchar_t)wc)) 2249 if (IsDigit((wchar_t)wc))
2253 » » { 2250 {
2254 » » » sPart += wc; 2251 sPart += wc;
2255 » » } 2252 }
2256 » » else 2253 else
2257 » » { 2254 {
2258 » » » if (sPart.GetLength() > 0) 2255 if (sPart.GetLength() > 0)
2259 » » » { 2256 {
2260 » » » » nums.SetElement(nIndex,CJS_Value(isolate,sPart.c _str())); 2257 nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
2261 » » » » sPart = L""; 2258 sPart = L"";
2262 » » » » nIndex ++; 2259 nIndex ++;
2263 » » » } 2260 }
2264 » » } 2261 }
2265 » } 2262 }
2266 2263
2267 » if (sPart.GetLength() > 0) 2264 if (sPart.GetLength() > 0)
2268 » { 2265 {
2269 » » nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str())); 2266 nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
2270 » } 2267 }
2271 2268
2272 » if (nums.GetLength() > 0) 2269 if (nums.GetLength() > 0)
2273 » » vRet = nums; 2270 vRet = nums;
2274 » else 2271 else
2275 » » vRet.SetNull(); 2272 vRet.SetNull();
2276 2273
2277 » return TRUE; 2274 return TRUE;
2278 } 2275 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | fpdfsdk/src/javascript/global.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698