7#include "core/fxcrt/fx_system.h"
13#include "build/build_config.h"
14#include "core/fxcrt/fx_extension.h"
19uint32_t g_last_error = 0;
22template <
typename IntType,
typename CharType>
23IntType FXSYS_StrToInt(
const CharType* str) {
28 bool neg = *str ==
'-';
29 if (neg || *str ==
'+')
33 while (*str && FXSYS_IsDecimalDigit(*str)) {
34 IntType val = FXSYS_DecimalCharToInt(*str);
35 if (num > (
std::numeric_limits<IntType>::max() - val) / 10) {
36 if (neg &&
std::numeric_limits<IntType>::is_signed) {
39 return std::numeric_limits<IntType>::min();
43 return std::numeric_limits<IntType>::max();
53 return neg ? ~num + 1 : num;
56template <
typename T,
typename UT,
typename STR_T>
57STR_T FXSYS_IntToStr(T value, STR_T str,
int radix) {
58 if (radix < 2 || radix > 16) {
72 uvalue =
static_cast<UT>(-(value + 1)) + 1;
77 T order = uvalue / radix;
80 order = order / radix;
82 for (
int d = digits - 1; d > -1; d--) {
83 str[d + i] =
"0123456789abcdef"[uvalue % radix];
95 if (f <
static_cast<
float>(
std::numeric_limits<
int>::min()))
96 return std::numeric_limits<
int>::min();
97 if (f >=
static_cast<
float>(
std::numeric_limits<
int>::max()))
98 return std::numeric_limits<
int>::max();
99 return static_cast<
int>(round(f));
105 if (d <
static_cast<
double>(
std::numeric_limits<
int>::min()))
106 return std::numeric_limits<
int>::min();
107 if (d >=
static_cast<
double>(
std::numeric_limits<
int>::max()))
108 return std::numeric_limits<
int>::max();
109 return static_cast<
int>(round(d));
113 return FXSYS_StrToInt<int32_t,
char>(str);
116 return FXSYS_StrToInt<uint32_t>(str);
119 return FXSYS_StrToInt<int32_t,
wchar_t>(str);
122 return FXSYS_StrToInt<int64_t,
char>(str);
125 return FXSYS_IntToStr<int64_t, uint64_t,
char*>(value, str, radix);
130size_t FXSYS_wcsftime(
wchar_t* strDest,
132 const wchar_t* format,
133 const struct tm* timeptr) {
136 if (timeptr->tm_year < -1900 || timeptr->tm_year > 8099 ||
137 timeptr->tm_mon < 0 || timeptr->tm_mon > 11 || timeptr->tm_mday < 1 ||
138 timeptr->tm_mday > 31 || timeptr->tm_hour < 0 || timeptr->tm_hour > 23 ||
139 timeptr->tm_min < 0 || timeptr->tm_min > 59 || timeptr->tm_sec < 0 ||
140 timeptr->tm_sec > 60 || timeptr->tm_wday < 0 || timeptr->tm_wday > 6 ||
141 timeptr->tm_yday < 0 || timeptr->tm_yday > 365) {
145 return wcsftime(strDest, maxsize, format, timeptr);
156 *str = tolower(*str);
167 *str = toupper(*str);
203 }
while (f && f == l);
215 }
while (f && f == l);
220 return FXSYS_IntToStr<int32_t, uint32_t,
char*>(value, str, radix);
233 return sqrtf(a * a + b * b);
int32_t FXSYS_towupper(wchar_t c)
int32_t FXSYS_towlower(wchar_t c)
int32_t FXSYS_atoi(const char *str)
char * FXSYS_strlwr(char *str)
wchar_t * FXSYS_wcsupr(wchar_t *str)
char * FXSYS_strupr(char *str)
uint32_t FXSYS_atoui(const char *str)
int FXSYS_wcsicmp(const wchar_t *str1, const wchar_t *str2)
wchar_t * FXSYS_wcslwr(wchar_t *str)
int32_t FXSYS_wtoi(const wchar_t *str)
uint32_t FXSYS_GetLastError()
const char * FXSYS_i64toa(int64_t value, char *str, int radix)
int FXSYS_stricmp(const char *str1, const char *str2)
int64_t FXSYS_atoi64(const char *str)
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)