7#include "core/fxcrt/fx_system.h"
13#include "build/build_config.h"
14#include "core/fxcrt/compiler_specific.h"
15#include "core/fxcrt/fx_extension.h"
20uint32_t g_last_error = 0;
23template <
typename IntType,
typename CharType>
24IntType FXSYS_StrToInt(
const CharType* str) {
29 bool neg = *str ==
'-';
30 if (neg || *str ==
'+') {
39 while (*str && FXSYS_IsDecimalDigit(*str)) {
40 IntType val = FXSYS_DecimalCharToInt(*str);
41 if (num > (
std::numeric_limits<IntType>::max() - val) / 10) {
42 if (neg &&
std::numeric_limits<IntType>::is_signed) {
45 return std::numeric_limits<IntType>::min();
49 return std::numeric_limits<IntType>::max();
61 return neg ? ~num + 1 : num;
64template <
typename T,
typename UT,
typename STR_T>
65STR_T FXSYS_IntToStr(T value, STR_T str,
int radix) {
66 if (radix < 2 || radix > 16) {
80 uvalue =
static_cast<UT>(-(value + 1)) + 1;
85 T order = uvalue / radix;
88 order = order / radix;
90 for (
int d = digits - 1; d > -1; d--) {
91 UNSAFE_TODO(str[d + i] =
"0123456789abcdef"[uvalue % radix]);
103 if (f <
static_cast<
float>(
std::numeric_limits<
int>::min()))
104 return std::numeric_limits<
int>::min();
105 if (f >=
static_cast<
float>(
std::numeric_limits<
int>::max()))
106 return std::numeric_limits<
int>::max();
107 return static_cast<
int>(round(f));
113 if (d <
static_cast<
double>(
std::numeric_limits<
int>::min()))
114 return std::numeric_limits<
int>::min();
115 if (d >=
static_cast<
double>(
std::numeric_limits<
int>::max()))
116 return std::numeric_limits<
int>::max();
117 return static_cast<
int>(round(d));
121 return FXSYS_StrToInt<int32_t,
char>(str);
124 return FXSYS_StrToInt<uint32_t>(str);
127 return FXSYS_StrToInt<int32_t,
wchar_t>(str);
130 return FXSYS_StrToInt<int64_t,
char>(str);
133 return FXSYS_IntToStr<int64_t, uint64_t,
char*>(value, str, radix);
138size_t FXSYS_wcsftime(
wchar_t* strDest,
140 const wchar_t* format,
141 const struct tm* timeptr) {
144 if (timeptr->tm_year < -1900 || timeptr->tm_year > 8099 ||
145 timeptr->tm_mon < 0 || timeptr->tm_mon > 11 || timeptr->tm_mday < 1 ||
146 timeptr->tm_mday > 31 || timeptr->tm_hour < 0 || timeptr->tm_hour > 23 ||
147 timeptr->tm_min < 0 || timeptr->tm_min > 59 || timeptr->tm_sec < 0 ||
148 timeptr->tm_sec > 60 || timeptr->tm_wday < 0 || timeptr->tm_wday > 6 ||
149 timeptr->tm_yday < 0 || timeptr->tm_yday > 365) {
153 return wcsftime(strDest, maxsize, format, timeptr);
156int FXSYS_stricmp(
const char* str1,
const char* str2) {
157 return _stricmp(str1, str2);
160int FXSYS_wcsicmp(
const wchar_t* str1,
const wchar_t* str2) {
161 return _wcsicmp(str1, str2);
172 *str = tolower(*str);
184 *str = toupper(*str);
226 }
while (f && f == l);
242 }
while (f && f == l);
247 return FXSYS_IntToStr<int32_t, uint32_t,
char*>(value, str, radix);
260 return sqrtf(a * a + b * b);
#define UNSAFE_BUFFERS(...)
int32_t FXSYS_towupper(wchar_t c)
int32_t FXSYS_towlower(wchar_t c)
int32_t FXSYS_atoi(const char *str)
uint32_t FXSYS_atoui(const char *str)
int FXSYS_wcsicmp(const wchar_t *str1, const wchar_t *str2)
int32_t FXSYS_wtoi(const wchar_t *str)
int FXSYS_stricmp(const char *str1, const char *str2)
int64_t FXSYS_atoi64(const char *str)
char * FXSYS_strlwr(char *str)
wchar_t * FXSYS_wcsupr(wchar_t *str)
char * FXSYS_strupr(char *str)
wchar_t * FXSYS_wcslwr(wchar_t *str)
uint32_t FXSYS_GetLastError()
const char * FXSYS_i64toa(int64_t value, char *str, int radix)
int FXSYS_roundf(float f)
int FXSYS_round(double d)
char * FXSYS_itoa(int value, char *str, int radix)
void FXSYS_SetLastError(uint32_t err)
float FXSYS_sqrt2(float a, float b)