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

Side by Side Diff: fpdfsdk/src/javascript/PublicMethods.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/fsdk_baseannot.cpp ('k') | fpdfsdk/src/javascript/util.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "PublicMethods.h" 7 #include "PublicMethods.h"
8 8
9 #include "Field.h" 9 #include "Field.h"
10 #include "JS_Context.h" 10 #include "JS_Context.h"
11 #include "JS_Define.h" 11 #include "JS_Define.h"
12 #include "JS_EventHandler.h" 12 #include "JS_EventHandler.h"
13 #include "JS_Object.h" 13 #include "JS_Object.h"
14 #include "JS_Runtime.h" 14 #include "JS_Runtime.h"
15 #include "JS_Value.h" 15 #include "JS_Value.h"
16 #include "color.h" 16 #include "color.h"
17 #include "core/include/fxcrt/fx_ext.h"
17 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. 18 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment.
18 #include "fpdfsdk/include/javascript/IJavaScript.h" 19 #include "fpdfsdk/include/javascript/IJavaScript.h"
19 #include "resource.h" 20 #include "resource.h"
20 #include "util.h" 21 #include "util.h"
21 22
22 #define DOUBLE_CORRECT 0.000000000000001 23 #define DOUBLE_CORRECT 0.000000000000001
23 24
24 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) 25 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
25 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) 26 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format)
26 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) 27 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 110 }
110 111
111 return TRUE; 112 return TRUE;
112 } 113 }
113 114
114 FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) { 115 FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) {
115 return (ch >= L'0' && ch <= L'9'); 116 return (ch >= L'0' && ch <= L'9');
116 } 117 }
117 118
118 FX_BOOL CJS_PublicMethods::IsDigit(char ch) { 119 FX_BOOL CJS_PublicMethods::IsDigit(char ch) {
119 return (ch >= '0' && ch <= '9'); 120 return std::isdigit(ch);
120 } 121 }
121 122
122 FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) { 123 FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) {
123 return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z')); 124 return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
124 } 125 }
125 126
126 FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch) { 127 FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch) {
127 return (IsDigit(ch) || IsAlphabetic(ch)); 128 return (IsDigit(ch) || IsAlphabetic(ch));
128 } 129 }
129 130
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 int& nSkip, 390 int& nSkip,
390 int nMaxStep) { 391 int nMaxStep) {
391 int nRet = 0; 392 int nRet = 0;
392 nSkip = 0; 393 nSkip = 0;
393 for (int i = nStart, sz = string.GetLength(); i < sz; i++) { 394 for (int i = nStart, sz = string.GetLength(); i < sz; i++) {
394 if (i - nStart > 10) 395 if (i - nStart > 10)
395 break; 396 break;
396 397
397 FX_WCHAR c = string.GetAt(i); 398 FX_WCHAR c = string.GetAt(i);
398 if (IsDigit((wchar_t)c)) { 399 if (IsDigit((wchar_t)c)) {
399 nRet = nRet * 10 + (c - '0'); 400 nRet = nRet * 10 + FXSYS_toDecimalDigitWide(c);
400 nSkip = i - nStart + 1; 401 nSkip = i - nStart + 1;
401 if (nSkip >= nMaxStep) 402 if (nSkip >= nMaxStep)
402 break; 403 break;
403 } else 404 } else
404 break; 405 break;
405 } 406 }
406 407
407 return nRet; 408 return nRet;
408 } 409 }
409 410
(...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); 2090 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
2090 } 2091 }
2091 2092
2092 if (nums.GetLength() > 0) 2093 if (nums.GetLength() > 0)
2093 vRet = nums; 2094 vRet = nums;
2094 else 2095 else
2095 vRet.SetNull(); 2096 vRet.SetNull();
2096 2097
2097 return TRUE; 2098 return TRUE;
2098 } 2099 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fsdk_baseannot.cpp ('k') | fpdfsdk/src/javascript/util.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698