| 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 "../../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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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"Oc
t", 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* fullmonths[] = | 70 static const FX_WCHAR* fullmonths[] = |
| 71 { | 71 { |
| 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" | 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 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 bool bDot = false; |
| 83 FX_BOOL bKXJS = FALSE; | 83 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) | 100 if (bKXJS) |
| 101 return FALSE; | 101 return false; |
| 102 | 102 |
| 103 p++; | 103 p++; |
| 104 c = *p; | 104 c = *p; |
| 105 if (c == '+' || c == '-') | 105 if (c == '+' || c == '-') |
| 106 { | 106 { |
| 107 bKXJS = TRUE; | 107 bKXJS = true; |
| 108 } | 108 } |
| 109 else | 109 else |
| 110 { | 110 { |
| 111 return FALSE; | 111 return false; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 else if (!IsDigit(c)) | 114 else if (!IsDigit(c)) |
| 115 { | 115 { |
| 116 return FALSE; | 116 return false; |
| 117 } | 117 } |
| 118 p++; | 118 p++; |
| 119 } | 119 } |
| 120 | 120 |
| 121 return TRUE; | 121 return true; |
| 122 } | 122 } |
| 123 | 123 |
| 124 FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) | 124 bool CJS_PublicMethods::IsDigit(wchar_t ch) |
| 125 { | 125 { |
| 126 return (ch >= L'0' && ch <= L'9'); | 126 return (ch >= L'0' && ch <= L'9'); |
| 127 } | 127 } |
| 128 | 128 |
| 129 FX_BOOL CJS_PublicMethods::IsDigit(char ch) | 129 bool CJS_PublicMethods::IsDigit(char ch) |
| 130 { | 130 { |
| 131 return (ch >= '0' && ch <= '9'); | 131 return (ch >= '0' && ch <= '9'); |
| 132 } | 132 } |
| 133 | 133 |
| 134 FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) | 134 bool CJS_PublicMethods::IsAlphabetic(wchar_t ch) |
| 135 { | 135 { |
| 136 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')); |
| 137 } | 137 } |
| 138 | 138 |
| 139 FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch) | 139 bool CJS_PublicMethods::IsAlphaNumeric(wchar_t ch) |
| 140 { | 140 { |
| 141 return (IsDigit(ch) || IsAlphabetic(ch)); | 141 return (IsDigit(ch) || IsAlphabetic(ch)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask) | 144 bool CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask) |
| 145 { | 145 { |
| 146 switch (c_Mask) | 146 switch (c_Mask) |
| 147 { | 147 { |
| 148 case L'9': | 148 case L'9': |
| 149 return IsDigit(c_Change); | 149 return IsDigit(c_Change); |
| 150 case L'A': | 150 case L'A': |
| 151 return IsAlphabetic(c_Change); | 151 return IsAlphabetic(c_Change); |
| 152 case L'O': | 152 case L'O': |
| 153 return IsAlphaNumeric(c_Change); | 153 return IsAlphaNumeric(c_Change); |
| 154 case L'X': | 154 case L'X': |
| 155 return TRUE; | 155 return true; |
| 156 default: | 156 default: |
| 157 return (c_Change == c_Mask); | 157 return (c_Change == c_Mask); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch) | 161 bool CJS_PublicMethods::isReservedMaskChar(wchar_t ch) |
| 162 { | 162 { |
| 163 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'; |
| 164 } | 164 } |
| 165 | 165 |
| 166 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) |
| 167 { | 167 { |
| 168 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) |
| 169 { | 169 { |
| 170 return dValue1 + dValue2; | 170 return dValue1 + dValue2; |
| 171 } | 171 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, bool& bAllDigits
, bool& bDot, bool& bSign, 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 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) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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 bool bAllDigits = false; |
| 378 FX_BOOL bDot = FALSE; | 378 bool bDot = false; |
| 379 FX_BOOL bSign = FALSE; | 379 bool bSign = false; |
| 380 FX_BOOL bKXJS = FALSE; | 380 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 bool CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource, double &
dRet, bool & bDot) |
| 386 { | 386 { |
| 387 FX_BOOL bAllDigits = FALSE; | 387 bool bAllDigits = false; |
| 388 FX_BOOL bSign = FALSE; | 388 bool bSign = false; |
| 389 FX_BOOL bKXJS = FALSE; | 389 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()) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, bool& bW
rongFormat) |
| 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 && numbe
r[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) && (number[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 && numbe
r[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 && numbe
r[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, 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 bool bPm = false; |
| 585 FX_BOOL bExit = FALSE; | 585 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) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_WideString sMonth = ParseStringString(va
lue, j, nSkip); | 717 CFX_WideString sMonth = ParseStringString(va
lue, j, nSkip); |
| 718 FX_BOOL bFind = FALSE; | 718 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 (!bFind) | 731 if (!bFind) |
| 732 { | 732 { |
| 733 nMonth = ParseStringInteger(value, j, nS
kip, 3); | 733 nMonth = ParseStringInteger(value, j, nS
kip, 3); |
| 734 i+=3; | 734 i+=3; |
| 735 j += nSkip; | 735 j += nSkip; |
| 736 } | 736 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 750 { | 750 { |
| 751 | 751 |
| 752 | 752 |
| 753 case 'y': | 753 case 'y': |
| 754 nYear = ParseStringInteger(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 bool bFind = false; |
| 761 | 761 |
| 762 CFX_WideString sMonth = ParseStringString(va
lue, j, nSkip); | 762 CFX_WideString sMonth = ParseStringString(va
lue, j, nSkip); |
| 763 sMonth.MakeLower(); | 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 (!bFind) | 780 if (!bFind) |
| 781 { | 781 { |
| 782 nMonth = ParseStringInteger(value, j, nS
kip, 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() || format.GetAt(i) != value.G
etAt(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)); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 bool CJS_PublicMethods::AFNumber_Format(IFXJS_Context* cc, const CJS_Parameters&
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; |
| 1029 ASSERT(pContext != NULL); | 1029 ASSERT(pContext != NULL); |
| 1030 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1030 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1031 ASSERT(pEvent != NULL); | 1031 ASSERT(pEvent != NULL); |
| 1032 | 1032 |
| 1033 if (params.size() != 6) | 1033 if (params.size() != 6) |
| 1034 { | 1034 { |
| 1035 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1035 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1036 return FALSE; | 1036 return false; |
| 1037 } | 1037 } |
| 1038 if(!pEvent->m_pValue) | 1038 if(!pEvent->m_pValue) |
| 1039 return FALSE; | 1039 return false; |
| 1040 CFX_WideString& Value = pEvent->Value(); | 1040 CFX_WideString& Value = pEvent->Value(); |
| 1041 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 1041 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
| 1042 | 1042 |
| 1043 if (strValue.IsEmpty()) return TRUE; | 1043 if (strValue.IsEmpty()) return true; |
| 1044 | 1044 |
| 1045 int iDec = params[0].ToInt(); | 1045 int iDec = params[0].ToInt(); |
| 1046 int iSepStyle = params[1].ToInt(); | 1046 int iSepStyle = params[1].ToInt(); |
| 1047 int iNegStyle = params[2].ToInt(); | 1047 int iNegStyle = params[2].ToInt(); |
| 1048 // params[3] is iCurrStyle, it's not used. | 1048 // params[3] is iCurrStyle, it's not used. |
| 1049 std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); | 1049 std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); |
| 1050 FX_BOOL bCurrencyPrepend = params[5].ToBool(); | 1050 bool bCurrencyPrepend = params[5].ToBool(); |
| 1051 | 1051 |
| 1052 if (iDec < 0) iDec = -iDec; | 1052 if (iDec < 0) iDec = -iDec; |
| 1053 | 1053 |
| 1054 if (iSepStyle < 0 || iSepStyle > 3) | 1054 if (iSepStyle < 0 || iSepStyle > 3) |
| 1055 iSepStyle = 0; | 1055 iSepStyle = 0; |
| 1056 | 1056 |
| 1057 if (iNegStyle < 0 || iNegStyle > 3) | 1057 if (iNegStyle < 0 || iNegStyle > 3) |
| 1058 iNegStyle = 0; | 1058 iNegStyle = 0; |
| 1059 | 1059 |
| 1060 | 1060 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 vProp2.StartGetting(); | 1217 vProp2.StartGetting(); |
| 1218 vProp2<<arColor; | 1218 vProp2<<arColor; |
| 1219 vProp2.StartSetting(); | 1219 vProp2.StartSetting(); |
| 1220 fTarget->textColor(cc,vProp2,sError); | 1220 fTarget->textColor(cc,vProp2,sError); |
| 1221 } | 1221 } |
| 1222 } | 1222 } |
| 1223 } | 1223 } |
| 1224 } | 1224 } |
| 1225 Value = strValue2.c_str(); | 1225 Value = strValue2.c_str(); |
| 1226 #endif | 1226 #endif |
| 1227 return TRUE; | 1227 return true; |
| 1228 } | 1228 } |
| 1229 | 1229 |
| 1230 //function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency,
bCurrencyPrepend) | 1230 //function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency,
bCurrencyPrepend) |
| 1231 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Param
eters& params, CJS_Value& vRet, CFX_WideString& sError) | 1231 bool CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Paramete
rs& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1232 { | 1232 { |
| 1233 CJS_Context* pContext = (CJS_Context *)cc; | 1233 CJS_Context* pContext = (CJS_Context *)cc; |
| 1234 ASSERT(pContext != NULL); | 1234 ASSERT(pContext != NULL); |
| 1235 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1235 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1236 ASSERT(pEvent != NULL); | 1236 ASSERT(pEvent != NULL); |
| 1237 | 1237 |
| 1238 if(params.size() < 2) | 1238 if(params.size() < 2) |
| 1239 return FALSE; | 1239 return false; |
| 1240 int iSepStyle = params[1].ToInt(); | 1240 int iSepStyle = params[1].ToInt(); |
| 1241 | 1241 |
| 1242 if (iSepStyle < 0 || iSepStyle > 3) | 1242 if (iSepStyle < 0 || iSepStyle > 3) |
| 1243 iSepStyle = 0; | 1243 iSepStyle = 0; |
| 1244 if(!pEvent->m_pValue) | 1244 if(!pEvent->m_pValue) |
| 1245 return FALSE; | 1245 return false; |
| 1246 CFX_WideString & val = pEvent->Value(); | 1246 CFX_WideString & val = pEvent->Value(); |
| 1247 CFX_WideString & w_strChange = pEvent->Change(); | 1247 CFX_WideString & w_strChange = pEvent->Change(); |
| 1248 CFX_WideString w_strValue = val; | 1248 CFX_WideString w_strValue = val; |
| 1249 | 1249 |
| 1250 if (pEvent->WillCommit()) | 1250 if (pEvent->WillCommit()) |
| 1251 { | 1251 { |
| 1252 CFX_WideString wstrChange = w_strChange; | 1252 CFX_WideString wstrChange = w_strChange; |
| 1253 CFX_WideString wstrValue = StrLTrim(w_strValue.c_str()); | 1253 CFX_WideString wstrValue = StrLTrim(w_strValue.c_str()); |
| 1254 if (wstrValue.IsEmpty()) | 1254 if (wstrValue.IsEmpty()) |
| 1255 return TRUE; | 1255 return true; |
| 1256 | 1256 |
| 1257 CFX_WideString swTemp = wstrValue; | 1257 CFX_WideString swTemp = wstrValue; |
| 1258 swTemp.Replace(L",", L"."); | 1258 swTemp.Replace(L",", L"."); |
| 1259 if (!IsNumber(swTemp.c_str())) | 1259 if (!IsNumber(swTemp.c_str())) |
| 1260 { | 1260 { |
| 1261 pEvent->Rc() = FALSE; | 1261 pEvent->Rc() = false; |
| 1262 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE
); | 1262 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE
); |
| 1263 Alert(pContext, sError.c_str()); | 1263 Alert(pContext, sError.c_str()); |
| 1264 return TRUE; | 1264 return true; |
| 1265 } | 1265 } |
| 1266 return TRUE; // it happens after the last keystroke and before validatin
g, | 1266 return true; // it happens after the last keystroke and before validatin
g, |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 std::wstring w_strValue2 = w_strValue.c_str(); | 1269 std::wstring w_strValue2 = w_strValue.c_str(); |
| 1270 std::wstring w_strChange2 = w_strChange.c_str(); | 1270 std::wstring w_strChange2 = w_strChange.c_str(); |
| 1271 std::wstring w_strSelected; | 1271 std::wstring w_strSelected; |
| 1272 if(-1 != pEvent->SelStart()) | 1272 if(-1 != pEvent->SelStart()) |
| 1273 w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd()
- pEvent->SelStart())); | 1273 w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd()
- pEvent->SelStart())); |
| 1274 FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-')
== -1); | 1274 bool bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') ==
-1); |
| 1275 if (bHasSign) | 1275 if (bHasSign) |
| 1276 { | 1276 { |
| 1277 //can't insert "change" in front to sign postion. | 1277 //can't insert "change" in front to sign postion. |
| 1278 if (pEvent->SelStart() == 0) | 1278 if (pEvent->SelStart() == 0) |
| 1279 { | 1279 { |
| 1280 FX_BOOL &bRc = pEvent->Rc(); | 1280 bool &bRc = pEvent->Rc(); |
| 1281 bRc = FALSE; | 1281 bRc = false; |
| 1282 return TRUE; | 1282 return true; |
| 1283 } | 1283 } |
| 1284 } | 1284 } |
| 1285 | 1285 |
| 1286 char cSep = L'.'; | 1286 char cSep = L'.'; |
| 1287 | 1287 |
| 1288 switch (iSepStyle) | 1288 switch (iSepStyle) |
| 1289 { | 1289 { |
| 1290 case 0: | 1290 case 0: |
| 1291 case 1: | 1291 case 1: |
| 1292 cSep = L'.'; | 1292 cSep = L'.'; |
| 1293 break; | 1293 break; |
| 1294 case 2: | 1294 case 2: |
| 1295 case 3: | 1295 case 3: |
| 1296 cSep = L','; | 1296 cSep = L','; |
| 1297 break; | 1297 break; |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1); | 1300 bool bHasSep = (w_strValue2.find(cSep) != -1); |
| 1301 for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.en
d(); it++) | 1301 for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.en
d(); it++) |
| 1302 { | 1302 { |
| 1303 if (*it == cSep) | 1303 if (*it == cSep) |
| 1304 { | 1304 { |
| 1305 if (bHasSep) | 1305 if (bHasSep) |
| 1306 { | 1306 { |
| 1307 FX_BOOL &bRc = pEvent->Rc(); | 1307 bool &bRc = pEvent->Rc(); |
| 1308 bRc = FALSE; | 1308 bRc = false; |
| 1309 return TRUE; | 1309 return true; |
| 1310 } | 1310 } |
| 1311 bHasSep = TRUE; | 1311 bHasSep = true; |
| 1312 continue; | 1312 continue; |
| 1313 } | 1313 } |
| 1314 if (*it == L'-') | 1314 if (*it == L'-') |
| 1315 { | 1315 { |
| 1316 if (bHasSign) | 1316 if (bHasSign) |
| 1317 { | 1317 { |
| 1318 FX_BOOL &bRc = pEvent->Rc(); | 1318 bool &bRc = pEvent->Rc(); |
| 1319 bRc = FALSE; | 1319 bRc = false; |
| 1320 return TRUE; | 1320 return true; |
| 1321 } | 1321 } |
| 1322 if (it != w_strChange2.begin()) //sign's position is not correct | 1322 if (it != w_strChange2.begin()) //sign's position is not correct |
| 1323 { | 1323 { |
| 1324 FX_BOOL &bRc = pEvent->Rc(); | 1324 bool &bRc = pEvent->Rc(); |
| 1325 bRc = FALSE; | 1325 bRc = false; |
| 1326 return TRUE; | 1326 return true; |
| 1327 } | 1327 } |
| 1328 if (pEvent->SelStart() != 0) | 1328 if (pEvent->SelStart() != 0) |
| 1329 { | 1329 { |
| 1330 FX_BOOL &bRc = pEvent->Rc(); | 1330 bool &bRc = pEvent->Rc(); |
| 1331 bRc = FALSE; | 1331 bRc = false; |
| 1332 return TRUE; | 1332 return true; |
| 1333 } | 1333 } |
| 1334 bHasSign = TRUE; | 1334 bHasSign = true; |
| 1335 continue; | 1335 continue; |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 if (!IsDigit(*it)) | 1338 if (!IsDigit(*it)) |
| 1339 { | 1339 { |
| 1340 FX_BOOL &bRc = pEvent->Rc(); | 1340 bool &bRc = pEvent->Rc(); |
| 1341 bRc = FALSE; | 1341 bRc = false; |
| 1342 return TRUE; | 1342 return true; |
| 1343 } | 1343 } |
| 1344 } | 1344 } |
| 1345 | 1345 |
| 1346 | 1346 |
| 1347 std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart()); | 1347 std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart()); |
| 1348 std::wstring w_postfix; | 1348 std::wstring w_postfix; |
| 1349 if (pEvent->SelEnd()<(int)w_strValue2.length()) | 1349 if (pEvent->SelEnd()<(int)w_strValue2.length()) |
| 1350 w_postfix = w_strValue2.substr(pEvent->SelEnd()); | 1350 w_postfix = w_strValue2.substr(pEvent->SelEnd()); |
| 1351 w_strValue2 = w_prefix + w_strChange2 + w_postfix; | 1351 w_strValue2 = w_prefix + w_strChange2 + w_postfix; |
| 1352 w_strValue = w_strValue2.c_str(); | 1352 w_strValue = w_strValue2.c_str(); |
| 1353 val = w_strValue; | 1353 val = w_strValue; |
| 1354 return TRUE; | 1354 return true; |
| 1355 | 1355 |
| 1356 } | 1356 } |
| 1357 | 1357 |
| 1358 //function AFPercent_Format(nDec, sepStyle) | 1358 //function AFPercent_Format(nDec, sepStyle) |
| 1359 FX_BOOL CJS_PublicMethods::AFPercent_Format(IFXJS_Context* cc, const CJS_Paramet
ers& params, CJS_Value& vRet, CFX_WideString& sError) | 1359 bool CJS_PublicMethods::AFPercent_Format(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1360 { | 1360 { |
| 1361 #if _FX_OS_ != _FX_ANDROID_ | 1361 #if _FX_OS_ != _FX_ANDROID_ |
| 1362 CJS_Context* pContext = (CJS_Context *)cc; | 1362 CJS_Context* pContext = (CJS_Context *)cc; |
| 1363 ASSERT(pContext != NULL); | 1363 ASSERT(pContext != NULL); |
| 1364 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1364 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1365 ASSERT(pEvent != NULL); | 1365 ASSERT(pEvent != NULL); |
| 1366 | 1366 |
| 1367 if (params.size() != 2) | 1367 if (params.size() != 2) |
| 1368 { | 1368 { |
| 1369 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1369 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1370 return FALSE; | 1370 return false; |
| 1371 } | 1371 } |
| 1372 if(!pEvent->m_pValue) | 1372 if(!pEvent->m_pValue) |
| 1373 return FALSE; | 1373 return false; |
| 1374 | 1374 |
| 1375 CFX_WideString& Value = pEvent->Value(); | 1375 CFX_WideString& Value = pEvent->Value(); |
| 1376 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 1376 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
| 1377 if (strValue.IsEmpty()) | 1377 if (strValue.IsEmpty()) |
| 1378 return TRUE; | 1378 return true; |
| 1379 | 1379 |
| 1380 int iDec = params[0].ToInt(); | 1380 int iDec = params[0].ToInt(); |
| 1381 if (iDec < 0) | 1381 if (iDec < 0) |
| 1382 iDec = -iDec; | 1382 iDec = -iDec; |
| 1383 | 1383 |
| 1384 int iSepStyle = params[1].ToInt(); | 1384 int iSepStyle = params[1].ToInt(); |
| 1385 if (iSepStyle < 0 || iSepStyle > 3) | 1385 if (iSepStyle < 0 || iSepStyle > 3) |
| 1386 iSepStyle = 0; | 1386 iSepStyle = 0; |
| 1387 | 1387 |
| 1388 ////////////////////////////////////////////////////// | 1388 ////////////////////////////////////////////////////// |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 iMax++; | 1454 iMax++; |
| 1455 } | 1455 } |
| 1456 } | 1456 } |
| 1457 //////////////////////////////////////////////////////////////////// | 1457 //////////////////////////////////////////////////////////////////// |
| 1458 //negative mark | 1458 //negative mark |
| 1459 if (iNegative) | 1459 if (iNegative) |
| 1460 strValue = "-" + strValue; | 1460 strValue = "-" + strValue; |
| 1461 strValue += "%"; | 1461 strValue += "%"; |
| 1462 Value = CFX_WideString::FromLocal(strValue); | 1462 Value = CFX_WideString::FromLocal(strValue); |
| 1463 #endif | 1463 #endif |
| 1464 return TRUE; | 1464 return true; |
| 1465 } | 1465 } |
| 1466 //AFPercent_Keystroke(nDec, sepStyle) | 1466 //AFPercent_Keystroke(nDec, sepStyle) |
| 1467 FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Para
meters& params, CJS_Value& vRet, CFX_WideString& sError) | 1467 bool CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Paramet
ers& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1468 { | 1468 { |
| 1469 return AFNumber_Keystroke(cc,params,vRet,sError); | 1469 return AFNumber_Keystroke(cc,params,vRet,sError); |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 //function AFDate_FormatEx(cFormat) | 1472 //function AFDate_FormatEx(cFormat) |
| 1473 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, const CJS_Paramete
rs& params, CJS_Value& vRet, CFX_WideString& sError) | 1473 bool CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, const CJS_Parameters&
params, CJS_Value& vRet, CFX_WideString& sError) |
| 1474 { | 1474 { |
| 1475 CJS_Context* pContext = (CJS_Context *)cc; | 1475 CJS_Context* pContext = (CJS_Context *)cc; |
| 1476 ASSERT(pContext != NULL); | 1476 ASSERT(pContext != NULL); |
| 1477 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1477 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1478 ASSERT(pEvent != NULL); | 1478 ASSERT(pEvent != NULL); |
| 1479 | 1479 |
| 1480 if (params.size() != 1) | 1480 if (params.size() != 1) |
| 1481 { | 1481 { |
| 1482 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1482 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1483 return FALSE; | 1483 return false; |
| 1484 } | 1484 } |
| 1485 if(!pEvent->m_pValue) | 1485 if(!pEvent->m_pValue) |
| 1486 return FALSE; | 1486 return false; |
| 1487 | 1487 |
| 1488 CFX_WideString& val = pEvent->Value(); | 1488 CFX_WideString& val = pEvent->Value(); |
| 1489 CFX_WideString strValue = val; | 1489 CFX_WideString strValue = val; |
| 1490 if (strValue.IsEmpty()) | 1490 if (strValue.IsEmpty()) |
| 1491 return TRUE; | 1491 return true; |
| 1492 | 1492 |
| 1493 CFX_WideString sFormat = params[0].ToCFXWideString(); | 1493 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 1494 FX_BOOL bWrongFormat = FALSE; | 1494 bool bWrongFormat = false; |
| 1495 double dDate = 0.0f; | 1495 double dDate = 0.0f; |
| 1496 | 1496 |
| 1497 if(strValue.Find(L"GMT") != -1) | 1497 if(strValue.Find(L"GMT") != -1) |
| 1498 { | 1498 { |
| 1499 //for GMT format time | 1499 //for GMT format time |
| 1500 //such as "Tue Aug 11 14:24:16 GMT+08002009" | 1500 //such as "Tue Aug 11 14:24:16 GMT+08002009" |
| 1501 dDate = MakeInterDate(strValue); | 1501 dDate = MakeInterDate(strValue); |
| 1502 } | 1502 } |
| 1503 else | 1503 else |
| 1504 { | 1504 { |
| 1505 dDate = MakeRegularDate(strValue,sFormat,bWrongFormat); | 1505 dDate = MakeRegularDate(strValue,sFormat,bWrongFormat); |
| 1506 } | 1506 } |
| 1507 | 1507 |
| 1508 if (JS_PortIsNan(dDate)) | 1508 if (JS_PortIsNan(dDate)) |
| 1509 { | 1509 { |
| 1510 CFX_WideString swMsg; | 1510 CFX_WideString swMsg; |
| 1511 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str()
, sFormat.c_str()); | 1511 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str()
, sFormat.c_str()); |
| 1512 Alert(pContext, swMsg.c_str()); | 1512 Alert(pContext, swMsg.c_str()); |
| 1513 return FALSE; | 1513 return false; |
| 1514 } | 1514 } |
| 1515 | 1515 |
| 1516 val = MakeFormatDate(dDate,sFormat); | 1516 val = MakeFormatDate(dDate,sFormat); |
| 1517 return TRUE; | 1517 return true; |
| 1518 } | 1518 } |
| 1519 | 1519 |
| 1520 double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue) | 1520 double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue) |
| 1521 { | 1521 { |
| 1522 int nHour; | 1522 int nHour; |
| 1523 int nMin; | 1523 int nMin; |
| 1524 int nSec; | 1524 int nSec; |
| 1525 int nYear; | 1525 int nYear; |
| 1526 int nMonth; | 1526 int nMonth; |
| 1527 int nDay; | 1527 int nDay; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 | 1571 |
| 1572 if (JS_PortIsNan(dRet)) | 1572 if (JS_PortIsNan(dRet)) |
| 1573 { | 1573 { |
| 1574 dRet = JS_DateParse(strValue.c_str()); | 1574 dRet = JS_DateParse(strValue.c_str()); |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 return dRet; | 1577 return dRet; |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 //AFDate_KeystrokeEx(cFormat) | 1580 //AFDate_KeystrokeEx(cFormat) |
| 1581 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Param
eters& params, CJS_Value& vRet, CFX_WideString& sError) | 1581 bool CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Paramete
rs& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1582 { | 1582 { |
| 1583 CJS_Context* pContext = (CJS_Context *)cc; | 1583 CJS_Context* pContext = (CJS_Context *)cc; |
| 1584 ASSERT(pContext != NULL); | 1584 ASSERT(pContext != NULL); |
| 1585 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1585 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1586 ASSERT(pEvent != NULL); | 1586 ASSERT(pEvent != NULL); |
| 1587 | 1587 |
| 1588 if (params.size() != 1) | 1588 if (params.size() != 1) |
| 1589 { | 1589 { |
| 1590 sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; | 1590 sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; |
| 1591 return FALSE; | 1591 return false; |
| 1592 } | 1592 } |
| 1593 | 1593 |
| 1594 if (pEvent->WillCommit()) | 1594 if (pEvent->WillCommit()) |
| 1595 { | 1595 { |
| 1596 if(!pEvent->m_pValue) | 1596 if(!pEvent->m_pValue) |
| 1597 return FALSE; | 1597 return false; |
| 1598 CFX_WideString strValue = pEvent->Value(); | 1598 CFX_WideString strValue = pEvent->Value(); |
| 1599 if (strValue.IsEmpty()) | 1599 if (strValue.IsEmpty()) |
| 1600 return TRUE; | 1600 return true; |
| 1601 | 1601 |
| 1602 CFX_WideString sFormat = params[0].ToCFXWideString(); | 1602 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 1603 FX_BOOL bWrongFormat = FALSE; | 1603 bool bWrongFormat = false; |
| 1604 double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat); | 1604 double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat); |
| 1605 if (bWrongFormat || JS_PortIsNan(dRet)) | 1605 if (bWrongFormat || JS_PortIsNan(dRet)) |
| 1606 { | 1606 { |
| 1607 CFX_WideString swMsg; | 1607 CFX_WideString swMsg; |
| 1608 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_s
tr(), sFormat.c_str()); | 1608 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_s
tr(), sFormat.c_str()); |
| 1609 Alert(pContext, swMsg.c_str()); | 1609 Alert(pContext, swMsg.c_str()); |
| 1610 pEvent->Rc() = FALSE; | 1610 pEvent->Rc() = false; |
| 1611 return TRUE; | 1611 return true; |
| 1612 } | 1612 } |
| 1613 } | 1613 } |
| 1614 return TRUE; | 1614 return true; |
| 1615 } | 1615 } |
| 1616 | 1616 |
| 1617 FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) | 1617 bool CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, const CJS_Parameters& p
arams, CJS_Value& vRet, CFX_WideString& sError) |
| 1618 { | 1618 { |
| 1619 v8::Isolate* isolate = ::GetIsolate(cc); | 1619 v8::Isolate* isolate = ::GetIsolate(cc); |
| 1620 | 1620 |
| 1621 if (params.size() != 1) | 1621 if (params.size() != 1) |
| 1622 { | 1622 { |
| 1623 CJS_Context* pContext = (CJS_Context*)cc; | 1623 CJS_Context* pContext = (CJS_Context*)cc; |
| 1624 ASSERT(pContext != NULL); | 1624 ASSERT(pContext != NULL); |
| 1625 | 1625 |
| 1626 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1626 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1627 return FALSE; | 1627 return false; |
| 1628 } | 1628 } |
| 1629 | 1629 |
| 1630 int iIndex = params[0].ToInt(); | 1630 int iIndex = params[0].ToInt(); |
| 1631 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", | 1631 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", |
| 1632 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy", | 1632 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy", |
| 1633 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; | 1633 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; |
| 1634 | 1634 |
| 1635 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1635 ASSERT(iIndex < FX_ArraySize(cFormats)); |
| 1636 | 1636 |
| 1637 if (iIndex < 0) | 1637 if (iIndex < 0) |
| 1638 iIndex = 0; | 1638 iIndex = 0; |
| 1639 if (iIndex >= FX_ArraySize(cFormats)) | 1639 if (iIndex >= FX_ArraySize(cFormats)) |
| 1640 iIndex = 0; | 1640 iIndex = 0; |
| 1641 CJS_Parameters newParams; | 1641 CJS_Parameters newParams; |
| 1642 CJS_Value val(isolate,cFormats[iIndex]); | 1642 CJS_Value val(isolate,cFormats[iIndex]); |
| 1643 newParams.push_back(val); | 1643 newParams.push_back(val); |
| 1644 return AFDate_FormatEx(cc,newParams,vRet,sError); | 1644 return AFDate_FormatEx(cc,newParams,vRet,sError); |
| 1645 } | 1645 } |
| 1646 | 1646 |
| 1647 //AFDate_KeystrokeEx(cFormat) | 1647 //AFDate_KeystrokeEx(cFormat) |
| 1648 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, const CJS_Paramet
ers& params, CJS_Value& vRet, CFX_WideString& sError) | 1648 bool CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1649 { | 1649 { |
| 1650 v8::Isolate* isolate = ::GetIsolate(cc); | 1650 v8::Isolate* isolate = ::GetIsolate(cc); |
| 1651 | 1651 |
| 1652 if (params.size() != 1) | 1652 if (params.size() != 1) |
| 1653 { | 1653 { |
| 1654 CJS_Context* pContext = (CJS_Context*)cc; | 1654 CJS_Context* pContext = (CJS_Context*)cc; |
| 1655 ASSERT(pContext != NULL); | 1655 ASSERT(pContext != NULL); |
| 1656 | 1656 |
| 1657 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1657 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1658 return FALSE; | 1658 return false; |
| 1659 } | 1659 } |
| 1660 | 1660 |
| 1661 int iIndex = params[0].ToInt(); | 1661 int iIndex = params[0].ToInt(); |
| 1662 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", | 1662 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", |
| 1663 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy", | 1663 L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy", |
| 1664 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; | 1664 L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; |
| 1665 | 1665 |
| 1666 ASSERT(iIndex<FX_ArraySize(cFormats)); | 1666 ASSERT(iIndex<FX_ArraySize(cFormats)); |
| 1667 | 1667 |
| 1668 if (iIndex < 0) | 1668 if (iIndex < 0) |
| 1669 iIndex = 0; | 1669 iIndex = 0; |
| 1670 if (iIndex >= FX_ArraySize(cFormats)) | 1670 if (iIndex >= FX_ArraySize(cFormats)) |
| 1671 iIndex = 0; | 1671 iIndex = 0; |
| 1672 CJS_Parameters newParams; | 1672 CJS_Parameters newParams; |
| 1673 CJS_Value val(isolate,cFormats[iIndex]); | 1673 CJS_Value val(isolate,cFormats[iIndex]); |
| 1674 newParams.push_back(val); | 1674 newParams.push_back(val); |
| 1675 return AFDate_KeystrokeEx(cc,newParams,vRet,sError); | 1675 return AFDate_KeystrokeEx(cc,newParams,vRet,sError); |
| 1676 } | 1676 } |
| 1677 | 1677 |
| 1678 //function AFTime_Format(ptf) | 1678 //function AFTime_Format(ptf) |
| 1679 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) | 1679 bool CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, const CJS_Parameters& p
arams, CJS_Value& vRet, CFX_WideString& sError) |
| 1680 { | 1680 { |
| 1681 v8::Isolate* isolate = ::GetIsolate(cc); | 1681 v8::Isolate* isolate = ::GetIsolate(cc); |
| 1682 | 1682 |
| 1683 if (params.size() != 1) | 1683 if (params.size() != 1) |
| 1684 { | 1684 { |
| 1685 CJS_Context* pContext = (CJS_Context*)cc; | 1685 CJS_Context* pContext = (CJS_Context*)cc; |
| 1686 ASSERT(pContext != NULL); | 1686 ASSERT(pContext != NULL); |
| 1687 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1687 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1688 return FALSE; | 1688 return false; |
| 1689 } | 1689 } |
| 1690 | 1690 |
| 1691 int iIndex = params[0].ToInt(); | 1691 int iIndex = params[0].ToInt(); |
| 1692 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss t
t"}; | 1692 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss t
t"}; |
| 1693 | 1693 |
| 1694 ASSERT(iIndex<FX_ArraySize(cFormats)); | 1694 ASSERT(iIndex<FX_ArraySize(cFormats)); |
| 1695 | 1695 |
| 1696 if (iIndex < 0) | 1696 if (iIndex < 0) |
| 1697 iIndex = 0; | 1697 iIndex = 0; |
| 1698 if (iIndex >= FX_ArraySize(cFormats)) | 1698 if (iIndex >= FX_ArraySize(cFormats)) |
| 1699 iIndex = 0; | 1699 iIndex = 0; |
| 1700 CJS_Parameters newParams; | 1700 CJS_Parameters newParams; |
| 1701 CJS_Value val(isolate,cFormats[iIndex]); | 1701 CJS_Value val(isolate,cFormats[iIndex]); |
| 1702 newParams.push_back(val); | 1702 newParams.push_back(val); |
| 1703 return AFDate_FormatEx(cc,newParams,vRet,sError); | 1703 return AFDate_FormatEx(cc,newParams,vRet,sError); |
| 1704 } | 1704 } |
| 1705 | 1705 |
| 1706 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, const CJS_Paramet
ers& params, CJS_Value& vRet, CFX_WideString& sError) | 1706 bool CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1707 { | 1707 { |
| 1708 v8::Isolate* isolate = ::GetIsolate(cc); | 1708 v8::Isolate* isolate = ::GetIsolate(cc); |
| 1709 if (params.size() != 1) | 1709 if (params.size() != 1) |
| 1710 { | 1710 { |
| 1711 CJS_Context* pContext = (CJS_Context*)cc; | 1711 CJS_Context* pContext = (CJS_Context*)cc; |
| 1712 ASSERT(pContext != NULL); | 1712 ASSERT(pContext != NULL); |
| 1713 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1713 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1714 return FALSE; | 1714 return false; |
| 1715 } | 1715 } |
| 1716 | 1716 |
| 1717 int iIndex = params[0].ToInt(); | 1717 int iIndex = params[0].ToInt(); |
| 1718 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss t
t"}; | 1718 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss t
t"}; |
| 1719 | 1719 |
| 1720 ASSERT(iIndex<FX_ArraySize(cFormats)); | 1720 ASSERT(iIndex<FX_ArraySize(cFormats)); |
| 1721 | 1721 |
| 1722 if (iIndex < 0) | 1722 if (iIndex < 0) |
| 1723 iIndex = 0; | 1723 iIndex = 0; |
| 1724 if (iIndex >= FX_ArraySize(cFormats)) | 1724 if (iIndex >= FX_ArraySize(cFormats)) |
| 1725 iIndex = 0; | 1725 iIndex = 0; |
| 1726 CJS_Parameters newParams; | 1726 CJS_Parameters newParams; |
| 1727 CJS_Value val(isolate,cFormats[iIndex]); | 1727 CJS_Value val(isolate,cFormats[iIndex]); |
| 1728 newParams.push_back(val); | 1728 newParams.push_back(val); |
| 1729 return AFDate_KeystrokeEx(cc,newParams,vRet,sError); | 1729 return AFDate_KeystrokeEx(cc,newParams,vRet,sError); |
| 1730 } | 1730 } |
| 1731 | 1731 |
| 1732 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, const CJS_Paramete
rs& params, CJS_Value& vRet, CFX_WideString& sError) | 1732 bool CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, const CJS_Parameters&
params, CJS_Value& vRet, CFX_WideString& sError) |
| 1733 { | 1733 { |
| 1734 return AFDate_FormatEx(cc,params,vRet,sError); | 1734 return AFDate_FormatEx(cc,params,vRet,sError); |
| 1735 } | 1735 } |
| 1736 | 1736 |
| 1737 FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Param
eters& params, CJS_Value& vRet, CFX_WideString& sError) | 1737 bool CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Paramete
rs& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1738 { | 1738 { |
| 1739 return AFDate_KeystrokeEx(cc,params,vRet,sError); | 1739 return AFDate_KeystrokeEx(cc,params,vRet,sError); |
| 1740 } | 1740 } |
| 1741 | 1741 |
| 1742 //function AFSpecial_Format(psf) | 1742 //function AFSpecial_Format(psf) |
| 1743 FX_BOOL CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, const CJS_Paramet
ers& params, CJS_Value& vRet, CFX_WideString& sError) | 1743 bool CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1744 { | 1744 { |
| 1745 CJS_Context* pContext = (CJS_Context *)cc; | 1745 CJS_Context* pContext = (CJS_Context *)cc; |
| 1746 ASSERT(pContext != NULL); | 1746 ASSERT(pContext != NULL); |
| 1747 | 1747 |
| 1748 if (params.size() != 1) | 1748 if (params.size() != 1) |
| 1749 { | 1749 { |
| 1750 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1750 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1751 return FALSE; | 1751 return false; |
| 1752 } | 1752 } |
| 1753 | 1753 |
| 1754 std::string cFormat; | 1754 std::string cFormat; |
| 1755 int iIndex = params[0].ToInt(); | 1755 int iIndex = params[0].ToInt(); |
| 1756 | 1756 |
| 1757 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1757 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1758 ASSERT(pEvent != NULL); | 1758 ASSERT(pEvent != NULL); |
| 1759 | 1759 |
| 1760 if(!pEvent->m_pValue) | 1760 if(!pEvent->m_pValue) |
| 1761 return FALSE; | 1761 return false; |
| 1762 CFX_WideString& Value = pEvent->Value(); | 1762 CFX_WideString& Value = pEvent->Value(); |
| 1763 std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str(); | 1763 std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str(); |
| 1764 | 1764 |
| 1765 switch (iIndex) | 1765 switch (iIndex) |
| 1766 { | 1766 { |
| 1767 case 0: | 1767 case 0: |
| 1768 cFormat = "99999"; | 1768 cFormat = "99999"; |
| 1769 break; | 1769 break; |
| 1770 case 1: | 1770 case 1: |
| 1771 cFormat = "99999-9999"; | 1771 cFormat = "99999-9999"; |
| 1772 break; | 1772 break; |
| 1773 case 2: | 1773 case 2: |
| 1774 { | 1774 { |
| 1775 std::string NumberStr; | 1775 std::string NumberStr; |
| 1776 util::printx("9999999999", strSrc,NumberStr); | 1776 util::printx("9999999999", strSrc,NumberStr); |
| 1777 if (NumberStr.length() >= 10 ) | 1777 if (NumberStr.length() >= 10 ) |
| 1778 cFormat = "(999) 999-9999"; | 1778 cFormat = "(999) 999-9999"; |
| 1779 else | 1779 else |
| 1780 cFormat = "999-9999"; | 1780 cFormat = "999-9999"; |
| 1781 break; | 1781 break; |
| 1782 } | 1782 } |
| 1783 case 3: | 1783 case 3: |
| 1784 cFormat = "999-99-9999"; | 1784 cFormat = "999-99-9999"; |
| 1785 break; | 1785 break; |
| 1786 } | 1786 } |
| 1787 | 1787 |
| 1788 std::string strDes; | 1788 std::string strDes; |
| 1789 util::printx(cFormat,strSrc,strDes); | 1789 util::printx(cFormat,strSrc,strDes); |
| 1790 Value = CFX_WideString::FromLocal(strDes.c_str()); | 1790 Value = CFX_WideString::FromLocal(strDes.c_str()); |
| 1791 return TRUE; | 1791 return true; |
| 1792 } | 1792 } |
| 1793 | 1793 |
| 1794 | 1794 |
| 1795 //function AFSpecial_KeystrokeEx(mask) | 1795 //function AFSpecial_KeystrokeEx(mask) |
| 1796 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Pa
rameters& params, CJS_Value& vRet, CFX_WideString& sError) | 1796 bool CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Param
eters& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1797 { | 1797 { |
| 1798 CJS_Context* pContext = (CJS_Context *)cc; | 1798 CJS_Context* pContext = (CJS_Context *)cc; |
| 1799 ASSERT(pContext != NULL); | 1799 ASSERT(pContext != NULL); |
| 1800 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1800 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1801 | 1801 |
| 1802 ASSERT(pEvent != NULL); | 1802 ASSERT(pEvent != NULL); |
| 1803 | 1803 |
| 1804 if (params.size() < 1) | 1804 if (params.size() < 1) |
| 1805 { | 1805 { |
| 1806 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1806 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1807 return FALSE; | 1807 return false; |
| 1808 } | 1808 } |
| 1809 | 1809 |
| 1810 if(!pEvent->m_pValue) | 1810 if(!pEvent->m_pValue) |
| 1811 return FALSE; | 1811 return false; |
| 1812 CFX_WideString& valEvent = pEvent->Value(); | 1812 CFX_WideString& valEvent = pEvent->Value(); |
| 1813 | 1813 |
| 1814 CFX_WideString wstrMask = params[0].ToCFXWideString(); | 1814 CFX_WideString wstrMask = params[0].ToCFXWideString(); |
| 1815 if (wstrMask.IsEmpty()) | 1815 if (wstrMask.IsEmpty()) |
| 1816 return TRUE; | 1816 return true; |
| 1817 | 1817 |
| 1818 std::wstring wstrValue = valEvent.c_str(); | 1818 std::wstring wstrValue = valEvent.c_str(); |
| 1819 | 1819 |
| 1820 if (pEvent->WillCommit()) | 1820 if (pEvent->WillCommit()) |
| 1821 { | 1821 { |
| 1822 if (wstrValue.empty()) | 1822 if (wstrValue.empty()) |
| 1823 return TRUE; | 1823 return true; |
| 1824 int iIndexMask = 0; | 1824 int iIndexMask = 0; |
| 1825 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(
); it++) | 1825 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(
); it++) |
| 1826 { | 1826 { |
| 1827 wchar_t w_Value = *it; | 1827 wchar_t w_Value = *it; |
| 1828 if (!maskSatisfied(w_Value,wstrMask[iIndexMask])) | 1828 if (!maskSatisfied(w_Value,wstrMask[iIndexMask])) |
| 1829 break; | 1829 break; |
| 1830 iIndexMask++; | 1830 iIndexMask++; |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size(
) && wstrMask.GetLength() != 0)) | 1833 if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size(
) && wstrMask.GetLength() != 0)) |
| 1834 { | 1834 { |
| 1835 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KE
YSTROKE).c_str()); | 1835 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KE
YSTROKE).c_str()); |
| 1836 pEvent->Rc() = FALSE; | 1836 pEvent->Rc() = false; |
| 1837 } | 1837 } |
| 1838 return TRUE; | 1838 return true; |
| 1839 } | 1839 } |
| 1840 | 1840 |
| 1841 CFX_WideString &wideChange = pEvent->Change(); | 1841 CFX_WideString &wideChange = pEvent->Change(); |
| 1842 std::wstring wChange = wideChange.c_str(); | 1842 std::wstring wChange = wideChange.c_str(); |
| 1843 if (wChange.empty()) | 1843 if (wChange.empty()) |
| 1844 return TRUE; | 1844 return true; |
| 1845 | 1845 |
| 1846 int iIndexMask = pEvent->SelStart(); | 1846 int iIndexMask = pEvent->SelStart(); |
| 1847 | 1847 |
| 1848 if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.len
gth() > (FX_DWORD)wstrMask.GetLength()) | 1848 if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.len
gth() > (FX_DWORD)wstrMask.GetLength()) |
| 1849 { | 1849 { |
| 1850 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).
c_str()); | 1850 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).
c_str()); |
| 1851 pEvent->Rc() = FALSE; | 1851 pEvent->Rc() = false; |
| 1852 return TRUE; | 1852 return true; |
| 1853 } | 1853 } |
| 1854 | 1854 |
| 1855 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) | 1855 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) |
| 1856 { | 1856 { |
| 1857 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).
c_str()); | 1857 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).
c_str()); |
| 1858 pEvent->Rc() = FALSE; | 1858 pEvent->Rc() = false; |
| 1859 return TRUE; | 1859 return true; |
| 1860 } | 1860 } |
| 1861 | 1861 |
| 1862 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) | 1862 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) |
| 1863 { | 1863 { |
| 1864 if (iIndexMask >= wstrMask.GetLength()) | 1864 if (iIndexMask >= wstrMask.GetLength()) |
| 1865 { | 1865 { |
| 1866 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLO
NG).c_str()); | 1866 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLO
NG).c_str()); |
| 1867 pEvent->Rc() = FALSE; | 1867 pEvent->Rc() = false; |
| 1868 return TRUE; | 1868 return true; |
| 1869 } | 1869 } |
| 1870 wchar_t w_Mask = wstrMask[iIndexMask]; | 1870 wchar_t w_Mask = wstrMask[iIndexMask]; |
| 1871 if (!isReservedMaskChar(w_Mask)) | 1871 if (!isReservedMaskChar(w_Mask)) |
| 1872 { | 1872 { |
| 1873 *it = w_Mask; | 1873 *it = w_Mask; |
| 1874 } | 1874 } |
| 1875 wchar_t w_Change = *it; | 1875 wchar_t w_Change = *it; |
| 1876 if (!maskSatisfied(w_Change,w_Mask)) | 1876 if (!maskSatisfied(w_Change,w_Mask)) |
| 1877 { | 1877 { |
| 1878 pEvent->Rc() = FALSE; | 1878 pEvent->Rc() = false; |
| 1879 return TRUE; | 1879 return true; |
| 1880 } | 1880 } |
| 1881 iIndexMask++; | 1881 iIndexMask++; |
| 1882 } | 1882 } |
| 1883 | 1883 |
| 1884 wideChange = wChange.c_str(); | 1884 wideChange = wChange.c_str(); |
| 1885 return TRUE; | 1885 return true; |
| 1886 } | 1886 } |
| 1887 | 1887 |
| 1888 | 1888 |
| 1889 //function AFSpecial_Keystroke(psf) | 1889 //function AFSpecial_Keystroke(psf) |
| 1890 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Para
meters& params, CJS_Value& vRet, CFX_WideString& sError) | 1890 bool CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Paramet
ers& params, CJS_Value& vRet, CFX_WideString& sError) |
| 1891 { | 1891 { |
| 1892 v8::Isolate* isolate = ::GetIsolate(cc); | 1892 v8::Isolate* isolate = ::GetIsolate(cc); |
| 1893 | 1893 |
| 1894 CJS_Context* pContext = (CJS_Context *)cc; | 1894 CJS_Context* pContext = (CJS_Context *)cc; |
| 1895 ASSERT(pContext != NULL); | 1895 ASSERT(pContext != NULL); |
| 1896 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1896 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1897 ASSERT(pEvent != NULL); | 1897 ASSERT(pEvent != NULL); |
| 1898 | 1898 |
| 1899 if (params.size() != 1) | 1899 if (params.size() != 1) |
| 1900 { | 1900 { |
| 1901 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1901 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1902 return FALSE; | 1902 return false; |
| 1903 } | 1903 } |
| 1904 | 1904 |
| 1905 std::string cFormat; | 1905 std::string cFormat; |
| 1906 int iIndex = params[0].ToInt(); | 1906 int iIndex = params[0].ToInt(); |
| 1907 | 1907 |
| 1908 if(!pEvent->m_pValue) | 1908 if(!pEvent->m_pValue) |
| 1909 return FALSE; | 1909 return false; |
| 1910 //CJS_Value val = pEvent->Value(); | 1910 //CJS_Value val = pEvent->Value(); |
| 1911 CFX_WideString& val = pEvent->Value(); | 1911 CFX_WideString& val = pEvent->Value(); |
| 1912 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); | 1912 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); |
| 1913 std::wstring wstrChange = pEvent->Change().c_str(); | 1913 std::wstring wstrChange = pEvent->Change().c_str(); |
| 1914 | 1914 |
| 1915 switch (iIndex) | 1915 switch (iIndex) |
| 1916 { | 1916 { |
| 1917 case 0: | 1917 case 0: |
| 1918 cFormat = "99999"; | 1918 cFormat = "99999"; |
| 1919 break; | 1919 break; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1939 break; | 1939 break; |
| 1940 } | 1940 } |
| 1941 | 1941 |
| 1942 CJS_Parameters params2; | 1942 CJS_Parameters params2; |
| 1943 CJS_Value vMask(isolate, cFormat.c_str()); | 1943 CJS_Value vMask(isolate, cFormat.c_str()); |
| 1944 params2.push_back(vMask); | 1944 params2.push_back(vMask); |
| 1945 | 1945 |
| 1946 return AFSpecial_KeystrokeEx(cc,params2,vRet,sError); | 1946 return AFSpecial_KeystrokeEx(cc,params2,vRet,sError); |
| 1947 } | 1947 } |
| 1948 | 1948 |
| 1949 FX_BOOL CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) | 1949 bool CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, const CJS_Parameters& p
arams, CJS_Value& vRet, CFX_WideString& sError) |
| 1950 { | 1950 { |
| 1951 CJS_Context* pContext = (CJS_Context *)cc; | 1951 CJS_Context* pContext = (CJS_Context *)cc; |
| 1952 ASSERT(pContext != NULL); | 1952 ASSERT(pContext != NULL); |
| 1953 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); | 1953 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); |
| 1954 ASSERT(pEventHandler != NULL); | 1954 ASSERT(pEventHandler != NULL); |
| 1955 | 1955 |
| 1956 if (params.size() != 1) | 1956 if (params.size() != 1) |
| 1957 { | 1957 { |
| 1958 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1958 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1959 return FALSE; | 1959 return false; |
| 1960 } | 1960 } |
| 1961 | 1961 |
| 1962 CFX_WideString swValue; | 1962 CFX_WideString swValue; |
| 1963 if (pEventHandler->m_pValue != NULL) | 1963 if (pEventHandler->m_pValue != NULL) |
| 1964 swValue = pEventHandler->Value(); | 1964 swValue = pEventHandler->Value(); |
| 1965 | 1965 |
| 1966 if (pEventHandler->WillCommit()) | 1966 if (pEventHandler->WillCommit()) |
| 1967 { | 1967 { |
| 1968 vRet = swValue.c_str(); | 1968 vRet = swValue.c_str(); |
| 1969 return TRUE; | 1969 return true; |
| 1970 } | 1970 } |
| 1971 | 1971 |
| 1972 CFX_WideString prefix,postfix; | 1972 CFX_WideString prefix,postfix; |
| 1973 | 1973 |
| 1974 if (pEventHandler->SelStart() >= 0) | 1974 if (pEventHandler->SelStart() >= 0) |
| 1975 prefix = swValue.Mid(0,pEventHandler->SelStart()); | 1975 prefix = swValue.Mid(0,pEventHandler->SelStart()); |
| 1976 else | 1976 else |
| 1977 prefix = L""; | 1977 prefix = L""; |
| 1978 | 1978 |
| 1979 | 1979 |
| 1980 if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLe
ngth()) | 1980 if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLe
ngth()) |
| 1981 postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEv
entHandler->SelEnd()); | 1981 postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEv
entHandler->SelEnd()); |
| 1982 else postfix = L""; | 1982 else postfix = L""; |
| 1983 | 1983 |
| 1984 vRet = (prefix + pEventHandler->Change() + postfix).c_str(); | 1984 vRet = (prefix + pEventHandler->Change() + postfix).c_str(); |
| 1985 | 1985 |
| 1986 return TRUE; | 1986 return true; |
| 1987 } | 1987 } |
| 1988 | 1988 |
| 1989 FX_BOOL CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) | 1989 bool CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters& p
arams, CJS_Value& vRet, CFX_WideString& sError) |
| 1990 { | 1990 { |
| 1991 CJS_Context* pContext = (CJS_Context *)cc; | 1991 CJS_Context* pContext = (CJS_Context *)cc; |
| 1992 ASSERT(pContext != NULL); | 1992 ASSERT(pContext != NULL); |
| 1993 | 1993 |
| 1994 if (params.size() != 2) | 1994 if (params.size() != 2) |
| 1995 { | 1995 { |
| 1996 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1996 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1997 return FALSE; | 1997 return false; |
| 1998 } | 1998 } |
| 1999 | 1999 |
| 2000 CFX_WideString sValue = params[0].ToCFXWideString(); | 2000 CFX_WideString sValue = params[0].ToCFXWideString(); |
| 2001 CFX_WideString sFormat = params[1].ToCFXWideString(); | 2001 CFX_WideString sFormat = params[1].ToCFXWideString(); |
| 2002 | 2002 |
| 2003 FX_BOOL bWrongFormat = FALSE; | 2003 bool bWrongFormat = false; |
| 2004 double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat); | 2004 double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat); |
| 2005 | 2005 |
| 2006 if (JS_PortIsNan(dDate)) | 2006 if (JS_PortIsNan(dDate)) |
| 2007 { | 2007 { |
| 2008 CFX_WideString swMsg; | 2008 CFX_WideString swMsg; |
| 2009 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str()
, sFormat.c_str()); | 2009 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str()
, sFormat.c_str()); |
| 2010 Alert((CJS_Context *)cc, swMsg.c_str()); | 2010 Alert((CJS_Context *)cc, swMsg.c_str()); |
| 2011 return FALSE; | 2011 return false; |
| 2012 } | 2012 } |
| 2013 | 2013 |
| 2014 vRet = dDate; | 2014 vRet = dDate; |
| 2015 return TRUE; | 2015 return true; |
| 2016 } | 2016 } |
| 2017 | 2017 |
| 2018 FX_BOOL CJS_PublicMethods::AFSimple(IFXJS_Context* cc, const CJS_Parameters& par
ams, CJS_Value& vRet, CFX_WideString& sError) | 2018 bool CJS_PublicMethods::AFSimple(IFXJS_Context* cc, const CJS_Parameters& params
, CJS_Value& vRet, CFX_WideString& sError) |
| 2019 { | 2019 { |
| 2020 if (params.size() != 3) | 2020 if (params.size() != 3) |
| 2021 { | 2021 { |
| 2022 CJS_Context* pContext = (CJS_Context *)cc; | 2022 CJS_Context* pContext = (CJS_Context *)cc; |
| 2023 ASSERT(pContext != NULL); | 2023 ASSERT(pContext != NULL); |
| 2024 | 2024 |
| 2025 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 2025 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 2026 return FALSE; | 2026 return false; |
| 2027 } | 2027 } |
| 2028 | 2028 |
| 2029 vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1].ToDo
uble(), params[2].ToDouble()); | 2029 vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1].ToDo
uble(), params[2].ToDouble()); |
| 2030 return TRUE; | 2030 return true; |
| 2031 } | 2031 } |
| 2032 | 2032 |
| 2033 FX_BOOL CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters&
params, CJS_Value& vRet, CFX_WideString& sError) | 2033 bool CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters& pa
rams, CJS_Value& vRet, CFX_WideString& sError) |
| 2034 { | 2034 { |
| 2035 if (params.size() != 1) | 2035 if (params.size() != 1) |
| 2036 { | 2036 { |
| 2037 CJS_Context* pContext = (CJS_Context *)cc; | 2037 CJS_Context* pContext = (CJS_Context *)cc; |
| 2038 ASSERT(pContext != NULL); | 2038 ASSERT(pContext != NULL); |
| 2039 | 2039 |
| 2040 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 2040 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 2041 return FALSE; | 2041 return false; |
| 2042 } | 2042 } |
| 2043 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); | 2043 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); |
| 2044 return TRUE; | 2044 return true; |
| 2045 } | 2045 } |
| 2046 | 2046 |
| 2047 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Param
eters& params, CJS_Value& vRet, CFX_WideString& sError) | 2047 bool CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Paramete
rs& params, CJS_Value& vRet, CFX_WideString& sError) |
| 2048 { | 2048 { |
| 2049 v8::Isolate* isolate = ::GetIsolate(cc); | 2049 v8::Isolate* isolate = ::GetIsolate(cc); |
| 2050 | 2050 |
| 2051 CJS_Context* pContext = (CJS_Context *)cc; | 2051 CJS_Context* pContext = (CJS_Context *)cc; |
| 2052 ASSERT(pContext != NULL); | 2052 ASSERT(pContext != NULL); |
| 2053 | 2053 |
| 2054 if (params.size() != 2) | 2054 if (params.size() != 2) |
| 2055 { | 2055 { |
| 2056 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 2056 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 2057 return FALSE; | 2057 return false; |
| 2058 } | 2058 } |
| 2059 | 2059 |
| 2060 CJS_Value params1 = params[1]; | 2060 CJS_Value params1 = params[1]; |
| 2061 | 2061 |
| 2062 if (!params1.IsArrayObject() && params1.GetType() != VT_string) | 2062 if (!params1.IsArrayObject() && params1.GetType() != VT_string) |
| 2063 { | 2063 { |
| 2064 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 2064 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 2065 return FALSE; | 2065 return false; |
| 2066 } | 2066 } |
| 2067 | 2067 |
| 2068 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); | 2068 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); |
| 2069 ASSERT(pReaderDoc != NULL); | 2069 ASSERT(pReaderDoc != NULL); |
| 2070 | 2070 |
| 2071 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); | 2071 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); |
| 2072 ASSERT(pReaderInterForm != NULL); | 2072 ASSERT(pReaderInterForm != NULL); |
| 2073 | 2073 |
| 2074 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); | 2074 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
| 2075 ASSERT(pInterForm != NULL); | 2075 ASSERT(pInterForm != NULL); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2155 } | 2155 } |
| 2156 | 2156 |
| 2157 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) | 2157 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) |
| 2158 dValue /= nFieldsCount; | 2158 dValue /= nFieldsCount; |
| 2159 | 2159 |
| 2160 dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FX
SYS_pow((double)10,(double)6); | 2160 dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FX
SYS_pow((double)10,(double)6); |
| 2161 CJS_Value jsValue(isolate,dValue); | 2161 CJS_Value jsValue(isolate,dValue); |
| 2162 if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue) | 2162 if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue) |
| 2163 ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue.ToCF
XWideString(); | 2163 ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue.ToCF
XWideString(); |
| 2164 | 2164 |
| 2165 return TRUE; | 2165 return true; |
| 2166 } | 2166 } |
| 2167 | 2167 |
| 2168 /* This function validates the current event to ensure that its value is | 2168 /* This function validates the current event to ensure that its value is |
| 2169 ** within the specified range. */ | 2169 ** within the specified range. */ |
| 2170 | 2170 |
| 2171 FX_BOOL CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, const CJS_Paramet
ers& params, CJS_Value& vRet, CFX_WideString& sError) | 2171 bool CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) |
| 2172 { | 2172 { |
| 2173 CJS_Context* pContext = (CJS_Context *)cc; | 2173 CJS_Context* pContext = (CJS_Context *)cc; |
| 2174 ASSERT(pContext != NULL); | 2174 ASSERT(pContext != NULL); |
| 2175 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 2175 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 2176 ASSERT(pEvent != NULL); | 2176 ASSERT(pEvent != NULL); |
| 2177 | 2177 |
| 2178 if (params.size() != 4) | 2178 if (params.size() != 4) |
| 2179 { | 2179 { |
| 2180 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 2180 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 2181 return FALSE; | 2181 return false; |
| 2182 } | 2182 } |
| 2183 | 2183 |
| 2184 if(!pEvent->m_pValue) | 2184 if(!pEvent->m_pValue) |
| 2185 return FALSE; | 2185 return false; |
| 2186 if (pEvent->Value().IsEmpty() ) | 2186 if (pEvent->Value().IsEmpty() ) |
| 2187 return TRUE; | 2187 return true; |
| 2188 double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value())); | 2188 double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value())); |
| 2189 FX_BOOL bGreaterThan = params[0].ToBool(); | 2189 bool bGreaterThan = params[0].ToBool(); |
| 2190 double dGreaterThan = params[1].ToDouble(); | 2190 double dGreaterThan = params[1].ToDouble(); |
| 2191 FX_BOOL bLessThan = params[2].ToBool(); | 2191 bool bLessThan = params[2].ToBool(); |
| 2192 double dLessThan = params[3].ToDouble(); | 2192 double dLessThan = params[3].ToDouble(); |
| 2193 CFX_WideString swMsg; | 2193 CFX_WideString swMsg; |
| 2194 | 2194 |
| 2195 if (bGreaterThan && bLessThan) | 2195 if (bGreaterThan && bLessThan) |
| 2196 { | 2196 { |
| 2197 if (dEentValue < dGreaterThan || dEentValue > dLessThan) | 2197 if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
| 2198 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(
), | 2198 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(
), |
| 2199 params[1].ToCFXWideString().c_str(), | 2199 params[1].ToCFXWideString().c_str(), |
| 2200 params[3].ToCFXWideString().c_str()); | 2200 params[3].ToCFXWideString().c_str()); |
| 2201 } | 2201 } |
| 2202 else if (bGreaterThan) | 2202 else if (bGreaterThan) |
| 2203 { | 2203 { |
| 2204 if (dEentValue < dGreaterThan) | 2204 if (dEentValue < dGreaterThan) |
| 2205 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(
), | 2205 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(
), |
| 2206 params[1].ToCFXWideString().c_str()); | 2206 params[1].ToCFXWideString().c_str()); |
| 2207 } | 2207 } |
| 2208 else if (bLessThan) | 2208 else if (bLessThan) |
| 2209 { | 2209 { |
| 2210 if (dEentValue > dLessThan) | 2210 if (dEentValue > dLessThan) |
| 2211 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(
), | 2211 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(
), |
| 2212 params[3].ToCFXWideString().c_str()); | 2212 params[3].ToCFXWideString().c_str()); |
| 2213 } | 2213 } |
| 2214 | 2214 |
| 2215 if (!swMsg.IsEmpty()) | 2215 if (!swMsg.IsEmpty()) |
| 2216 { | 2216 { |
| 2217 Alert(pContext, swMsg.c_str()); | 2217 Alert(pContext, swMsg.c_str()); |
| 2218 pEvent->Rc() = FALSE; | 2218 pEvent->Rc() = false; |
| 2219 } | 2219 } |
| 2220 return TRUE; | 2220 return true; |
| 2221 } | 2221 } |
| 2222 | 2222 |
| 2223 FX_BOOL CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, const CJS_Parameters
& params, CJS_Value& vRet, CFX_WideString& sError) | 2223 bool CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, const CJS_Parameters& p
arams, CJS_Value& vRet, CFX_WideString& sError) |
| 2224 { | 2224 { |
| 2225 v8::Isolate* isolate = ::GetIsolate(cc); | 2225 v8::Isolate* isolate = ::GetIsolate(cc); |
| 2226 CJS_Context* pContext = (CJS_Context*)cc; | 2226 CJS_Context* pContext = (CJS_Context*)cc; |
| 2227 ASSERT(pContext != NULL); | 2227 ASSERT(pContext != NULL); |
| 2228 | 2228 |
| 2229 if (params.size() != 1) | 2229 if (params.size() != 1) |
| 2230 { | 2230 { |
| 2231 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 2231 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 2232 return FALSE; | 2232 return false; |
| 2233 } | 2233 } |
| 2234 | 2234 |
| 2235 CJS_Array nums(isolate); | 2235 CJS_Array nums(isolate); |
| 2236 | 2236 |
| 2237 CFX_WideString str = params[0].ToCFXWideString(); | 2237 CFX_WideString str = params[0].ToCFXWideString(); |
| 2238 CFX_WideString sPart; | 2238 CFX_WideString sPart; |
| 2239 | 2239 |
| 2240 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 2240 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
| 2241 str = L"0" + str; | 2241 str = L"0" + str; |
| 2242 | 2242 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2262 if (sPart.GetLength() > 0) | 2262 if (sPart.GetLength() > 0) |
| 2263 { | 2263 { |
| 2264 nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str())); | 2264 nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str())); |
| 2265 } | 2265 } |
| 2266 | 2266 |
| 2267 if (nums.GetLength() > 0) | 2267 if (nums.GetLength() > 0) |
| 2268 vRet = nums; | 2268 vRet = nums; |
| 2269 else | 2269 else |
| 2270 vRet.SetNull(); | 2270 vRet.SetNull(); |
| 2271 | 2271 |
| 2272 return TRUE; | 2272 return true; |
| 2273 } | 2273 } |
| OLD | NEW |