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/fxcrt/fx_ext.h" | 7 #include "../../include/fxcrt/fx_ext.h" |
8 template <class T, class STR_T> | 8 template <class T, class STR_T> |
9 T FXSYS_StrToInt(STR_T str) | 9 T FXSYS_StrToInt(STR_T str) |
10 { | 10 { |
11 FX_BOOL neg = FALSE; | 11 FX_BOOL neg = FALSE; |
12 if (str == NULL) { | 12 if (str == NULL) { |
13 return 0; | 13 return 0; |
14 } | 14 } |
15 if (*str == '-') { | 15 if (*str == '-') { |
16 neg = TRUE; | 16 neg = TRUE; |
17 str ++; | 17 str ++; |
18 } | 18 } |
19 T num = 0; | 19 base::CheckedNumeric<T> num = 0; |
Tom Sepez
2014/09/19 22:35:07
num doesn't need to be checked.
| |
20 base::CheckedNumeric<T> num_new = num; | |
Tom Sepez
2014/09/19 22:35:07
maybe this moves to right before line 25, and its
| |
20 while (*str) { | 21 while (*str) { |
21 if ((*str) < '0' || (*str) > '9') { | 22 if ((*str) < '0' || (*str) > '9') { |
22 break; | 23 break; |
23 } | 24 } |
24 num = num * 10 + (*str) - '0'; | 25 num_new *= 10; |
26 num_new += (*str) - '0'; | |
27 if (!num_new.IsValid()) { | |
28 break; | |
29 } | |
30 num = num_new; | |
Tom Sepez
2014/09/19 22:35:07
num = new_num.ValueOrDie();
| |
25 str ++; | 31 str ++; |
26 } | 32 } |
27 return neg ? -num : num; | 33 return neg ? -num.ValueOrDie() : num.ValueOrDie(); |
28 } | 34 } |
29 template <typename T, typename STR_T> | 35 template <typename T, typename STR_T> |
30 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) | 36 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) |
31 { | 37 { |
32 int i = 0; | 38 int i = 0; |
33 if (value < 0) { | 39 if (value < 0) { |
34 string[i++] = '-'; | 40 string[i++] = '-'; |
35 value = -value; | 41 value = -value; |
36 } else if (value == 0) { | 42 } else if (value == 0) { |
37 string[0] = '0'; | 43 string[0] = '0'; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 buf[wlen] = bstr[i]; | 229 buf[wlen] = bstr[i]; |
224 } | 230 } |
225 wlen ++; | 231 wlen ++; |
226 } | 232 } |
227 return wlen; | 233 return wlen; |
228 } | 234 } |
229 #ifdef __cplusplus | 235 #ifdef __cplusplus |
230 } | 236 } |
231 #endif | 237 #endif |
232 #endif | 238 #endif |
OLD | NEW |