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 <cctype> | 7 #include <cctype> |
8 #include <cwctype> | 8 #include <cwctype> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "core/include/fxcrt/fx_ext.h" | 11 #include "core/include/fxcrt/fx_ext.h" |
12 #include "core/include/fxcrt/fx_string.h" | 12 #include "core/include/fxcrt/fx_string.h" |
13 | 13 |
14 template <typename IntType, typename CharType> | 14 template <typename IntType, typename CharType> |
15 IntType FXSYS_StrToInt(const CharType* str) { | 15 IntType FXSYS_StrToInt(const CharType* str) { |
16 if (!str) | 16 if (!str) |
17 return 0; | 17 return 0; |
18 | 18 |
19 bool neg = std::numeric_limits<IntType>::is_signed && *str == '-'; | 19 // Process the sign. |
20 if (neg) | 20 bool neg = *str == '-'; |
dsinclair
2016/03/24 02:41:06
This loses the std::numeric_limits<IntType>::is_si
Wei Li
2016/03/24 17:31:25
I think eventually we may want to use std:strto? t
dsinclair
2016/03/24 18:10:11
Fair enough, think the conditional on 28 can still
Wei Li
2016/03/24 23:25:46
Done.
| |
21 if (neg || *str == '+') | |
21 str++; | 22 str++; |
22 | 23 |
23 IntType num = 0; | 24 IntType num = 0; |
24 while (*str && FXSYS_isDecimalDigit(*str)) { | 25 while (*str && FXSYS_isDecimalDigit(*str)) { |
25 IntType val = FXSYS_toDecimalDigit(*str); | 26 IntType val = FXSYS_toDecimalDigit(*str); |
26 if (num > (std::numeric_limits<IntType>::max() - val) / 10) | 27 if (num > (std::numeric_limits<IntType>::max() - val) / 10) { |
27 break; | 28 if (std::numeric_limits<IntType>::is_signed) { |
dsinclair
2016/03/24 01:40:44
I didn't make this change originally because I was
Wei Li
2016/03/24 02:27:42
I checked callers which mainly use this to process
| |
29 // Return MAX or MIN when the represented number is larger than the max | |
30 // value or smaller than the min value. | |
31 return neg ? std::numeric_limits<IntType>::min() | |
32 : std::numeric_limits<IntType>::max(); | |
33 } else { | |
34 // Return MAX when the represented number is out of range. | |
35 return std::numeric_limits<IntType>::max(); | |
dsinclair
2016/03/24 02:41:06
If you put the is_signed check back at line 20 thi
| |
36 } | |
37 } | |
28 | 38 |
29 num = num * 10 + val; | 39 num = num * 10 + val; |
30 str++; | 40 str++; |
31 } | 41 } |
32 return neg ? -num : num; | 42 return neg ? -num : num; |
33 } | 43 } |
34 | 44 |
35 template <typename T, typename UT, typename STR_T> | 45 template <typename T, typename UT, typename STR_T> |
36 STR_T FXSYS_IntToStr(T value, STR_T str, int radix) { | 46 STR_T FXSYS_IntToStr(T value, STR_T str, int radix) { |
37 if (radix < 2 || radix > 16) { | 47 if (radix < 2 || radix > 16) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 buf[wlen] = bstr[i]; | 243 buf[wlen] = bstr[i]; |
234 } | 244 } |
235 wlen++; | 245 wlen++; |
236 } | 246 } |
237 return wlen; | 247 return wlen; |
238 } | 248 } |
239 #ifdef __cplusplus | 249 #ifdef __cplusplus |
240 } | 250 } |
241 #endif | 251 #endif |
242 #endif | 252 #endif |
OLD | NEW |