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 15 matching lines...) Expand all Loading... |
26 if (num > (std::numeric_limits<IntType>::max() - val) / 10) | 26 if (num > (std::numeric_limits<IntType>::max() - val) / 10) |
27 break; | 27 break; |
28 | 28 |
29 num = num * 10 + val; | 29 num = num * 10 + val; |
30 str++; | 30 str++; |
31 } | 31 } |
32 return neg ? -num : num; | 32 return neg ? -num : num; |
33 } | 33 } |
34 | 34 |
35 template <typename T, typename UT, typename STR_T> | 35 template <typename T, typename UT, typename STR_T> |
36 STR_T FXSYS_IntToStr(T value, STR_T string, int radix) { | 36 STR_T FXSYS_IntToStr(T value, STR_T str, int radix) { |
37 if (radix < 2 || radix > 16) { | 37 if (radix < 2 || radix > 16) { |
38 string[0] = 0; | 38 str[0] = 0; |
39 return string; | 39 return str; |
40 } | 40 } |
41 if (value == 0) { | 41 if (value == 0) { |
42 string[0] = '0'; | 42 str[0] = '0'; |
43 string[1] = 0; | 43 str[1] = 0; |
44 return string; | 44 return str; |
45 } | 45 } |
46 int i = 0; | 46 int i = 0; |
47 UT uvalue; | 47 UT uvalue; |
48 if (value < 0) { | 48 if (value < 0) { |
49 string[i++] = '-'; | 49 str[i++] = '-'; |
50 // Standard trick to avoid undefined behaviour when negating INT_MIN. | 50 // Standard trick to avoid undefined behaviour when negating INT_MIN. |
51 uvalue = static_cast<UT>(-(value + 1)) + 1; | 51 uvalue = static_cast<UT>(-(value + 1)) + 1; |
52 } else { | 52 } else { |
53 uvalue = value; | 53 uvalue = value; |
54 } | 54 } |
55 int digits = 1; | 55 int digits = 1; |
56 T order = uvalue / radix; | 56 T order = uvalue / radix; |
57 while (order > 0) { | 57 while (order > 0) { |
58 digits++; | 58 digits++; |
59 order = order / radix; | 59 order = order / radix; |
60 } | 60 } |
61 for (int d = digits - 1; d > -1; d--) { | 61 for (int d = digits - 1; d > -1; d--) { |
62 string[d + i] = "0123456789abcdef"[uvalue % radix]; | 62 str[d + i] = "0123456789abcdef"[uvalue % radix]; |
63 uvalue /= radix; | 63 uvalue /= radix; |
64 } | 64 } |
65 string[digits + i] = 0; | 65 str[digits + i] = 0; |
66 return string; | 66 return str; |
67 } | 67 } |
68 | 68 |
69 #ifdef __cplusplus | 69 #ifdef __cplusplus |
70 extern "C" { | 70 extern "C" { |
71 #endif | 71 #endif |
72 int32_t FXSYS_atoi(const FX_CHAR* str) { | 72 int32_t FXSYS_atoi(const FX_CHAR* str) { |
73 return FXSYS_StrToInt<int32_t, FX_CHAR>(str); | 73 return FXSYS_StrToInt<int32_t, FX_CHAR>(str); |
74 } | 74 } |
75 uint32_t FXSYS_atoui(const FX_CHAR* str) { | 75 uint32_t FXSYS_atoui(const FX_CHAR* str) { |
76 return FXSYS_StrToInt<uint32_t>(str); | 76 return FXSYS_StrToInt<uint32_t>(str); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 do { | 184 do { |
185 if (((f = (FX_WCHAR)(*(dst++))) >= 'A') && (f <= 'Z')) { | 185 if (((f = (FX_WCHAR)(*(dst++))) >= 'A') && (f <= 'Z')) { |
186 f -= ('A' - 'a'); | 186 f -= ('A' - 'a'); |
187 } | 187 } |
188 if (((l = (FX_WCHAR)(*(src++))) >= 'A') && (l <= 'Z')) { | 188 if (((l = (FX_WCHAR)(*(src++))) >= 'A') && (l <= 'Z')) { |
189 l -= ('A' - 'a'); | 189 l -= ('A' - 'a'); |
190 } | 190 } |
191 } while (f && (f == l)); | 191 } while (f && (f == l)); |
192 return (f - l); | 192 return (f - l); |
193 } | 193 } |
194 char* FXSYS_itoa(int value, char* string, int radix) { | 194 char* FXSYS_itoa(int value, char* str, int radix) { |
195 return FXSYS_IntToStr<int32_t, uint32_t, FX_CHAR*>(value, string, radix); | 195 return FXSYS_IntToStr<int32_t, uint32_t, FX_CHAR*>(value, str, radix); |
196 } | 196 } |
197 #ifdef __cplusplus | 197 #ifdef __cplusplus |
198 } | 198 } |
199 #endif | 199 #endif |
200 #endif | 200 #endif |
201 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 201 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
202 #ifdef __cplusplus | 202 #ifdef __cplusplus |
203 extern "C" { | 203 extern "C" { |
204 #endif | 204 #endif |
205 int FXSYS_WideCharToMultiByte(FX_DWORD codepage, | 205 int FXSYS_WideCharToMultiByte(FX_DWORD codepage, |
(...skipping 27 matching lines...) Expand all Loading... |
233 buf[wlen] = bstr[i]; | 233 buf[wlen] = bstr[i]; |
234 } | 234 } |
235 wlen++; | 235 wlen++; |
236 } | 236 } |
237 return wlen; | 237 return wlen; |
238 } | 238 } |
239 #ifdef __cplusplus | 239 #ifdef __cplusplus |
240 } | 240 } |
241 #endif | 241 #endif |
242 #endif | 242 #endif |
OLD | NEW |