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 |
(...skipping 21 matching lines...) Expand all Loading... |
32 } else { | 32 } else { |
33 // Return MAX when the represented number is signed type and is larger | 33 // Return MAX when the represented number is signed type and is larger |
34 // than the max value, or the number is unsigned type and out of range. | 34 // than the max value, or the number is unsigned type and out of range. |
35 return std::numeric_limits<IntType>::max(); | 35 return std::numeric_limits<IntType>::max(); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 num = num * 10 + val; | 39 num = num * 10 + val; |
40 str++; | 40 str++; |
41 } | 41 } |
42 return neg ? -num : num; | 42 // When it is a negative value, -num should be returned. Since num may be of |
| 43 // unsigned type, use ~num + 1 to avoid the warning of applying unary minus |
| 44 // operator to unsigned type. |
| 45 return neg ? ~num + 1 : num; |
43 } | 46 } |
44 | 47 |
45 template <typename T, typename UT, typename STR_T> | 48 template <typename T, typename UT, typename STR_T> |
46 STR_T FXSYS_IntToStr(T value, STR_T str, int radix) { | 49 STR_T FXSYS_IntToStr(T value, STR_T str, int radix) { |
47 if (radix < 2 || radix > 16) { | 50 if (radix < 2 || radix > 16) { |
48 str[0] = 0; | 51 str[0] = 0; |
49 return str; | 52 return str; |
50 } | 53 } |
51 if (value == 0) { | 54 if (value == 0) { |
52 str[0] = '0'; | 55 str[0] = '0'; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 buf[wlen] = bstr[i]; | 246 buf[wlen] = bstr[i]; |
244 } | 247 } |
245 wlen++; | 248 wlen++; |
246 } | 249 } |
247 return wlen; | 250 return wlen; |
248 } | 251 } |
249 #ifdef __cplusplus | 252 #ifdef __cplusplus |
250 } | 253 } |
251 #endif | 254 #endif |
252 #endif | 255 #endif |
OLD | NEW |