OLD | NEW |
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 "PublicMethods.h" | 7 #include "PublicMethods.h" |
8 | 8 |
9 #include "Field.h" | 9 #include "Field.h" |
10 #include "JS_Context.h" | 10 #include "JS_Context.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (bKXJS) | 96 if (bKXJS) |
97 return FALSE; | 97 return FALSE; |
98 | 98 |
99 p++; | 99 p++; |
100 c = *p; | 100 c = *p; |
101 if (c == '+' || c == '-') { | 101 if (c == '+' || c == '-') { |
102 bKXJS = TRUE; | 102 bKXJS = TRUE; |
103 } else { | 103 } else { |
104 return FALSE; | 104 return FALSE; |
105 } | 105 } |
106 } else if (!IsDigit(c)) { | 106 } else if (!FXSYS_iswdigit(c)) { |
107 return FALSE; | 107 return FALSE; |
108 } | 108 } |
109 p++; | 109 p++; |
110 } | 110 } |
111 | 111 |
112 return TRUE; | 112 return TRUE; |
113 } | 113 } |
114 | 114 |
115 FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) { | |
116 return (ch >= L'0' && ch <= L'9'); | |
117 } | |
118 | |
119 FX_BOOL CJS_PublicMethods::IsDigit(char ch) { | |
120 return std::isdigit(ch); | |
121 } | |
122 | |
123 FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) { | |
124 return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z')); | |
125 } | |
126 | |
127 FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch) { | |
128 return (IsDigit(ch) || IsAlphabetic(ch)); | |
129 } | |
130 | |
131 FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change, wchar_t c_Mask) { | 115 FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change, wchar_t c_Mask) { |
132 switch (c_Mask) { | 116 switch (c_Mask) { |
133 case L'9': | 117 case L'9': |
134 return IsDigit(c_Change); | 118 return FXSYS_iswdigit(c_Change); |
135 case L'A': | 119 case L'A': |
136 return IsAlphabetic(c_Change); | 120 return FXSYS_iswalpha(c_Change); |
137 case L'O': | 121 case L'O': |
138 return IsAlphaNumeric(c_Change); | 122 return FXSYS_iswalnum(c_Change); |
139 case L'X': | 123 case L'X': |
140 return TRUE; | 124 return TRUE; |
141 default: | 125 default: |
142 return (c_Change == c_Mask); | 126 return (c_Change == c_Mask); |
143 } | 127 } |
144 } | 128 } |
145 | 129 |
146 FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch) { | 130 FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch) { |
147 return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X'; | 131 return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X'; |
148 } | 132 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 231 } |
248 | 232 |
249 double dRet = 0; | 233 double dRet = 0; |
250 p = pStart; | 234 p = pStart; |
251 bAllDigits = TRUE; | 235 bAllDigits = TRUE; |
252 CFX_WideString swDigits; | 236 CFX_WideString swDigits; |
253 | 237 |
254 while (p <= pEnd) { | 238 while (p <= pEnd) { |
255 c = *p; | 239 c = *p; |
256 | 240 |
257 if (IsDigit(c)) { | 241 if (FXSYS_iswdigit(c)) { |
258 swDigits += c; | 242 swDigits += c; |
259 bDigitExist = TRUE; | 243 bDigitExist = TRUE; |
260 } else { | 244 } else { |
261 switch (c) { | 245 switch (c) { |
262 case L' ': | 246 case L' ': |
263 bAllDigits = FALSE; | 247 bAllDigits = FALSE; |
264 break; | 248 break; |
265 case L'.': | 249 case L'.': |
266 case L',': | 250 case L',': |
267 if (!bDot) { | 251 if (!bDot) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 int nStart, | 373 int nStart, |
390 int& nSkip, | 374 int& nSkip, |
391 int nMaxStep) { | 375 int nMaxStep) { |
392 int nRet = 0; | 376 int nRet = 0; |
393 nSkip = 0; | 377 nSkip = 0; |
394 for (int i = nStart, sz = string.GetLength(); i < sz; i++) { | 378 for (int i = nStart, sz = string.GetLength(); i < sz; i++) { |
395 if (i - nStart > 10) | 379 if (i - nStart > 10) |
396 break; | 380 break; |
397 | 381 |
398 FX_WCHAR c = string.GetAt(i); | 382 FX_WCHAR c = string.GetAt(i); |
399 if (IsDigit((wchar_t)c)) { | 383 if (!FXSYS_iswdigit(c)) |
400 nRet = nRet * 10 + FXSYS_toDecimalDigitWide(c); | 384 break; |
401 nSkip = i - nStart + 1; | 385 |
402 if (nSkip >= nMaxStep) | 386 nRet = nRet * 10 + FXSYS_toDecimalDigitWide(c); |
403 break; | 387 nSkip = i - nStart + 1; |
404 } else | 388 if (nSkip >= nMaxStep) |
405 break; | 389 break; |
406 } | 390 } |
407 | 391 |
408 return nRet; | 392 return nRet; |
409 } | 393 } |
410 | 394 |
411 CFX_WideString CJS_PublicMethods::ParseStringString( | 395 CFX_WideString CJS_PublicMethods::ParseStringString( |
412 const CFX_WideString& string, | 396 const CFX_WideString& string, |
413 int nStart, | 397 int nStart, |
414 int& nSkip) { | 398 int& nSkip) { |
415 CFX_WideString swRet; | 399 CFX_WideString swRet; |
416 nSkip = 0; | 400 nSkip = 0; |
417 for (int i = nStart, sz = string.GetLength(); i < sz; i++) { | 401 for (int i = nStart, sz = string.GetLength(); i < sz; i++) { |
418 FX_WCHAR c = string.GetAt(i); | 402 FX_WCHAR c = string.GetAt(i); |
419 if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z')) { | 403 if (!FXSYS_iswdigit(c)) |
420 swRet += c; | |
421 nSkip = i - nStart + 1; | |
422 } else | |
423 break; | 404 break; |
| 405 |
| 406 swRet += c; |
| 407 nSkip = i - nStart + 1; |
424 } | 408 } |
425 | 409 |
426 return swRet; | 410 return swRet; |
427 } | 411 } |
428 | 412 |
429 double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value, | 413 double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value, |
430 FX_BOOL& bWrongFormat) { | 414 bool* bWrongFormat) { |
431 double dt = JS_GetDateTime(); | 415 double dt = JS_GetDateTime(); |
432 | 416 |
433 int nYear = JS_GetYearFromTime(dt); | 417 int nYear = JS_GetYearFromTime(dt); |
434 int nMonth = JS_GetMonthFromTime(dt) + 1; | 418 int nMonth = JS_GetMonthFromTime(dt) + 1; |
435 int nDay = JS_GetDayFromTime(dt); | 419 int nDay = JS_GetDayFromTime(dt); |
436 int nHour = JS_GetHourFromTime(dt); | 420 int nHour = JS_GetHourFromTime(dt); |
437 int nMin = JS_GetMinFromTime(dt); | 421 int nMin = JS_GetMinFromTime(dt); |
438 int nSec = JS_GetSecFromTime(dt); | 422 int nSec = JS_GetSecFromTime(dt); |
439 | 423 |
440 int number[3]; | 424 int number[3]; |
441 | 425 |
442 int nSkip = 0; | 426 int nSkip = 0; |
443 int nLen = value.GetLength(); | 427 int nLen = value.GetLength(); |
444 int nIndex = 0; | 428 int nIndex = 0; |
445 int i = 0; | 429 int i = 0; |
446 while (i < nLen) { | 430 while (i < nLen) { |
447 if (nIndex > 2) | 431 if (nIndex > 2) |
448 break; | 432 break; |
449 | 433 |
450 FX_WCHAR c = value.GetAt(i); | 434 FX_WCHAR c = value.GetAt(i); |
451 if (IsDigit((wchar_t)c)) { | 435 if (FXSYS_iswdigit(c)) { |
452 number[nIndex++] = ParseStringInteger(value, i, nSkip, 4); | 436 number[nIndex++] = ParseStringInteger(value, i, nSkip, 4); |
453 i += nSkip; | 437 i += nSkip; |
454 } else { | 438 } else { |
455 i++; | 439 i++; |
456 } | 440 } |
457 } | 441 } |
458 | 442 |
459 if (nIndex == 2) { | 443 if (nIndex == 2) { |
460 // case2: month/day | 444 // case2: month/day |
461 // case3: day/month | 445 // case3: day/month |
462 if ((number[0] >= 1 && number[0] <= 12) && | 446 if ((number[0] >= 1 && number[0] <= 12) && |
463 (number[1] >= 1 && number[1] <= 31)) { | 447 (number[1] >= 1 && number[1] <= 31)) { |
464 nMonth = number[0]; | 448 nMonth = number[0]; |
465 nDay = number[1]; | 449 nDay = number[1]; |
466 } else if ((number[0] >= 1 && number[0] <= 31) && | 450 } else if ((number[0] >= 1 && number[0] <= 31) && |
467 (number[1] >= 1 && number[1] <= 12)) { | 451 (number[1] >= 1 && number[1] <= 12)) { |
468 nDay = number[0]; | 452 nDay = number[0]; |
469 nMonth = number[1]; | 453 nMonth = number[1]; |
470 } | 454 } |
471 | 455 |
472 bWrongFormat = FALSE; | 456 if (bWrongFormat) |
| 457 *bWrongFormat = false; |
473 } else if (nIndex == 3) { | 458 } else if (nIndex == 3) { |
474 // case1: year/month/day | 459 // case1: year/month/day |
475 // case2: month/day/year | 460 // case2: month/day/year |
476 // case3: day/month/year | 461 // case3: day/month/year |
477 | 462 |
478 if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && | 463 if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && |
479 (number[2] >= 1 && number[2] <= 31)) { | 464 (number[2] >= 1 && number[2] <= 31)) { |
480 nYear = number[0]; | 465 nYear = number[0]; |
481 nMonth = number[1]; | 466 nMonth = number[1]; |
482 nDay = number[2]; | 467 nDay = number[2]; |
483 } else if ((number[0] >= 1 && number[0] <= 12) && | 468 } else if ((number[0] >= 1 && number[0] <= 12) && |
484 (number[1] >= 1 && number[1] <= 31) && number[2] > 31) { | 469 (number[1] >= 1 && number[1] <= 31) && number[2] > 31) { |
485 nMonth = number[0]; | 470 nMonth = number[0]; |
486 nDay = number[1]; | 471 nDay = number[1]; |
487 nYear = number[2]; | 472 nYear = number[2]; |
488 } else if ((number[0] >= 1 && number[0] <= 31) && | 473 } else if ((number[0] >= 1 && number[0] <= 31) && |
489 (number[1] >= 1 && number[1] <= 12) && number[2] > 31) { | 474 (number[1] >= 1 && number[1] <= 12) && number[2] > 31) { |
490 nDay = number[0]; | 475 nDay = number[0]; |
491 nMonth = number[1]; | 476 nMonth = number[1]; |
492 nYear = number[2]; | 477 nYear = number[2]; |
493 } | 478 } |
494 | 479 |
495 bWrongFormat = FALSE; | 480 if (bWrongFormat) |
| 481 *bWrongFormat = false; |
496 } else { | 482 } else { |
497 bWrongFormat = TRUE; | 483 if (bWrongFormat) |
| 484 *bWrongFormat = true; |
498 return dt; | 485 return dt; |
499 } | 486 } |
500 | 487 |
501 CFX_WideString swTemp; | 488 CFX_WideString swTemp; |
502 swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec); | 489 swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec); |
503 return JS_DateParse(swTemp.c_str()); | 490 return JS_DateParse(swTemp.c_str()); |
504 } | 491 } |
505 | 492 |
506 double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, | 493 double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, |
507 const CFX_WideString& format, | 494 const CFX_WideString& format, |
508 FX_BOOL& bWrongFormat) { | 495 bool* bWrongFormat) { |
509 double dt = JS_GetDateTime(); | 496 double dt = JS_GetDateTime(); |
510 | 497 |
511 if (format.IsEmpty() || value.IsEmpty()) | 498 if (format.IsEmpty() || value.IsEmpty()) |
512 return dt; | 499 return dt; |
513 | 500 |
514 int nYear = JS_GetYearFromTime(dt); | 501 int nYear = JS_GetYearFromTime(dt); |
515 int nMonth = JS_GetMonthFromTime(dt) + 1; | 502 int nMonth = JS_GetMonthFromTime(dt) + 1; |
516 int nDay = JS_GetDayFromTime(dt); | 503 int nDay = JS_GetDayFromTime(dt); |
517 int nHour = JS_GetHourFromTime(dt); | 504 int nHour = JS_GetHourFromTime(dt); |
518 int nMin = JS_GetMinFromTime(dt); | 505 int nMin = JS_GetMinFromTime(dt); |
519 int nSec = JS_GetSecFromTime(dt); | 506 int nSec = JS_GetSecFromTime(dt); |
520 | 507 |
521 int nYearSub = 99; // nYear - 2000; | 508 int nYearSub = 99; // nYear - 2000; |
522 | 509 |
523 FX_BOOL bPm = FALSE; | 510 FX_BOOL bPm = FALSE; |
524 FX_BOOL bExit = FALSE; | 511 FX_BOOL bExit = FALSE; |
525 bWrongFormat = FALSE; | 512 bool bBadFormat = false; |
526 | 513 |
527 int i = 0; | 514 int i = 0; |
528 int j = 0; | 515 int j = 0; |
529 | 516 |
530 while (i < format.GetLength()) { | 517 while (i < format.GetLength()) { |
531 if (bExit) | 518 if (bExit) |
532 break; | 519 break; |
533 | 520 |
534 FX_WCHAR c = format.GetAt(i); | 521 FX_WCHAR c = format.GetAt(i); |
535 switch (c) { | 522 switch (c) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 j += nSkip; | 687 j += nSkip; |
701 } | 688 } |
702 } break; | 689 } break; |
703 default: | 690 default: |
704 i += 4; | 691 i += 4; |
705 j += 4; | 692 j += 4; |
706 break; | 693 break; |
707 } | 694 } |
708 } else { | 695 } else { |
709 if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) { | 696 if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) { |
710 bWrongFormat = TRUE; | 697 bBadFormat = true; |
711 bExit = TRUE; | 698 bExit = TRUE; |
712 } | 699 } |
713 i++; | 700 i++; |
714 j++; | 701 j++; |
715 } | 702 } |
716 | 703 |
717 if (oldj == j) { | 704 if (oldj == j) { |
718 bWrongFormat = TRUE; | 705 bBadFormat = true; |
719 bExit = TRUE; | 706 bExit = TRUE; |
720 } | 707 } |
721 } | 708 } |
722 | 709 |
723 break; | 710 break; |
724 default: | 711 default: |
725 if (value.GetLength() <= j) { | 712 if (value.GetLength() <= j) { |
726 bExit = TRUE; | 713 bExit = TRUE; |
727 } else if (format.GetAt(i) != value.GetAt(j)) { | 714 } else if (format.GetAt(i) != value.GetAt(j)) { |
728 bWrongFormat = TRUE; | 715 bBadFormat = true; |
729 bExit = TRUE; | 716 bExit = TRUE; |
730 } | 717 } |
731 | 718 |
732 i++; | 719 i++; |
733 j++; | 720 j++; |
734 break; | 721 break; |
735 } | 722 } |
736 } | 723 } |
737 | 724 |
738 if (bPm) | 725 if (bPm) |
739 nHour += 12; | 726 nHour += 12; |
740 | 727 |
741 if (nYear >= 0 && nYear <= nYearSub) | 728 if (nYear >= 0 && nYear <= nYearSub) |
742 nYear += 2000; | 729 nYear += 2000; |
743 | 730 |
744 if (nMonth < 1 || nMonth > 12) | 731 if (nMonth < 1 || nMonth > 12) |
745 bWrongFormat = TRUE; | 732 bBadFormat = true; |
746 | 733 |
747 if (nDay < 1 || nDay > 31) | 734 if (nDay < 1 || nDay > 31) |
748 bWrongFormat = TRUE; | 735 bBadFormat = true; |
749 | 736 |
750 if (nHour < 0 || nHour > 24) | 737 if (nHour < 0 || nHour > 24) |
751 bWrongFormat = TRUE; | 738 bBadFormat = true; |
752 | 739 |
753 if (nMin < 0 || nMin > 60) | 740 if (nMin < 0 || nMin > 60) |
754 bWrongFormat = TRUE; | 741 bBadFormat = true; |
755 | 742 |
756 if (nSec < 0 || nSec > 60) | 743 if (nSec < 0 || nSec > 60) |
757 bWrongFormat = TRUE; | 744 bBadFormat = true; |
758 | 745 |
759 double dRet = 0; | 746 double dRet = 0; |
760 | 747 |
761 if (bWrongFormat) { | 748 if (bBadFormat) { |
762 dRet = ParseNormalDate(value, bWrongFormat); | 749 dRet = ParseNormalDate(value, &bBadFormat); |
763 } else { | 750 } else { |
764 dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), | 751 dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), |
765 JS_MakeTime(nHour, nMin, nSec, 0)); | 752 JS_MakeTime(nHour, nMin, nSec, 0)); |
766 | 753 |
767 if (JS_PortIsNan(dRet)) { | 754 if (JS_PortIsNan(dRet)) { |
768 dRet = JS_DateParse(value.c_str()); | 755 dRet = JS_DateParse(value.c_str()); |
769 } | 756 } |
770 } | 757 } |
771 | 758 |
772 if (JS_PortIsNan(dRet)) { | 759 if (JS_PortIsNan(dRet)) { |
773 dRet = ParseNormalDate(value, bWrongFormat); | 760 dRet = ParseNormalDate(value, &bBadFormat); |
774 } | 761 } |
775 | 762 |
| 763 if (bWrongFormat) |
| 764 *bWrongFormat = bBadFormat; |
776 return dRet; | 765 return dRet; |
777 } | 766 } |
778 | 767 |
779 CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, | 768 CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, |
780 const CFX_WideString& format) { | 769 const CFX_WideString& format) { |
781 CFX_WideString sRet = L"", sPart = L""; | 770 CFX_WideString sRet = L"", sPart = L""; |
782 | 771 |
783 int nYear = JS_GetYearFromTime(dDate); | 772 int nYear = JS_GetYearFromTime(dDate); |
784 int nMonth = JS_GetMonthFromTime(dDate) + 1; | 773 int nMonth = JS_GetMonthFromTime(dDate) + 1; |
785 int nDay = JS_GetDayFromTime(dDate); | 774 int nDay = JS_GetDayFromTime(dDate); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 } | 1157 } |
1169 bHasSep = TRUE; | 1158 bHasSep = TRUE; |
1170 continue; | 1159 continue; |
1171 } | 1160 } |
1172 if (*it == L'-') { | 1161 if (*it == L'-') { |
1173 if (bHasSign) { | 1162 if (bHasSign) { |
1174 FX_BOOL& bRc = pEvent->Rc(); | 1163 FX_BOOL& bRc = pEvent->Rc(); |
1175 bRc = FALSE; | 1164 bRc = FALSE; |
1176 return TRUE; | 1165 return TRUE; |
1177 } | 1166 } |
1178 if (it != w_strChange2.begin()) // sign's position is not correct | 1167 // sign's position is not correct |
1179 { | 1168 if (it != w_strChange2.begin()) { |
1180 FX_BOOL& bRc = pEvent->Rc(); | 1169 FX_BOOL& bRc = pEvent->Rc(); |
1181 bRc = FALSE; | 1170 bRc = FALSE; |
1182 return TRUE; | 1171 return TRUE; |
1183 } | 1172 } |
1184 if (pEvent->SelStart() != 0) { | 1173 if (pEvent->SelStart() != 0) { |
1185 FX_BOOL& bRc = pEvent->Rc(); | 1174 FX_BOOL& bRc = pEvent->Rc(); |
1186 bRc = FALSE; | 1175 bRc = FALSE; |
1187 return TRUE; | 1176 return TRUE; |
1188 } | 1177 } |
1189 bHasSign = TRUE; | 1178 bHasSign = TRUE; |
1190 continue; | 1179 continue; |
1191 } | 1180 } |
1192 | 1181 |
1193 if (!IsDigit(*it)) { | 1182 if (!FXSYS_iswdigit(*it)) { |
1194 FX_BOOL& bRc = pEvent->Rc(); | 1183 FX_BOOL& bRc = pEvent->Rc(); |
1195 bRc = FALSE; | 1184 bRc = FALSE; |
1196 return TRUE; | 1185 return TRUE; |
1197 } | 1186 } |
1198 } | 1187 } |
1199 | 1188 |
1200 std::wstring w_prefix = w_strValue2.substr(0, pEvent->SelStart()); | 1189 std::wstring w_prefix = w_strValue2.substr(0, pEvent->SelStart()); |
1201 std::wstring w_postfix; | 1190 std::wstring w_postfix; |
1202 if (pEvent->SelEnd() < (int)w_strValue2.length()) | 1191 if (pEvent->SelEnd() < (int)w_strValue2.length()) |
1203 w_postfix = w_strValue2.substr(pEvent->SelEnd()); | 1192 w_postfix = w_strValue2.substr(pEvent->SelEnd()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 | 1224 |
1236 int iSepStyle = params[1].ToInt(); | 1225 int iSepStyle = params[1].ToInt(); |
1237 if (iSepStyle < 0 || iSepStyle > 3) | 1226 if (iSepStyle < 0 || iSepStyle > 3) |
1238 iSepStyle = 0; | 1227 iSepStyle = 0; |
1239 | 1228 |
1240 ////////////////////////////////////////////////////// | 1229 ////////////////////////////////////////////////////// |
1241 // for processing decimal places | 1230 // for processing decimal places |
1242 double dValue = atof(strValue); | 1231 double dValue = atof(strValue); |
1243 dValue *= 100; | 1232 dValue *= 100; |
1244 if (iDec > 0) | 1233 if (iDec > 0) |
1245 dValue += DOUBLE_CORRECT; //УÕý | 1234 dValue += DOUBLE_CORRECT; |
1246 | 1235 |
1247 int iDec2; | 1236 int iDec2; |
1248 int iNegative = 0; | 1237 int iNegative = 0; |
1249 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); | 1238 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
1250 if (strValue.IsEmpty()) { | 1239 if (strValue.IsEmpty()) { |
1251 dValue = 0; | 1240 dValue = 0; |
1252 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); | 1241 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
1253 } | 1242 } |
1254 | 1243 |
1255 if (iDec2 < 0) { | 1244 if (iDec2 < 0) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 } | 1312 } |
1324 if (!pEvent->m_pValue) | 1313 if (!pEvent->m_pValue) |
1325 return FALSE; | 1314 return FALSE; |
1326 | 1315 |
1327 CFX_WideString& val = pEvent->Value(); | 1316 CFX_WideString& val = pEvent->Value(); |
1328 CFX_WideString strValue = val; | 1317 CFX_WideString strValue = val; |
1329 if (strValue.IsEmpty()) | 1318 if (strValue.IsEmpty()) |
1330 return TRUE; | 1319 return TRUE; |
1331 | 1320 |
1332 CFX_WideString sFormat = params[0].ToCFXWideString(); | 1321 CFX_WideString sFormat = params[0].ToCFXWideString(); |
1333 FX_BOOL bWrongFormat = FALSE; | |
1334 double dDate = 0.0f; | 1322 double dDate = 0.0f; |
1335 | 1323 |
1336 if (strValue.Find(L"GMT") != -1) { | 1324 if (strValue.Find(L"GMT") != -1) { |
1337 // for GMT format time | 1325 // for GMT format time |
1338 // such as "Tue Aug 11 14:24:16 GMT+08002009" | 1326 // such as "Tue Aug 11 14:24:16 GMT+08002009" |
1339 dDate = MakeInterDate(strValue); | 1327 dDate = MakeInterDate(strValue); |
1340 } else { | 1328 } else { |
1341 dDate = MakeRegularDate(strValue, sFormat, bWrongFormat); | 1329 dDate = MakeRegularDate(strValue, sFormat, nullptr); |
1342 } | 1330 } |
1343 | 1331 |
1344 if (JS_PortIsNan(dDate)) { | 1332 if (JS_PortIsNan(dDate)) { |
1345 CFX_WideString swMsg; | 1333 CFX_WideString swMsg; |
1346 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1334 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
1347 sFormat.c_str()); | 1335 sFormat.c_str()); |
1348 Alert(pContext, swMsg.c_str()); | 1336 Alert(pContext, swMsg.c_str()); |
1349 return FALSE; | 1337 return FALSE; |
1350 } | 1338 } |
1351 | 1339 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 } | 1426 } |
1439 | 1427 |
1440 if (pEvent->WillCommit()) { | 1428 if (pEvent->WillCommit()) { |
1441 if (!pEvent->m_pValue) | 1429 if (!pEvent->m_pValue) |
1442 return FALSE; | 1430 return FALSE; |
1443 CFX_WideString strValue = pEvent->Value(); | 1431 CFX_WideString strValue = pEvent->Value(); |
1444 if (strValue.IsEmpty()) | 1432 if (strValue.IsEmpty()) |
1445 return TRUE; | 1433 return TRUE; |
1446 | 1434 |
1447 CFX_WideString sFormat = params[0].ToCFXWideString(); | 1435 CFX_WideString sFormat = params[0].ToCFXWideString(); |
1448 FX_BOOL bWrongFormat = FALSE; | 1436 bool bWrongFormat = FALSE; |
1449 double dRet = MakeRegularDate(strValue, sFormat, bWrongFormat); | 1437 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); |
1450 if (bWrongFormat || JS_PortIsNan(dRet)) { | 1438 if (bWrongFormat || JS_PortIsNan(dRet)) { |
1451 CFX_WideString swMsg; | 1439 CFX_WideString swMsg; |
1452 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1440 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
1453 sFormat.c_str()); | 1441 sFormat.c_str()); |
1454 Alert(pContext, swMsg.c_str()); | 1442 Alert(pContext, swMsg.c_str()); |
1455 pEvent->Rc() = FALSE; | 1443 pEvent->Rc() = FALSE; |
1456 return TRUE; | 1444 return TRUE; |
1457 } | 1445 } |
1458 } | 1446 } |
1459 return TRUE; | 1447 return TRUE; |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 ASSERT(pContext); | 1822 ASSERT(pContext); |
1835 | 1823 |
1836 if (params.size() != 2) { | 1824 if (params.size() != 2) { |
1837 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1825 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1838 return FALSE; | 1826 return FALSE; |
1839 } | 1827 } |
1840 | 1828 |
1841 CFX_WideString sValue = params[0].ToCFXWideString(); | 1829 CFX_WideString sValue = params[0].ToCFXWideString(); |
1842 CFX_WideString sFormat = params[1].ToCFXWideString(); | 1830 CFX_WideString sFormat = params[1].ToCFXWideString(); |
1843 | 1831 |
1844 FX_BOOL bWrongFormat = FALSE; | 1832 double dDate = MakeRegularDate(sValue, sFormat, nullptr); |
1845 double dDate = MakeRegularDate(sValue, sFormat, bWrongFormat); | |
1846 | 1833 |
1847 if (JS_PortIsNan(dDate)) { | 1834 if (JS_PortIsNan(dDate)) { |
1848 CFX_WideString swMsg; | 1835 CFX_WideString swMsg; |
1849 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1836 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
1850 sFormat.c_str()); | 1837 sFormat.c_str()); |
1851 Alert((CJS_Context*)cc, swMsg.c_str()); | 1838 Alert((CJS_Context*)cc, swMsg.c_str()); |
1852 return FALSE; | 1839 return FALSE; |
1853 } | 1840 } |
1854 | 1841 |
1855 vRet = dDate; | 1842 vRet = dDate; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 } | 1924 } |
1938 case FIELDTYPE_CHECKBOX: | 1925 case FIELDTYPE_CHECKBOX: |
1939 case FIELDTYPE_RADIOBUTTON: { | 1926 case FIELDTYPE_RADIOBUTTON: { |
1940 dTemp = 0.0; | 1927 dTemp = 0.0; |
1941 for (int c = 0, csz = pFormField->CountControls(); c < csz; c++) { | 1928 for (int c = 0, csz = pFormField->CountControls(); c < csz; c++) { |
1942 if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c)) { | 1929 if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c)) { |
1943 if (pFormCtrl->IsChecked()) { | 1930 if (pFormCtrl->IsChecked()) { |
1944 dTemp += | 1931 dTemp += |
1945 ParseStringToNumber(pFormCtrl->GetExportValue().c_str()); | 1932 ParseStringToNumber(pFormCtrl->GetExportValue().c_str()); |
1946 break; | 1933 break; |
1947 } else | 1934 } |
1948 continue; | |
1949 } | 1935 } |
1950 } | 1936 } |
1951 break; | 1937 break; |
1952 } | 1938 } |
1953 case FIELDTYPE_LISTBOX: { | 1939 case FIELDTYPE_LISTBOX: { |
1954 dTemp = 0.0; | |
1955 if (pFormField->CountSelectedItems() > 1) | 1940 if (pFormField->CountSelectedItems() > 1) |
1956 break; | 1941 break; |
1957 else { | 1942 |
1958 dTemp = ParseStringToNumber(pFormField->GetValue().c_str()); | 1943 dTemp = ParseStringToNumber(pFormField->GetValue().c_str()); |
1959 break; | 1944 break; |
1960 } | |
1961 } | 1945 } |
1962 default: | 1946 default: |
1963 break; | 1947 break; |
1964 } | 1948 } |
1965 | 1949 |
1966 if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || | 1950 if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || |
1967 wcscmp(sFunction.c_str(), L"MAX") == 0)) | 1951 wcscmp(sFunction.c_str(), L"MAX") == 0)) |
1968 dValue = dTemp; | 1952 dValue = dTemp; |
1969 | 1953 |
1970 dValue = AF_Simple(sFunction.c_str(), dValue, dTemp); | 1954 dValue = AF_Simple(sFunction.c_str(), dValue, dTemp); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 | 2034 |
2051 CFX_WideString str = params[0].ToCFXWideString(); | 2035 CFX_WideString str = params[0].ToCFXWideString(); |
2052 CFX_WideString sPart; | 2036 CFX_WideString sPart; |
2053 | 2037 |
2054 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 2038 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
2055 str = L"0" + str; | 2039 str = L"0" + str; |
2056 | 2040 |
2057 int nIndex = 0; | 2041 int nIndex = 0; |
2058 for (int i = 0, sz = str.GetLength(); i < sz; i++) { | 2042 for (int i = 0, sz = str.GetLength(); i < sz; i++) { |
2059 FX_WCHAR wc = str.GetAt(i); | 2043 FX_WCHAR wc = str.GetAt(i); |
2060 if (IsDigit((wchar_t)wc)) { | 2044 if (FXSYS_iswdigit(wc)) { |
2061 sPart += wc; | 2045 sPart += wc; |
2062 } else { | 2046 } else { |
2063 if (sPart.GetLength() > 0) { | 2047 if (sPart.GetLength() > 0) { |
2064 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 2048 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
2065 sPart = L""; | 2049 sPart = L""; |
2066 nIndex++; | 2050 nIndex++; |
2067 } | 2051 } |
2068 } | 2052 } |
2069 } | 2053 } |
2070 | 2054 |
2071 if (sPart.GetLength() > 0) { | 2055 if (sPart.GetLength() > 0) { |
2072 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 2056 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
2073 } | 2057 } |
2074 | 2058 |
2075 if (nums.GetLength() > 0) | 2059 if (nums.GetLength() > 0) |
2076 vRet = nums; | 2060 vRet = nums; |
2077 else | 2061 else |
2078 vRet.SetNull(); | 2062 vRet.SetNull(); |
2079 | 2063 |
2080 return TRUE; | 2064 return TRUE; |
2081 } | 2065 } |
OLD | NEW |