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

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

Issue 1449873003: Reland "Cleanup some numeric code."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix windows build Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/PublicMethods.cpp ('k') | pdfium.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "util.h" 7 #include "util.h"
8 8
9 #include "JS_Context.h" 9 #include "JS_Context.h"
10 #include "JS_Define.h" 10 #include "JS_Define.h"
11 #include "JS_EventHandler.h" 11 #include "JS_EventHandler.h"
12 #include "JS_Object.h" 12 #include "JS_Object.h"
13 #include "JS_Runtime.h" 13 #include "JS_Runtime.h"
14 #include "JS_Value.h" 14 #include "JS_Value.h"
15 #include "PublicMethods.h" 15 #include "PublicMethods.h"
16 #include "core/include/fxcrt/fx_ext.h"
16 #include "fpdfsdk/include/javascript/IJavaScript.h" 17 #include "fpdfsdk/include/javascript/IJavaScript.h"
17 #include "resource.h" 18 #include "resource.h"
18 19
19 #if _FX_OS_ == _FX_ANDROID_ 20 #if _FX_OS_ == _FX_ANDROID_
20 #include <ctype.h> 21 #include <ctype.h>
21 #endif 22 #endif
22 23
23 BEGIN_JS_STATIC_CONST(CJS_Util) 24 BEGIN_JS_STATIC_CONST(CJS_Util)
24 END_JS_STATIC_CONST() 25 END_JS_STATIC_CONST()
25 26
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 for (int iIndex = 0; iIndex < (int)cFormat.size() && itSource < iSize; 419 for (int iIndex = 0; iIndex < (int)cFormat.size() && itSource < iSize;
419 iIndex++) { 420 iIndex++) {
420 char letter = cFormat[iIndex]; 421 char letter = cFormat[iIndex];
421 switch (letter) { 422 switch (letter) {
422 case '?': 423 case '?':
423 cPurpose += cSource[itSource]; 424 cPurpose += cSource[itSource];
424 itSource++; 425 itSource++;
425 break; 426 break;
426 case 'X': { 427 case 'X': {
427 while (itSource < iSize) { 428 while (itSource < iSize) {
428 if ((cSource[itSource] >= '0' && cSource[itSource] <= '9') || 429 if (std::isdigit(cSource[itSource]) ||
429 (cSource[itSource] >= 'a' && cSource[itSource] <= 'z') || 430 (cSource[itSource] >= 'a' && cSource[itSource] <= 'z') ||
430 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) { 431 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) {
431 cPurpose += cSource[itSource]; 432 cPurpose += cSource[itSource];
432 itSource++; 433 itSource++;
433 break; 434 break;
434 } 435 }
435 itSource++; 436 itSource++;
436 } 437 }
437 break; 438 break;
438 } break; 439 } break;
439 case 'A': { 440 case 'A': {
440 while (itSource < iSize) { 441 while (itSource < iSize) {
441 if ((cSource[itSource] >= 'a' && cSource[itSource] <= 'z') || 442 if ((cSource[itSource] >= 'a' && cSource[itSource] <= 'z') ||
442 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) { 443 (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) {
443 cPurpose += cSource[itSource]; 444 cPurpose += cSource[itSource];
444 itSource++; 445 itSource++;
445 break; 446 break;
446 } 447 }
447 itSource++; 448 itSource++;
448 } 449 }
449 break; 450 break;
450 } break; 451 } break;
451 case '9': { 452 case '9': {
452 while (itSource < iSize) { 453 while (itSource < iSize) {
453 if (cSource[itSource] >= '0' && cSource[itSource] <= '9') { 454 if (std::isdigit(cSource[itSource])) {
454 cPurpose += cSource[itSource]; 455 cPurpose += cSource[itSource];
455 itSource++; 456 itSource++;
456 break; 457 break;
457 } 458 }
458 itSource++; 459 itSource++;
459 } 460 }
460 break; 461 break;
461 } 462 }
462 case '*': { 463 case '*': {
463 cPurpose.append(cSource, itSource, iSize - itSource); 464 cPurpose.append(cSource, itSource, iSize - itSource);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 ++nptr; 525 ++nptr;
525 526
526 c = (int)(unsigned char)*nptr++; 527 c = (int)(unsigned char)*nptr++;
527 sign = c; /* save sign indication */ 528 sign = c; /* save sign indication */
528 if (c == '-' || c == '+') 529 if (c == '-' || c == '+')
529 c = (int)(unsigned char)*nptr++; /* skip sign */ 530 c = (int)(unsigned char)*nptr++; /* skip sign */
530 531
531 total = 0; 532 total = 0;
532 533
533 while (isdigit(c)) { 534 while (isdigit(c)) {
534 total = 10 * total + (c - '0'); /* accumulate digit */ 535 total = 10 * total + FXSYS_toDecimalDigit(c); /* accumulate digit */
535 c = (int)(unsigned char)*nptr++; /* get next char */ 536 c = (int)(unsigned char)*nptr++; /* get next char */
536 } 537 }
537 538
538 return sign == '-' ? -total : total; 539 return sign == '-' ? -total : total;
539 } 540 }
540 541
541 FX_BOOL util::byteToChar(IJS_Context* cc, 542 FX_BOOL util::byteToChar(IJS_Context* cc,
542 const std::vector<CJS_Value>& params, 543 const std::vector<CJS_Value>& params,
543 CJS_Value& vRet, 544 CJS_Value& vRet,
544 CFX_WideString& sError) { 545 CFX_WideString& sError) {
545 int iSize = params.size(); 546 int iSize = params.size();
546 if (iSize == 0) 547 if (iSize == 0)
547 return FALSE; 548 return FALSE;
548 int nByte = params[0].ToInt(); 549 int nByte = params[0].ToInt();
549 unsigned char cByte = (unsigned char)nByte; 550 unsigned char cByte = (unsigned char)nByte;
550 CFX_WideString csValue; 551 CFX_WideString csValue;
551 csValue.Format(L"%c", cByte); 552 csValue.Format(L"%c", cByte);
552 vRet = csValue.c_str(); 553 vRet = csValue.c_str();
553 return TRUE; 554 return TRUE;
554 } 555 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/PublicMethods.cpp ('k') | pdfium.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698