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

Side by Side Diff: core/src/fxcrt/fx_basic_gcc.cpp

Issue 1431683008: Revert "Revert "Revert "Cleanup some numeric code.""" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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 | « core/src/fxcrt/fx_basic_bstring.cpp ('k') | core/src/fxcrt/fx_basic_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 <limits> 7 #include <limits>
8 #include <cctype>
9 8
10 #include "../../include/fxcrt/fx_ext.h" 9 #include "../../include/fxcrt/fx_ext.h"
11 #include "../../include/fxcrt/fx_string.h" 10 #include "../../include/fxcrt/fx_string.h"
12 11
13 template <class T, class STR_T> 12 template <class T, class STR_T>
14 T FXSYS_StrToInt(STR_T str) { 13 T FXSYS_StrToInt(STR_T str) {
15 FX_BOOL neg = FALSE; 14 FX_BOOL neg = FALSE;
16 if (!str) 15 if (str == NULL) {
17 return 0; 16 return 0;
18 17 }
19 if (*str == '-') { 18 if (*str == '-') {
20 neg = TRUE; 19 neg = TRUE;
21 str++; 20 str++;
22 } 21 }
23 T num = 0; 22 T num = 0;
24 while (*str && std::isdigit(*str)) { 23 while (*str) {
25 if (num > (std::numeric_limits<T>::max() - 9) / 10) 24 if ((*str) < '0' || (*str) > '9') {
26 break; 25 break;
27 26 }
28 num = num * 10 + FXSYS_toDecimalDigit(*str); 27 if (num > (std::numeric_limits<T>::max() - 9) / 10) {
28 break;
29 }
30 num = num * 10 + (*str) - '0';
29 str++; 31 str++;
30 } 32 }
31 return neg ? -num : num; 33 return neg ? -num : num;
32 } 34 }
33 35
34 template <typename T, typename UT, typename STR_T> 36 template <typename T, typename UT, typename STR_T>
35 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) { 37 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) {
36 if (radix < 2 || radix > 16) { 38 if (radix < 2 || radix > 16) {
37 string[0] = 0; 39 string[0] = 0;
38 return string; 40 return string;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 buf[wlen] = bstr[i]; 231 buf[wlen] = bstr[i];
230 } 232 }
231 wlen++; 233 wlen++;
232 } 234 }
233 return wlen; 235 return wlen;
234 } 236 }
235 #ifdef __cplusplus 237 #ifdef __cplusplus
236 } 238 }
237 #endif 239 #endif
238 #endif 240 #endif
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_bstring.cpp ('k') | core/src/fxcrt/fx_basic_util.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698