22 #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) 23 #define SDL_DISABLE_ANALYZE_MACROS 1 26 #include "../SDL_internal.h" 33 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H) 40 #if defined(_XGP6) || defined(__APPLE__) || \ 41 (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \ 42 (defined(_NEWLIB_VERSION))) 43 #define ICONV_INBUF_NONCONST 53 return (SDL_iconv_t) ((
size_t) iconv_open(tocode, fromcode));
59 return iconv_close((iconv_t) ((
size_t) cd));
64 const char **inbuf,
size_t * inbytesleft,
65 char **outbuf,
size_t * outbytesleft)
68 #ifdef ICONV_INBUF_NONCONST 69 retCode = iconv((iconv_t) ((
size_t) cd), (
char **) inbuf, inbytesleft, outbuf, outbytesleft);
71 retCode = iconv((iconv_t) ((
size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft);
73 if (retCode == (
size_t) - 1) {
94 #define UNICODE_BOM 0xFEFF 96 #define UNKNOWN_ASCII '?' 97 #define UNKNOWN_UNICODE 0xFFFD 116 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 117 #define ENCODING_UTF16NATIVE ENCODING_UTF16BE 118 #define ENCODING_UTF32NATIVE ENCODING_UTF32BE 119 #define ENCODING_UCS2NATIVE ENCODING_UCS2BE 120 #define ENCODING_UCS4NATIVE ENCODING_UCS4BE 122 #define ENCODING_UTF16NATIVE ENCODING_UTF16LE 123 #define ENCODING_UTF32NATIVE ENCODING_UTF32LE 124 #define ENCODING_UCS2NATIVE ENCODING_UCS2LE 125 #define ENCODING_UCS4NATIVE ENCODING_UCS4LE 187 if (!lang || !*lang ||
SDL_strcmp(lang,
"C") == 0) {
212 char fromcode_buffer[64];
213 char tocode_buffer[64];
215 if (!fromcode || !*fromcode) {
216 fromcode =
getlocale(fromcode_buffer,
sizeof(fromcode_buffer));
218 if (!tocode || !*tocode) {
219 tocode =
getlocale(tocode_buffer,
sizeof(tocode_buffer));
236 SDL_iconv_t cd = (SDL_iconv_t)
SDL_malloc(
sizeof(*cd));
243 return (SDL_iconv_t) - 1;
248 const char **inbuf,
size_t * inbytesleft,
249 char **outbuf,
size_t * outbytesleft)
254 size_t srclen, dstlen;
258 if (!inbuf || !*inbuf) {
262 if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) {
266 srclen = (inbytesleft ? *inbytesleft : 0);
268 dstlen = *outbytesleft;
270 switch (cd->src_fmt) {
275 size_t n = srclen / 2;
277 if (p[0] == 0xFF && p[1] == 0xFE) {
280 }
else if (p[0] == 0xFE && p[1] == 0xFF) {
297 size_t n = srclen / 4;
299 if (p[0] == 0xFF && p[1] == 0xFE &&
300 p[2] == 0x00 && p[3] == 0x00) {
303 }
else if (p[0] == 0x00 && p[1] == 0x00 &&
304 p[2] == 0xFE && p[3] == 0xFF) {
319 switch (cd->dst_fmt) {
345 switch (cd->src_fmt) {
349 ch = (
Uint32) (p[0] & 0x7F);
368 if ((p[0] & 0xFE) != 0xFC) {
374 if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) {
377 ch = (
Uint32) (p[0] & 0x01);
380 }
else if (p[0] >= 0xF8) {
381 if ((p[0] & 0xFC) != 0xF8) {
387 if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) {
390 ch = (
Uint32) (p[0] & 0x03);
393 }
else if (p[0] >= 0xF0) {
394 if ((p[0] & 0xF8) != 0xF0) {
400 if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) {
403 ch = (
Uint32) (p[0] & 0x07);
406 }
else if (p[0] >= 0xE0) {
407 if ((p[0] & 0xF0) != 0xE0) {
413 if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) {
416 ch = (
Uint32) (p[0] & 0x0F);
419 }
else if (p[0] >= 0xC0) {
420 if ((p[0] & 0xE0) != 0xC0) {
426 if ((p[0] & 0xDE) == 0xC0) {
429 ch = (
Uint32) (p[0] & 0x1F);
433 if ((p[0] & 0x80) != 0x00) {
449 if ((p[0] & 0xC0) != 0x80) {
467 if ((ch >= 0xD800 && ch <= 0xDFFF) ||
468 (ch == 0xFFFE || ch == 0xFFFF) || ch > 0x10FFFF) {
486 if (W1 < 0xD800 || W1 > 0xDFFF) {
504 if (W2 < 0xDC00 || W2 > 0xDFFF) {
511 ch = (((
Uint32) (W1 & 0x3FF) << 10) |
512 (
Uint32) (W2 & 0x3FF)) + 0x10000;
525 if (W1 < 0xD800 || W1 > 0xDFFF) {
543 if (W2 < 0xDC00 || W2 > 0xDFFF) {
550 ch = (((
Uint32) (W1 & 0x3FF) << 10) |
551 (
Uint32) (W2 & 0x3FF)) + 0x10000;
583 ch = ((
Uint32) p[0] << 24) |
597 ch = ((
Uint32) p[3] << 24) |
607 switch (cd->dst_fmt) {
651 }
else if (ch <= 0x7FF) {
655 p[0] = 0xC0 | (
Uint8) ((ch >> 6) & 0x1F);
656 p[1] = 0x80 | (
Uint8) (ch & 0x3F);
659 }
else if (ch <= 0xFFFF) {
663 p[0] = 0xE0 | (
Uint8) ((ch >> 12) & 0x0F);
664 p[1] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
665 p[2] = 0x80 | (
Uint8) (ch & 0x3F);
668 }
else if (ch <= 0x1FFFFF) {
672 p[0] = 0xF0 | (
Uint8) ((ch >> 18) & 0x07);
673 p[1] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
674 p[2] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
675 p[3] = 0x80 | (
Uint8) (ch & 0x3F);
678 }
else if (ch <= 0x3FFFFFF) {
682 p[0] = 0xF8 | (
Uint8) ((ch >> 24) & 0x03);
683 p[1] = 0x80 | (
Uint8) ((ch >> 18) & 0x3F);
684 p[2] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
685 p[3] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
686 p[4] = 0x80 | (
Uint8) (ch & 0x3F);
693 p[0] = 0xFC | (
Uint8) ((ch >> 30) & 0x01);
694 p[1] = 0x80 | (
Uint8) ((ch >> 24) & 0x3F);
695 p[2] = 0x80 | (
Uint8) ((ch >> 18) & 0x3F);
696 p[3] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
697 p[4] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
698 p[5] = 0x80 | (
Uint8) (ch & 0x3F);
714 p[0] = (
Uint8) (ch >> 8);
724 W1 = 0xD800 | (
Uint16) ((ch >> 10) & 0x3FF);
725 W2 = 0xDC00 | (
Uint16) (ch & 0x3FF);
726 p[0] = (
Uint8) (W1 >> 8);
728 p[2] = (
Uint8) (W2 >> 8);
745 p[1] = (
Uint8) (ch >> 8);
755 W1 = 0xD800 | (
Uint16) ((ch >> 10) & 0x3FF);
756 W2 = 0xDC00 | (
Uint16) (ch & 0x3FF);
757 p[1] = (
Uint8) (W1 >> 8);
759 p[3] = (
Uint8) (W2 >> 8);
775 p[0] = (
Uint8) (ch >> 8);
790 p[1] = (
Uint8) (ch >> 8);
801 if (ch > 0x7FFFFFFF) {
809 p[0] = (
Uint8) (ch >> 24);
810 p[1] = (
Uint8) (ch >> 16);
811 p[2] = (
Uint8) (ch >> 8);
822 if (ch > 0x7FFFFFFF) {
830 p[3] = (
Uint8) (ch >> 24);
831 p[2] = (
Uint8) (ch >> 16);
832 p[1] = (
Uint8) (ch >> 8);
842 *inbytesleft = srclen;
844 *outbytesleft = dstlen;
853 if (cd != (SDL_iconv_t)-1) {
873 if (cd == (SDL_iconv_t) - 1) {
875 if (!tocode || !*tocode) {
878 if (!fromcode || !*fromcode) {
883 if (cd == (SDL_iconv_t) - 1) {
887 stringsize = inbytesleft > 4 ? inbytesleft : 4;
894 outbytesleft = stringsize;
897 while (inbytesleft > 0) {
898 retCode =
SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
909 outbuf =
string + (outbuf - oldstring);
910 outbytesleft = stringsize - (outbuf -
string);
int SDL_iconv_close(SDL_iconv_t cd)
GLsizei const GLchar *const * string
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
GLuint const GLchar * name
uint32_t Uint32
An unsigned 32-bit integer type.
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
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)
#define SDL_COMPILE_TIME_ASSERT(name, x)
static struct @25 encodings[]