25 #include "SDL_stdinc.h"
28 #define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
29 #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
31 #define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
32 #define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
36 if (c >= 0xC0 && c <= 0xDF)
38 else if (c >= 0xE0 && c <= 0xEF)
40 else if (c >= 0xF0 && c <= 0xF4)
46 #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL)
50 const char *textstart = text;
58 if (radix == 16 &&
SDL_strncmp(text,
"0x", 2) == 0) {
66 v = 10 + (*text -
'A');
68 v = 10 + (*text -
'a');
77 if (negative && value) {
83 return (text - textstart);
87 #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
91 const char *textstart = text;
92 unsigned long value = 0;
94 if (radix == 16 &&
SDL_strncmp(text,
"0x", 2) == 0) {
102 v = 10 + (*text -
'A');
104 v = 10 + (*text -
'a');
115 return (text - textstart);
123 const char *textstart = text;
126 if (radix == 16 &&
SDL_strncmp(text,
"0x", 2) == 0) {
134 v = 10 + (*text -
'A');
136 v = 10 + (*text -
'a');
147 return (text - textstart);
151 #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
155 const char *textstart = text;
163 if (radix == 16 &&
SDL_strncmp(text,
"0x", 2) == 0) {
171 v = 10 + (*text -
'A');
173 v = 10 + (*text -
'a');
182 if (negative && value) {
188 return (text - textstart);
192 #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
196 const char *textstart = text;
199 if (radix == 16 &&
SDL_strncmp(text,
"0x", 2) == 0) {
207 v = 10 + (*text -
'A');
209 v = 10 + (*text -
'a');
220 return (text - textstart);
224 #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
228 const char *textstart = text;
229 unsigned long lvalue = 0;
243 lvalue = *text -
'0';
244 value += (double) lvalue / mult;
250 if (negative && value) {
256 return (text - textstart);
263 #if defined(HAVE_MEMSET)
264 return memset(dst, c, len);
266 size_t left = (len % 4);
269 Uint32 value4 = (c | (c << 8) | (c << 16) | (c << 24));
278 dstp1 = (
Uint8 *) dstp4;
299 return __builtin_memcpy(dst, src, len);
300 #elif defined(HAVE_MEMCPY)
301 return memcpy(dst, src, len);
302 #elif defined(HAVE_BCOPY)
303 bcopy(src, dst, len);
310 if (((intptr_t)src & 0x3) || ((intptr_t)dst & 0x3)) {
319 size_t left = (len % 4);
321 Uint8 *srcp1, *dstp1;
330 srcp1 = (
Uint8 *) srcp4;
331 dstp1 = (
Uint8 *) dstp4;
348 #if defined(HAVE_MEMMOVE)
351 char *srcp = (
char *) src;
352 char *dstp = (
char *) dst;
372 #if defined(HAVE_MEMCMP)
373 return memcmp(s1, s2, len);
375 char *s1p = (
char *) s1;
376 char *s2p = (
char *) s2;
379 return (*s1p - *s2p);
391 #if defined(HAVE_STRLEN)
392 return strlen(
string);
405 #if defined(HAVE_WCSLEN)
406 return wcslen(
string);
419 #if defined(HAVE_WCSLCPY)
420 return wcslcpy(dst, src, maxlen);
435 #if defined(HAVE_WCSLCAT)
436 return wcslcat(dst, src, maxlen);
440 if (dstlen < maxlen) {
443 return dstlen + srclen;
450 #if defined(HAVE_STRLCPY)
451 return strlcpy(dst, src, maxlen);
466 size_t bytes =
SDL_min(src_bytes, dst_bytes - 1);
468 char trailing_bytes = 0;
471 unsigned char c = (
unsigned char)src[bytes - 1];
476 for (i = bytes - 1; i != 0; --
i)
478 c = (
unsigned char)src[i];
482 if (bytes - i != trailing_bytes + 1)
498 #if defined(HAVE_STRLCAT)
499 return strlcat(dst, src, maxlen);
503 if (dstlen < maxlen) {
506 return dstlen + srclen;
513 #if defined(HAVE_STRDUP)
528 #if defined(HAVE__STRREV)
529 return _strrev(
string);
532 char *
a = &
string[0];
533 char *
b = &
string[len - 1];
547 #if defined(HAVE__STRUPR)
548 return _strupr(
string);
562 #if defined(HAVE__STRLWR)
563 return _strlwr(
string);
579 #elif defined(HAVE_INDEX)
597 #elif defined(HAVE_RINDEX)
600 const char *bufp =
string +
SDL_strlen(
string) - 1;
601 while (bufp >=
string) {
603 return (
char *) bufp;
614 #if defined(HAVE_STRSTR)
620 return (
char *) haystack;
628 #if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
629 !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
631 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
632 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
633 'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
634 'U',
'V',
'W',
'X',
'Y',
'Z'
642 return itoa(value,
string, radix);
644 return SDL_ltoa((
long)value,
string, radix);
652 return _uitoa(value,
string, radix);
654 return SDL_ultoa((
unsigned long)value,
string, radix);
661 #if defined(HAVE__LTOA)
662 return _ltoa(value,
string, radix);
681 if (*
string ==
'-') {
694 #if defined(HAVE__ULTOA)
695 return _ultoa(value,
string, radix);
719 #if defined(HAVE__I64TOA)
720 return _i64toa(value,
string, radix);
739 if (*
string ==
'-') {
752 #if defined(HAVE__UI64TOA)
753 return _ui64toa(value,
string, radix);
786 return (
double) atof(
string);
795 #if defined(HAVE_STRTOL)
796 return strtol(
string, endp, base);
811 *endp = (
char *)
string + len;
820 #if defined(HAVE_STRTOUL)
821 return strtoul(
string, endp, base);
836 *endp = (
char *)
string + len;
845 #if defined(HAVE_STRTOLL)
846 return strtoll(
string, endp, base);
861 *endp = (
char *)
string + len;
870 #if defined(HAVE_STRTOULL)
871 return strtoull(
string, endp, base);
886 *endp = (
char *)
string + len;
895 #if defined(HAVE_STRTOD)
896 return strtod(
string, endp);
903 *endp = (
char *)
string + len;
912 #if defined(HAVE_STRCMP)
913 return strcmp(str1, str2);
915 while (*str1 && *str2) {
921 return (
int) ((
unsigned char) *str1 - (
unsigned char) *str2);
928 #if defined(HAVE_STRNCMP)
929 return strncmp(str1, str2, maxlen);
931 while (*str1 && *str2 && maxlen) {
941 return (
int) ((
unsigned char) *str1 - (
unsigned char) *str2);
948 #ifdef HAVE_STRCASECMP
949 return strcasecmp(str1, str2);
950 #elif defined(HAVE__STRICMP)
951 return _stricmp(str1, str2);
955 while (*str1 && *str2) {
965 return (
int) ((
unsigned char) a - (
unsigned char)
b);
972 #ifdef HAVE_STRNCASECMP
973 return strncasecmp(str1, str2, maxlen);
974 #elif defined(HAVE__STRNICMP)
975 return _strnicmp(str1, str2, maxlen);
979 while (*str1 && *str2 && maxlen) {
993 return (
int) ((
unsigned char) a - (
unsigned char)
b);
1000 SDL_sscanf(
const char *text,
const char *fmt, ...)
1005 rc = vsscanf(text, fmt, ap);
1062 char *valuep = va_arg(ap,
char *);
1064 *valuep++ = *text++;
1082 if (inttype > DO_SHORT) {
1087 if (inttype < DO_LONGLONG) {
1094 inttype = DO_LONGLONG;
1100 if (text[index] ==
'-') {
1103 if (text[index] ==
'0') {
1104 if (
SDL_tolower((
unsigned char) text[index + 1]) ==
'x') {
1113 if (inttype == DO_LONGLONG) {
1128 short *valuep = va_arg(ap,
short *);
1129 *valuep = (short) value;
1134 int *valuep = va_arg(ap,
int *);
1135 *valuep = (
int) value;
1140 long *valuep = va_arg(ap,
long *);
1165 if (inttype == DO_LONGLONG) {
1174 unsigned long value;
1180 short *valuep = va_arg(ap,
short *);
1181 *valuep = (short) value;
1186 int *valuep = va_arg(ap,
int *);
1187 *valuep = (
int) value;
1192 long *valuep = va_arg(ap,
long *);
1210 void **valuep = va_arg(ap,
void **);
1211 *valuep = (
void *) value;
1222 float *valuep = va_arg(ap,
float *);
1223 *valuep = (float) value;
1240 char *valuep = va_arg(ap,
char *);
1242 *valuep++ = *text++;
1262 if (*text == *fmt) {
1289 #ifdef HAVE_VSNPRINTF
1290 int SDL_vsnprintf(
char *text,
size_t maxlen,
const char *fmt, va_list ap)
1292 return vsnprintf(text, maxlen, fmt, ap);
1320 if (info && info->width && (
size_t)info->width >
SDL_strlen(
string)) {
1321 char fill = info->pad_zeroes ?
'0' :
' ';
1323 while (width-- > 0 && maxlen > 0) {
1347 SDL_ltoa(value, num, info ? info->radix : 10);
1356 SDL_ultoa(value, num, info ? info->radix : 10);
1365 SDL_lltoa(value, num, info ? info->radix : 10);
1374 SDL_ulltoa(value, num, info ? info->radix : 10);
1383 size_t left = maxlen;
1384 char *textstart = text;
1388 unsigned long value;
1397 }
else if (info->force_sign) {
1404 value = (
unsigned long) arg;
1413 if (info->precision < 0) {
1414 info->precision = 6;
1416 if (info->force_type || info->precision > 0) {
1423 while (info->precision-- > 0) {
1424 value = (
unsigned long) (arg * mult);
1432 arg -= (double) value / mult;
1442 if (info->force_type) {
1451 width = info->width - (
int)(text - textstart);
1453 char fill = info->pad_zeroes ?
'0' :
' ';
1454 char *
end = text+left-1;
1455 len = (text - textstart);
1456 for (len = (text - textstart); len--; ) {
1457 if ((textstart+len+width) <
end) {
1458 *(textstart+len+
width) = *(textstart+len);
1469 if (textstart+len < end) {
1470 textstart[
len] = fill;
1475 return (text - textstart);
1481 size_t left = maxlen;
1482 char *textstart = text;
1489 SDL_FormatInfo info;
1499 info.precision = -1;
1502 while (check_flag) {
1523 if (*fmt >=
'0' && *fmt <=
'9') {
1524 info.width =
SDL_strtol(fmt, (
char **)&fmt, 0);
1529 if (*fmt >=
'0' && *fmt <=
'9') {
1530 info.precision =
SDL_strtol(fmt, (
char **)&fmt, 0);
1548 *text = (char) va_arg(ap,
int);
1557 if (inttype < DO_LONGLONG) {
1564 inttype = DO_LONGLONG;
1572 (
long) va_arg(ap,
int));
1593 if (info.radix == 10) {
1601 if (info.radix == 10) {
1611 va_arg(ap,
unsigned int));
1615 va_arg(ap,
unsigned long));
1656 return (
int)(text - textstart);
DECLSPEC int SDLCALL SDL_isspace(int x)
DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix)
static size_t SDL_ScanFloat(const char *text, double *valuep)
DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp)
char * strdup(const char *inStr)
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix)
DECLSPEC double SDLCALL SDL_atof(const char *str)
DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c)
DECLSPEC int SDLCALL SDL_tolower(int x)
DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix)
DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,...)
GLboolean GLboolean GLboolean GLboolean a
DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen)
DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len)
static const char ntoa_table[]
#define SDL_const_cast(type, expression)
DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c)
#define SDL_islowerhex(X)
static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
static size_t SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
static size_t SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base)
DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix)
DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base)
DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base)
static size_t SDL_ScanLong(const char *text, int radix, long *valuep)
DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len)
DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix)
EGLSurface EGLint EGLint EGLint width
DECLSPEC char *SDLCALL SDL_strupr(char *str)
DECLSPEC char *SDLCALL SDL_strdup(const char *str)
uint64_t Uint64
An unsigned 64-bit integer type.
#define UTF8_IsLeadByte(c)
String itoa(const int &number)
DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle)
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr)
#define SDL_isupperhex(X)
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
EGLSurface EGLint void ** value
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
uint8_t Uint8
An unsigned 8-bit integer type.
GLsizei const GLcharARB ** string
DECLSPEC int SDLCALL SDL_atoi(const char *str)
DECLSPEC char *SDLCALL SDL_strlwr(char *str)
DECLSPEC int SDLCALL SDL_toupper(int x)
GLdouble GLdouble GLdouble b
static size_t SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint64 value)
static int UTF8_TrailingBytes(unsigned char c)
DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len)
static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
GLenum GLint GLint * precision
int64_t Sint64
A signed 64-bit integer type.
DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix)
#define UTF8_IsTrailingByte(c)
static size_t SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
DECLSPEC char *SDLCALL SDL_strrev(char *str)
DECLSPEC int SDLCALL SDL_isdigit(int x)
DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2)
DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep)
DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
static size_t SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value)
static size_t SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)