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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 bool bXFAPicture = false; | 247 bool bXFAPicture = false; |
248 if (iSize > 2) { | 248 if (iSize > 2) { |
249 bXFAPicture = params[2].ToBool(); | 249 bXFAPicture = params[2].ToBool(); |
250 } | 250 } |
251 | 251 |
252 if (bXFAPicture) { | 252 if (bXFAPicture) { |
253 return FALSE; // currently, it doesn't support XFAPicture. | 253 return FALSE; // currently, it doesn't support XFAPicture. |
254 } | 254 } |
255 | 255 |
256 int iIndex; | 256 for (size_t i = 0; i < sizeof(fcTable) / sizeof(stru_TbConvert); ++i) { |
257 for (iIndex = 0; iIndex < sizeof(fcTable) / sizeof(stru_TbConvert); | |
258 iIndex++) { | |
259 int iStart = 0; | 257 int iStart = 0; |
260 int iEnd; | 258 int iEnd; |
261 while ((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1) { | 259 while ((iEnd = cFormat.find(fcTable[i].lpszJSMark, iStart)) != -1) { |
262 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), | 260 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[i].lpszJSMark), |
263 fcTable[iIndex].lpszCppMark); | 261 fcTable[i].lpszCppMark); |
264 iStart = iEnd; | 262 iStart = iEnd; |
265 } | 263 } |
266 } | 264 } |
267 | 265 |
268 int iYear, iMonth, iDay, iHour, iMin, iSec; | 266 int iYear, iMonth, iDay, iHour, iMin, iSec; |
269 iYear = jsDate.GetYear(); | 267 iYear = jsDate.GetYear(); |
270 iMonth = jsDate.GetMonth(); | 268 iMonth = jsDate.GetMonth(); |
271 iDay = jsDate.GetDay(); | 269 iDay = jsDate.GetDay(); |
272 iHour = jsDate.GetHours(); | 270 iHour = jsDate.GetHours(); |
273 iMin = jsDate.GetMinutes(); | 271 iMin = jsDate.GetMinutes(); |
(...skipping 11 matching lines...) Expand all Loading... |
285 const FX_WCHAR* lpszJSMark; | 283 const FX_WCHAR* lpszJSMark; |
286 int iValue; | 284 int iValue; |
287 }; | 285 }; |
288 | 286 |
289 stru_TbConvertAd cTableAd[] = { | 287 stru_TbConvertAd cTableAd[] = { |
290 {L"m", iMonth + 1}, {L"d", iDay}, | 288 {L"m", iMonth + 1}, {L"d", iDay}, |
291 {L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour}, | 289 {L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour}, |
292 {L"M", iMin}, {L"s", iSec}, | 290 {L"M", iMin}, {L"s", iSec}, |
293 }; | 291 }; |
294 | 292 |
295 for (iIndex = 0; iIndex < sizeof(cTableAd) / sizeof(stru_TbConvertAd); | 293 for (size_t i = 0; i < sizeof(cTableAd) / sizeof(stru_TbConvertAd); ++i) { |
296 iIndex++) { | |
297 wchar_t tszValue[10]; | 294 wchar_t tszValue[10]; |
298 CFX_WideString sValue; | 295 CFX_WideString sValue; |
299 sValue.Format(L"%d", cTableAd[iIndex].iValue); | 296 sValue.Format(L"%d", cTableAd[i].iValue); |
300 memcpy(tszValue, (wchar_t*)sValue.GetBuffer(sValue.GetLength() + 1), | 297 memcpy(tszValue, (wchar_t*)sValue.GetBuffer(sValue.GetLength() + 1), |
301 (sValue.GetLength() + 1) * sizeof(wchar_t)); | 298 (sValue.GetLength() + 1) * sizeof(wchar_t)); |
302 | 299 |
303 int iStart = 0; | 300 int iStart = 0; |
304 int iEnd; | 301 int iEnd; |
305 while ((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1) { | 302 while ((iEnd = cFormat.find(cTableAd[i].lpszJSMark, iStart)) != -1) { |
306 if (iEnd > 0) { | 303 if (iEnd > 0) { |
307 if (cFormat[iEnd - 1] == L'%') { | 304 if (cFormat[iEnd - 1] == L'%') { |
308 iStart = iEnd + 1; | 305 iStart = iEnd + 1; |
309 continue; | 306 continue; |
310 } | 307 } |
311 } | 308 } |
312 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), | 309 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[i].lpszJSMark), tszValue); |
313 tszValue); | |
314 iStart = iEnd; | 310 iStart = iEnd; |
315 } | 311 } |
316 } | 312 } |
317 | 313 |
318 CFX_WideString strFormat; | 314 CFX_WideString strFormat; |
319 wchar_t buf[64] = {}; | 315 wchar_t buf[64] = {}; |
320 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 316 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
321 cFormat = buf; | 317 cFormat = buf; |
322 vRet = cFormat.c_str(); | 318 vRet = cFormat.c_str(); |
323 return TRUE; | 319 return TRUE; |
324 } | 320 } |
325 return FALSE; | 321 return FALSE; |
326 } | 322 } |
327 | 323 |
328 void util::printd(const std::wstring& cFormat2, | 324 void util::printd(const std::wstring& cFormat2, |
329 CJS_Date jsDate, | 325 CJS_Date jsDate, |
330 bool bXFAPicture, | 326 bool bXFAPicture, |
331 std::wstring& cPurpose) { | 327 std::wstring& cPurpose) { |
332 std::wstring cFormat = cFormat2; | 328 std::wstring cFormat = cFormat2; |
333 | 329 |
334 if (bXFAPicture) { | 330 if (bXFAPicture) { |
335 return; // currently, it doesn't support XFAPicture. | 331 return; // currently, it doesn't support XFAPicture. |
336 } | 332 } |
337 | 333 |
338 int iIndex; | 334 for (size_t i = 0; i < sizeof(fcTable) / sizeof(stru_TbConvert); ++i) { |
339 for (iIndex = 0; iIndex < sizeof(fcTable) / sizeof(stru_TbConvert); | |
340 iIndex++) { | |
341 int iStart = 0; | 335 int iStart = 0; |
342 int iEnd; | 336 int iEnd; |
343 while ((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1) { | 337 while ((iEnd = cFormat.find(fcTable[i].lpszJSMark, iStart)) != -1) { |
344 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), | 338 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[i].lpszJSMark), |
345 fcTable[iIndex].lpszCppMark); | 339 fcTable[i].lpszCppMark); |
346 iStart = iEnd; | 340 iStart = iEnd; |
347 } | 341 } |
348 } | 342 } |
349 | 343 |
350 int iYear, iMonth, iDay, iHour, iMin, iSec; | 344 int iYear, iMonth, iDay, iHour, iMin, iSec; |
351 iYear = jsDate.GetYear(); | 345 iYear = jsDate.GetYear(); |
352 iMonth = jsDate.GetMonth(); | 346 iMonth = jsDate.GetMonth(); |
353 iDay = jsDate.GetDay(); | 347 iDay = jsDate.GetDay(); |
354 iHour = jsDate.GetHours(); | 348 iHour = jsDate.GetHours(); |
355 iMin = jsDate.GetMinutes(); | 349 iMin = jsDate.GetMinutes(); |
(...skipping 14 matching lines...) Expand all Loading... |
370 int iValue; | 364 int iValue; |
371 }; | 365 }; |
372 | 366 |
373 stru_TbConvertAd cTableAd[] = { | 367 stru_TbConvertAd cTableAd[] = { |
374 {L"m", iMonth + 1}, {L"d", iDay}, | 368 {L"m", iMonth + 1}, {L"d", iDay}, |
375 {L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour}, | 369 {L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour}, |
376 {L"M", iMin}, {L"s", iSec}, | 370 {L"M", iMin}, {L"s", iSec}, |
377 }; | 371 }; |
378 | 372 |
379 // cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); | 373 // cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); |
380 for (iIndex = 0; iIndex < sizeof(cTableAd) / sizeof(stru_TbConvertAd); | 374 for (size_t i = 0; i < sizeof(cTableAd) / sizeof(stru_TbConvertAd); ++i) { |
381 iIndex++) { | |
382 wchar_t tszValue[10]; | 375 wchar_t tszValue[10]; |
383 //_itot(cTableAd[iIndex].iValue,tszValue,10); | |
384 CFX_WideString sValue; | 376 CFX_WideString sValue; |
385 sValue.Format(L"%d", cTableAd[iIndex].iValue); | 377 sValue.Format(L"%d", cTableAd[i].iValue); |
386 memcpy(tszValue, (wchar_t*)sValue.GetBuffer(sValue.GetLength() + 1), | 378 memcpy(tszValue, (wchar_t*)sValue.GetBuffer(sValue.GetLength() + 1), |
387 sValue.GetLength() * sizeof(wchar_t)); | 379 sValue.GetLength() * sizeof(wchar_t)); |
388 | 380 |
389 // strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); | |
390 // strFormat.Format(strFormat,cTableAd[iIndex].iValue); | |
391 int iStart = 0; | 381 int iStart = 0; |
392 int iEnd; | 382 int iEnd; |
393 while ((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1) { | 383 while ((iEnd = cFormat.find(cTableAd[i].lpszJSMark, iStart)) != -1) { |
394 if (iEnd > 0) { | 384 if (iEnd > 0) { |
395 if (cFormat[iEnd - 1] == L'%') { | 385 if (cFormat[iEnd - 1] == L'%') { |
396 iStart = iEnd + 1; | 386 iStart = iEnd + 1; |
397 continue; | 387 continue; |
398 } | 388 } |
399 } | 389 } |
400 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), | 390 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[i].lpszJSMark), tszValue); |
401 tszValue); | |
402 iStart = iEnd; | 391 iStart = iEnd; |
403 } | 392 } |
404 } | 393 } |
405 | 394 |
406 CFX_WideString strFormat; | 395 CFX_WideString strFormat; |
407 wchar_t buf[64] = {}; | 396 wchar_t buf[64] = {}; |
408 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 397 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
409 cFormat = buf; | 398 cFormat = buf; |
410 cPurpose = cFormat; | 399 cPurpose = cFormat; |
411 } | 400 } |
(...skipping 22 matching lines...) Expand all Loading... |
434 if (!cPurpose.empty()) | 423 if (!cPurpose.empty()) |
435 // cPurpose.clear(); | 424 // cPurpose.clear(); |
436 cPurpose.erase(); | 425 cPurpose.erase(); |
437 int itSource = 0; | 426 int itSource = 0; |
438 int iSize = cSource.size(); | 427 int iSize = cSource.size(); |
439 for (int iIndex = 0; iIndex < (int)cFormat.size() && itSource < iSize; | 428 for (int iIndex = 0; iIndex < (int)cFormat.size() && itSource < iSize; |
440 iIndex++) { | 429 iIndex++) { |
441 char letter = cFormat[iIndex]; | 430 char letter = cFormat[iIndex]; |
442 switch (letter) { | 431 switch (letter) { |
443 case '?': | 432 case '?': |
444 // cPurpose.push_back(cSource[itSource]); | |
445 cPurpose += cSource[itSource]; | 433 cPurpose += cSource[itSource]; |
446 itSource++; | 434 itSource++; |
447 break; | 435 break; |
448 case 'X': { | 436 case 'X': { |
449 while (itSource < iSize) { | 437 while (itSource < iSize) { |
450 if ((cSource[itSource] >= '0' && cSource[itSource] <= '9') || | 438 if ((cSource[itSource] >= '0' && cSource[itSource] <= '9') || |
451 (cSource[itSource] >= 'a' && cSource[itSource] <= 'z') || | 439 (cSource[itSource] >= 'a' && cSource[itSource] <= 'z') || |
452 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) { | 440 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) { |
453 // cPurpose.push_back(cSource[itSource]); | |
454 cPurpose += cSource[itSource]; | 441 cPurpose += cSource[itSource]; |
455 itSource++; | 442 itSource++; |
456 break; | 443 break; |
457 } | 444 } |
458 itSource++; | 445 itSource++; |
459 } | 446 } |
460 break; | 447 break; |
461 } break; | 448 } break; |
462 case 'A': { | 449 case 'A': { |
463 while (itSource < iSize) { | 450 while (itSource < iSize) { |
464 if ((cSource[itSource] >= 'a' && cSource[itSource] <= 'z') || | 451 if ((cSource[itSource] >= 'a' && cSource[itSource] <= 'z') || |
465 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) { | 452 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) { |
466 // cPurpose.push_back(cSource[itSource]); | |
467 cPurpose += cSource[itSource]; | 453 cPurpose += cSource[itSource]; |
468 itSource++; | 454 itSource++; |
469 break; | 455 break; |
470 } | 456 } |
471 itSource++; | 457 itSource++; |
472 } | 458 } |
473 break; | 459 break; |
474 } break; | 460 } break; |
475 case '9': { | 461 case '9': { |
476 while (itSource < iSize) { | 462 while (itSource < iSize) { |
477 if (cSource[itSource] >= '0' && cSource[itSource] <= '9') { | 463 if (cSource[itSource] >= '0' && cSource[itSource] <= '9') { |
478 // cPurpose.push_back(cSource[itSource]); | |
479 cPurpose += cSource[itSource]; | 464 cPurpose += cSource[itSource]; |
480 itSource++; | 465 itSource++; |
481 break; | 466 break; |
482 } | 467 } |
483 itSource++; | 468 itSource++; |
484 } | 469 } |
485 break; | 470 break; |
486 } | 471 } |
487 case '*': { | 472 case '*': { |
488 cPurpose.append(cSource, itSource, iSize - itSource); | 473 cPurpose.append(cSource, itSource, iSize - itSource); |
(...skipping 12 matching lines...) Expand all Loading... |
501 case '<': { | 486 case '<': { |
502 for (std::string::iterator it = cSource.begin(); it != cSource.end(); | 487 for (std::string::iterator it = cSource.begin(); it != cSource.end(); |
503 it++) { | 488 it++) { |
504 *it = tolower(*it); | 489 *it = tolower(*it); |
505 } | 490 } |
506 break; | 491 break; |
507 } | 492 } |
508 case '=': | 493 case '=': |
509 break; | 494 break; |
510 default: | 495 default: |
511 // cPurpose.push_back(letter); | |
512 cPurpose += letter; | 496 cPurpose += letter; |
513 break; | 497 break; |
514 } | 498 } |
515 } | 499 } |
516 } | 500 } |
517 | 501 |
518 FX_BOOL util::scand(IFXJS_Context* cc, | 502 FX_BOOL util::scand(IFXJS_Context* cc, |
519 const CJS_Parameters& params, | 503 const CJS_Parameters& params, |
520 CJS_Value& vRet, | 504 CJS_Value& vRet, |
521 CFX_WideString& sError) { | 505 CFX_WideString& sError) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 int iSize = params.size(); | 557 int iSize = params.size(); |
574 if (iSize == 0) | 558 if (iSize == 0) |
575 return FALSE; | 559 return FALSE; |
576 int nByte = params[0].ToInt(); | 560 int nByte = params[0].ToInt(); |
577 unsigned char cByte = (unsigned char)nByte; | 561 unsigned char cByte = (unsigned char)nByte; |
578 CFX_WideString csValue; | 562 CFX_WideString csValue; |
579 csValue.Format(L"%c", cByte); | 563 csValue.Format(L"%c", cByte); |
580 vRet = csValue.c_str(); | 564 vRet = csValue.c_str(); |
581 return TRUE; | 565 return TRUE; |
582 } | 566 } |
OLD | NEW |