| 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 <limits> | 7 #include <limits> |
| 8 #include <cctype> |
| 8 | 9 |
| 9 #include "../../include/fxcrt/fx_ext.h" | 10 #include "../../include/fxcrt/fx_ext.h" |
| 10 #include "../../include/fxcrt/fx_string.h" | 11 #include "../../include/fxcrt/fx_string.h" |
| 11 | 12 |
| 12 template <class T, class STR_T> | 13 template <class T, class STR_T> |
| 13 T FXSYS_StrToInt(STR_T str) { | 14 T FXSYS_StrToInt(STR_T str) { |
| 14 FX_BOOL neg = FALSE; | 15 FX_BOOL neg = FALSE; |
| 15 if (str == NULL) { | 16 if (!str) |
| 16 return 0; | 17 return 0; |
| 17 } | 18 |
| 18 if (*str == '-') { | 19 if (*str == '-') { |
| 19 neg = TRUE; | 20 neg = TRUE; |
| 20 str++; | 21 str++; |
| 21 } | 22 } |
| 22 T num = 0; | 23 T num = 0; |
| 23 while (*str) { | 24 while (*str && std::isdigit(*str)) { |
| 24 if ((*str) < '0' || (*str) > '9') { | 25 if (num > (std::numeric_limits<T>::max() - 9) / 10) |
| 25 break; | 26 break; |
| 26 } | 27 |
| 27 if (num > (std::numeric_limits<T>::max() - 9) / 10) { | 28 num = num * 10 + FXSYS_toDecimalDigit(*str); |
| 28 break; | |
| 29 } | |
| 30 num = num * 10 + (*str) - '0'; | |
| 31 str++; | 29 str++; |
| 32 } | 30 } |
| 33 return neg ? -num : num; | 31 return neg ? -num : num; |
| 34 } | 32 } |
| 35 | 33 |
| 36 template <typename T, typename UT, typename STR_T> | 34 template <typename T, typename UT, typename STR_T> |
| 37 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) { | 35 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) { |
| 38 if (radix < 2 || radix > 16) { | 36 if (radix < 2 || radix > 16) { |
| 39 string[0] = 0; | 37 string[0] = 0; |
| 40 return string; | 38 return string; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 buf[wlen] = bstr[i]; | 229 buf[wlen] = bstr[i]; |
| 232 } | 230 } |
| 233 wlen++; | 231 wlen++; |
| 234 } | 232 } |
| 235 return wlen; | 233 return wlen; |
| 236 } | 234 } |
| 237 #ifdef __cplusplus | 235 #ifdef __cplusplus |
| 238 } | 236 } |
| 239 #endif | 237 #endif |
| 240 #endif | 238 #endif |
| OLD | NEW |