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
7 #include "../../include/fxcrt/fx_ext.h"
8 template <class T, class STR_T>
9 T FXSYS_StrToInt(STR_T str)
21 if ((*str) < '0' || (*str) > '9') {
24 num = num * 10 + (*str) - '0';
27 return neg ? -num : num;
29 template <typename T, typename STR_T>
30 STR_T FXSYS_IntToStr(T value, STR_T string, int radix)
36 } else if (value == 0) {
47 for (int d = digits - 1; d > -1; d--) {
48 string[d + i] = "0123456789abcdef"[value % 10];
51 string[digits + i] = 0;
57 FX_INT32 FXSYS_atoi(FX_LPCSTR str)
59 return FXSYS_StrToInt<FX_INT32, FX_LPCSTR>(str);
61 FX_INT32 FXSYS_wtoi(FX_LPCWSTR str)
63 return FXSYS_StrToInt<FX_INT32, FX_LPCWSTR>(str);
65 FX_INT64 FXSYS_atoi64(FX_LPCSTR str)
67 return FXSYS_StrToInt<FX_INT64, FX_LPCSTR>(str);
69 FX_INT64 FXSYS_wtoi64(FX_LPCWSTR str)
71 return FXSYS_StrToInt<FX_INT64, FX_LPCWSTR>(str);
73 FX_LPCSTR FXSYS_i64toa(FX_INT64 value, FX_LPSTR str, int radix)
75 return FXSYS_IntToStr<FX_INT64, FX_LPSTR>(value, str, radix);
77 FX_LPCWSTR FXSYS_i64tow(FX_INT64 value, FX_LPWSTR str, int radix)
79 return FXSYS_IntToStr<FX_INT64, FX_LPWSTR>(value, str, radix);
84 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
92 FX_DWORD FXSYS_GetFullPathName(FX_LPCSTR filename, FX_DWORD buflen, FX_LPSTR buf, FX_LPSTR* filepart)
94 int srclen = FXSYS_strlen(filename);
95 if (buf == NULL || (int)buflen < srclen + 1) {
98 FXSYS_strcpy(buf, filename);
101 FX_DWORD FXSYS_GetModuleFileName(FX_LPVOID hModule, char* buf, FX_DWORD bufsize)
103 return (FX_DWORD) - 1;
109 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
113 FXSYS_FILE* FXSYS_wfopen(FX_LPCWSTR filename, FX_LPCWSTR mode)
115 return FXSYS_fopen(CFX_ByteString::FromUnicode(filename), CFX_ByteString::FromUnicode(mode));
117 char* FXSYS_strlwr(char* str)
124 *str = FXSYS_tolower(*str);
129 char* FXSYS_strupr(char* str)
136 *str = FXSYS_toupper(*str);
141 FX_WCHAR* FXSYS_wcslwr(FX_WCHAR* str)
148 *str = FXSYS_tolower(*str);
153 FX_WCHAR* FXSYS_wcsupr(FX_WCHAR* str)
160 *str = FXSYS_toupper(*str);
165 int FXSYS_stricmp(const char*dst, const char*src)
169 if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') ) {
172 if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') ) {
175 } while ( f && (f == l) );
178 int FXSYS_wcsicmp(const FX_WCHAR *dst, const FX_WCHAR *src)
182 if ( ((f = (FX_WCHAR)(*(dst++))) >= 'A') && (f <= 'Z') ) {
185 if ( ((l = (FX_WCHAR)(*(src++))) >= 'A') && (l <= 'Z') ) {
188 } while ( f && (f == l) );
191 char* FXSYS_itoa(int value, char* string, int radix)
193 return FXSYS_IntToStr<FX_INT32, FX_LPSTR>(value, string, radix);
199 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
203 int FXSYS_WideCharToMultiByte(FX_DWORD codepage, FX_DWORD dwFlags, FX_LPCWSTR wstr, int wlen,
204 FX_LPSTR buf, int buflen, FX_LPCSTR default_str, FX_BOOL* pUseDefault)
207 for (int i = 0; i < wlen; i ++) {
208 if (wstr[i] < 0x100) {
209 if (buf && len < buflen) {
210 buf[len] = (FX_CHAR)wstr[i];
217 int FXSYS_MultiByteToWideChar(FX_DWORD codepage, FX_DWORD dwFlags, FX_LPCSTR bstr, int blen,
218 FX_LPWSTR buf, int buflen)
221 for (int i = 0; i < blen; i ++) {
222 if (buf && wlen < buflen) {