22 #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) 23 #define SDL_DISABLE_ANALYZE_MACROS 1 26 #include "../SDL_internal.h" 39 #if defined(_XGP6) || defined(__APPLE__) || \ 40 (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \ 41 (defined(_NEWLIB_VERSION))) 42 #define ICONV_INBUF_NONCONST 52 return (SDL_iconv_t) ((
size_t) iconv_open(tocode, fromcode));
58 return iconv_close((iconv_t) ((
size_t) cd));
63 const char **inbuf,
size_t * inbytesleft,
64 char **outbuf,
size_t * outbytesleft)
67 #ifdef ICONV_INBUF_NONCONST 68 retCode = iconv((iconv_t) ((
size_t) cd), (
char **) inbuf, inbytesleft, outbuf, outbytesleft);
70 retCode = iconv((iconv_t) ((
size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft);
72 if (retCode == (
size_t) - 1) {
93 #define UNICODE_BOM 0xFEFF 95 #define UNKNOWN_ASCII '?' 96 #define UNKNOWN_UNICODE 0xFFFD 115 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 116 #define ENCODING_UTF16NATIVE ENCODING_UTF16BE 117 #define ENCODING_UTF32NATIVE ENCODING_UTF32BE 118 #define ENCODING_UCS2NATIVE ENCODING_UCS2BE 119 #define ENCODING_UCS4NATIVE ENCODING_UCS4BE 121 #define ENCODING_UTF16NATIVE ENCODING_UTF16LE 122 #define ENCODING_UTF32NATIVE ENCODING_UTF32LE 123 #define ENCODING_UCS2NATIVE ENCODING_UCS2LE 124 #define ENCODING_UCS4NATIVE ENCODING_UCS4LE 186 if (!lang || !*lang ||
SDL_strcmp(lang,
"C") == 0) {
211 char fromcode_buffer[64];
212 char tocode_buffer[64];
214 if (!fromcode || !*fromcode) {
215 fromcode =
getlocale(fromcode_buffer,
sizeof(fromcode_buffer));
217 if (!tocode || !*tocode) {
218 tocode =
getlocale(tocode_buffer,
sizeof(tocode_buffer));
235 SDL_iconv_t cd = (SDL_iconv_t)
SDL_malloc(
sizeof(*cd));
242 return (SDL_iconv_t) - 1;
247 const char **inbuf,
size_t * inbytesleft,
248 char **outbuf,
size_t * outbytesleft)
253 size_t srclen, dstlen;
257 if (!inbuf || !*inbuf) {
261 if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) {
265 srclen = (inbytesleft ? *inbytesleft : 0);
267 dstlen = *outbytesleft;
269 switch (cd->src_fmt) {
274 size_t n = srclen / 2;
276 if (p[0] == 0xFF && p[1] == 0xFE) {
279 }
else if (p[0] == 0xFE && p[1] == 0xFF) {
296 size_t n = srclen / 4;
298 if (p[0] == 0xFF && p[1] == 0xFE &&
299 p[2] == 0x00 && p[3] == 0x00) {
302 }
else if (p[0] == 0x00 && p[1] == 0x00 &&
303 p[2] == 0xFE && p[3] == 0xFF) {
318 switch (cd->dst_fmt) {
344 switch (cd->src_fmt) {
348 ch = (
Uint32) (p[0] & 0x7F);
367 if ((p[0] & 0xFE) != 0xFC) {
373 if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) {
376 ch = (
Uint32) (p[0] & 0x01);
379 }
else if (p[0] >= 0xF8) {
380 if ((p[0] & 0xFC) != 0xF8) {
386 if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) {
389 ch = (
Uint32) (p[0] & 0x03);
392 }
else if (p[0] >= 0xF0) {
393 if ((p[0] & 0xF8) != 0xF0) {
399 if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) {
402 ch = (
Uint32) (p[0] & 0x07);
405 }
else if (p[0] >= 0xE0) {
406 if ((p[0] & 0xF0) != 0xE0) {
412 if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) {
415 ch = (
Uint32) (p[0] & 0x0F);
418 }
else if (p[0] >= 0xC0) {
419 if ((p[0] & 0xE0) != 0xC0) {
425 if ((p[0] & 0xDE) == 0xC0) {
428 ch = (
Uint32) (p[0] & 0x1F);
432 if ((p[0] & 0x80) != 0x00) {
448 if ((p[0] & 0xC0) != 0x80) {
466 if ((ch >= 0xD800 && ch <= 0xDFFF) ||
467 (ch == 0xFFFE || ch == 0xFFFF) || ch > 0x10FFFF) {
485 if (W1 < 0xD800 || W1 > 0xDFFF) {
503 if (W2 < 0xDC00 || W2 > 0xDFFF) {
510 ch = (((
Uint32) (W1 & 0x3FF) << 10) |
511 (
Uint32) (W2 & 0x3FF)) + 0x10000;
524 if (W1 < 0xD800 || W1 > 0xDFFF) {
542 if (W2 < 0xDC00 || W2 > 0xDFFF) {
549 ch = (((
Uint32) (W1 & 0x3FF) << 10) |
550 (
Uint32) (W2 & 0x3FF)) + 0x10000;
582 ch = ((
Uint32) p[0] << 24) |
596 ch = ((
Uint32) p[3] << 24) |
606 switch (cd->dst_fmt) {
650 }
else if (ch <= 0x7FF) {
654 p[0] = 0xC0 | (
Uint8) ((ch >> 6) & 0x1F);
655 p[1] = 0x80 | (
Uint8) (ch & 0x3F);
658 }
else if (ch <= 0xFFFF) {
662 p[0] = 0xE0 | (
Uint8) ((ch >> 12) & 0x0F);
663 p[1] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
664 p[2] = 0x80 | (
Uint8) (ch & 0x3F);
667 }
else if (ch <= 0x1FFFFF) {
671 p[0] = 0xF0 | (
Uint8) ((ch >> 18) & 0x07);
672 p[1] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
673 p[2] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
674 p[3] = 0x80 | (
Uint8) (ch & 0x3F);
677 }
else if (ch <= 0x3FFFFFF) {
681 p[0] = 0xF8 | (
Uint8) ((ch >> 24) & 0x03);
682 p[1] = 0x80 | (
Uint8) ((ch >> 18) & 0x3F);
683 p[2] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
684 p[3] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
685 p[4] = 0x80 | (
Uint8) (ch & 0x3F);
692 p[0] = 0xFC | (
Uint8) ((ch >> 30) & 0x01);
693 p[1] = 0x80 | (
Uint8) ((ch >> 24) & 0x3F);
694 p[2] = 0x80 | (
Uint8) ((ch >> 18) & 0x3F);
695 p[3] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
696 p[4] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
697 p[5] = 0x80 | (
Uint8) (ch & 0x3F);
713 p[0] = (
Uint8) (ch >> 8);
723 W1 = 0xD800 | (
Uint16) ((ch >> 10) & 0x3FF);
724 W2 = 0xDC00 | (
Uint16) (ch & 0x3FF);
725 p[0] = (
Uint8) (W1 >> 8);
727 p[2] = (
Uint8) (W2 >> 8);
744 p[1] = (
Uint8) (ch >> 8);
754 W1 = 0xD800 | (
Uint16) ((ch >> 10) & 0x3FF);
755 W2 = 0xDC00 | (
Uint16) (ch & 0x3FF);
756 p[1] = (
Uint8) (W1 >> 8);
758 p[3] = (
Uint8) (W2 >> 8);
774 p[0] = (
Uint8) (ch >> 8);
789 p[1] = (
Uint8) (ch >> 8);
800 if (ch > 0x7FFFFFFF) {
808 p[0] = (
Uint8) (ch >> 24);
809 p[1] = (
Uint8) (ch >> 16);
810 p[2] = (
Uint8) (ch >> 8);
821 if (ch > 0x7FFFFFFF) {
829 p[3] = (
Uint8) (ch >> 24);
830 p[2] = (
Uint8) (ch >> 16);
831 p[1] = (
Uint8) (ch >> 8);
841 *inbytesleft = srclen;
843 *outbytesleft = dstlen;
852 if (cd != (SDL_iconv_t)-1) {
872 if (cd == (SDL_iconv_t) - 1) {
874 if (!tocode || !*tocode) {
877 if (!fromcode || !*fromcode) {
882 if (cd == (SDL_iconv_t) - 1) {
886 stringsize = inbytesleft > 4 ? inbytesleft : 4;
893 outbytesleft = stringsize;
896 while (inbytesleft > 0) {
897 retCode =
SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
908 outbuf =
string + (outbuf - oldstring);
909 outbytesleft = stringsize - (outbuf -
string);
static struct @26 encodings[]
int SDL_iconv_close(SDL_iconv_t cd)
uint32_t Uint32
An unsigned 32-bit integer type.
GLsizei const GLchar *const * string
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
GLuint const GLchar * name
GLenum GLuint GLsizei bufsize
uint8_t Uint8
An unsigned 8-bit integer type.
char * SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
#define ENCODING_UTF32NATIVE
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define ENCODING_UCS2NATIVE
#define ENCODING_UCS4NATIVE
SDL_COMPILE_TIME_ASSERT(size, CountTo >0)
uint16_t Uint16
An unsigned 16-bit integer type.
#define SDL_arraysize(array)
size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
#define ENCODING_UTF16NATIVE
static const char * getlocale(char *buffer, size_t bufsize)