Chromium Code Reviews| 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 T num = 0; |
| 20 T num_new = 0; | |
| 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 = num * 10 + (*str) - '0'; |
| 26 if (num_new < 0) { | |
| 27 break; | |
|
Bo Xu
2014/09/19 21:48:19
Now check when the string is too long and overflow
Tom Sepez
2014/09/19 22:15:38
This can't work, either T is a signed type in whic
Bo Xu
2014/09/19 22:28:15
Done.
| |
| 28 } | |
| 29 num = num_new; | |
| 25 str ++; | 30 str ++; |
| 26 } | 31 } |
| 27 return neg ? -num : num; | 32 return neg ? -num : num; |
| 28 } | 33 } |
| 29 template <typename T, typename STR_T> | 34 template <typename T, typename STR_T> |
| 30 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) | 35 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) |
| 31 { | 36 { |
| 32 int i = 0; | 37 int i = 0; |
| 33 if (value < 0) { | 38 if (value < 0) { |
| 34 string[i++] = '-'; | 39 string[i++] = '-'; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 buf[wlen] = bstr[i]; | 228 buf[wlen] = bstr[i]; |
| 224 } | 229 } |
| 225 wlen ++; | 230 wlen ++; |
| 226 } | 231 } |
| 227 return wlen; | 232 return wlen; |
| 228 } | 233 } |
| 229 #ifdef __cplusplus | 234 #ifdef __cplusplus |
| 230 } | 235 } |
| 231 #endif | 236 #endif |
| 232 #endif | 237 #endif |
| OLD | NEW |