1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
8 #include "../../include/fxcrt/fx_ext.h"
9 template <class T, class STR_T>
10 T FXSYS_StrToInt(STR_T str)
22 if ((*str) < '0' || (*str) > '9') {
25 if (num > (std::numeric_limits<T>::max() - 9) / 10) {
28 num = num * 10 + (*str) - '0';
31 return neg ? -num : num;
33 template <typename T, typename STR_T>
34 STR_T FXSYS_IntToStr(T value, STR_T string, int radix)
40 } else if (value == 0) {
51 for (int d = digits - 1; d > -1; d--) {
52 string[d + i] = "0123456789abcdef"[value % 10];
55 string[digits + i] = 0;
61 FX_INT32 FXSYS_atoi(FX_LPCSTR str)
63 return FXSYS_StrToInt<FX_INT32, FX_LPCSTR>(str);
65 FX_INT32 FXSYS_wtoi(FX_LPCWSTR str)
67 return FXSYS_StrToInt<FX_INT32, FX_LPCWSTR>(str);
69 FX_INT64 FXSYS_atoi64(FX_LPCSTR str)
71 return FXSYS_StrToInt<FX_INT64, FX_LPCSTR>(str);
73 FX_INT64 FXSYS_wtoi64(FX_LPCWSTR str)
75 return FXSYS_StrToInt<FX_INT64, FX_LPCWSTR>(str);
77 FX_LPCSTR FXSYS_i64toa(FX_INT64 value, FX_LPSTR str, int radix)
79 return FXSYS_IntToStr<FX_INT64, FX_LPSTR>(value, str, radix);
81 FX_LPCWSTR FXSYS_i64tow(FX_INT64 value, FX_LPWSTR str, int radix)
83 return FXSYS_IntToStr<FX_INT64, FX_LPWSTR>(value, str, radix);
88 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
96 FX_DWORD FXSYS_GetFullPathName(FX_LPCSTR filename, FX_DWORD buflen, FX_LPSTR buf, FX_LPSTR* filepart)
98 int srclen = FXSYS_strlen(filename);
99 if (buf == NULL || (int)buflen < srclen + 1) {
102 FXSYS_strcpy(buf, filename);
105 FX_DWORD FXSYS_GetModuleFileName(FX_LPVOID hModule, char* buf, FX_DWORD bufsize)
107 return (FX_DWORD) - 1;
113 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
117 FXSYS_FILE* FXSYS_wfopen(FX_LPCWSTR filename, FX_LPCWSTR mode)
119 return FXSYS_fopen(CFX_ByteString::FromUnicode(filename), CFX_ByteString::FromUnicode(mode));
121 char* FXSYS_strlwr(char* str)
128 *str = FXSYS_tolower(*str);
133 char* FXSYS_strupr(char* str)
140 *str = FXSYS_toupper(*str);
145 FX_WCHAR* FXSYS_wcslwr(FX_WCHAR* str)
152 *str = FXSYS_tolower(*str);
157 FX_WCHAR* FXSYS_wcsupr(FX_WCHAR* str)
164 *str = FXSYS_toupper(*str);
169 int FXSYS_stricmp(const char*dst, const char*src)
173 if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') ) {
176 if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') ) {
179 } while ( f && (f == l) );
182 int FXSYS_wcsicmp(const FX_WCHAR *dst, const FX_WCHAR *src)
186 if ( ((f = (FX_WCHAR)(*(dst++))) >= 'A') && (f <= 'Z') ) {
189 if ( ((l = (FX_WCHAR)(*(src++))) >= 'A') && (l <= 'Z') ) {
192 } while ( f && (f == l) );
195 char* FXSYS_itoa(int value, char* string, int radix)
197 return FXSYS_IntToStr<FX_INT32, FX_LPSTR>(value, string, radix);
203 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
207 int FXSYS_WideCharToMultiByte(FX_DWORD codepage, FX_DWORD dwFlags, FX_LPCWSTR wstr, int wlen,
208 FX_LPSTR buf, int buflen, FX_LPCSTR default_str, FX_BOOL* pUseDefault)
211 for (int i = 0; i < wlen; i ++) {
212 if (wstr[i] < 0x100) {
213 if (buf && len < buflen) {
214 buf[len] = (FX_CHAR)wstr[i];
221 int FXSYS_MultiByteToWideChar(FX_DWORD codepage, FX_DWORD dwFlags, FX_LPCSTR bstr, int blen,
222 FX_LPWSTR buf, int buflen)
225 for (int i = 0; i < blen; i ++) {
226 if (buf && wlen < buflen) {