25 #include "SDL_stdinc.h"
34 #if defined(_XGP6) || defined(__APPLE__) || \
35 (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)))
36 #define ICONV_INBUF_NONCONST
52 return iconv_close((iconv_t) ((
size_t) cd));
57 const char **inbuf,
size_t * inbytesleft,
58 char **outbuf,
size_t * outbytesleft)
61 #ifdef ICONV_INBUF_NONCONST
62 retCode = iconv((iconv_t) ((
size_t) cd), (
char **) inbuf, inbytesleft, outbuf, outbytesleft);
64 retCode = iconv((iconv_t) ((
size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft);
66 if (retCode == (
size_t) - 1) {
87 #define UNICODE_BOM 0xFEFF
89 #define UNKNOWN_ASCII '?'
90 #define UNKNOWN_UNICODE 0xFFFD
109 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
110 #define ENCODING_UTF16NATIVE ENCODING_UTF16BE
111 #define ENCODING_UTF32NATIVE ENCODING_UTF32BE
112 #define ENCODING_UCS2NATIVE ENCODING_UCS2BE
113 #define ENCODING_UCS4NATIVE ENCODING_UCS4BE
115 #define ENCODING_UTF16NATIVE ENCODING_UTF16LE
116 #define ENCODING_UTF32NATIVE ENCODING_UTF32LE
117 #define ENCODING_UCS2NATIVE ENCODING_UCS2LE
118 #define ENCODING_UCS4NATIVE ENCODING_UCS4LE
180 if (!lang || !*lang ||
SDL_strcmp(lang,
"C") == 0) {
205 char fromcode_buffer[64];
206 char tocode_buffer[64];
208 if (!fromcode || !*fromcode) {
209 fromcode =
getlocale(fromcode_buffer,
sizeof(fromcode_buffer));
211 if (!tocode || !*tocode) {
212 tocode =
getlocale(tocode_buffer,
sizeof(tocode_buffer));
231 cd->src_fmt = src_fmt;
232 cd->dst_fmt = dst_fmt;
241 const char **inbuf,
size_t * inbytesleft,
242 char **outbuf,
size_t * outbytesleft)
247 size_t srclen, dstlen;
251 if (!inbuf || !*inbuf) {
255 if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) {
259 srclen = (inbytesleft ? *inbytesleft : 0);
261 dstlen = *outbytesleft;
263 switch (cd->src_fmt) {
268 size_t n = srclen / 2;
270 if (p[0] == 0xFF && p[1] == 0xFE) {
273 }
else if (p[0] == 0xFE && p[1] == 0xFF) {
290 size_t n = srclen / 4;
292 if (p[0] == 0xFF && p[1] == 0xFE &&
293 p[2] == 0x00 && p[3] == 0x00) {
296 }
else if (p[0] == 0x00 && p[1] == 0x00 &&
297 p[2] == 0xFE && p[3] == 0xFF) {
312 switch (cd->dst_fmt) {
338 switch (cd->src_fmt) {
342 ch = (
Uint32) (p[0] & 0x7F);
361 if ((p[0] & 0xFE) != 0xFC) {
367 if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) {
370 ch = (
Uint32) (p[0] & 0x01);
373 }
else if (p[0] >= 0xF8) {
374 if ((p[0] & 0xFC) != 0xF8) {
380 if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) {
383 ch = (
Uint32) (p[0] & 0x03);
386 }
else if (p[0] >= 0xF0) {
387 if ((p[0] & 0xF8) != 0xF0) {
393 if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) {
396 ch = (
Uint32) (p[0] & 0x07);
399 }
else if (p[0] >= 0xE0) {
400 if ((p[0] & 0xF0) != 0xE0) {
406 if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) {
409 ch = (
Uint32) (p[0] & 0x0F);
412 }
else if (p[0] >= 0xC0) {
413 if ((p[0] & 0xE0) != 0xC0) {
419 if ((p[0] & 0xDE) == 0xC0) {
422 ch = (
Uint32) (p[0] & 0x1F);
426 if ((p[0] & 0x80) != 0x00) {
442 if ((p[0] & 0xC0) != 0x80) {
460 if ((ch >= 0xD800 && ch <= 0xDFFF) ||
461 (ch == 0xFFFE || ch == 0xFFFF) || ch > 0x10FFFF) {
479 if (W1 < 0xD800 || W1 > 0xDFFF) {
497 if (W2 < 0xDC00 || W2 > 0xDFFF) {
504 ch = (((
Uint32) (W1 & 0x3FF) << 10) |
505 (
Uint32) (W2 & 0x3FF)) + 0x10000;
518 if (W1 < 0xD800 || W1 > 0xDFFF) {
536 if (W2 < 0xDC00 || W2 > 0xDFFF) {
543 ch = (((
Uint32) (W1 & 0x3FF) << 10) |
544 (
Uint32) (W2 & 0x3FF)) + 0x10000;
576 ch = ((
Uint32) p[0] << 24) |
590 ch = ((
Uint32) p[3] << 24) |
600 switch (cd->dst_fmt) {
644 }
else if (ch <= 0x7FF) {
648 p[0] = 0xC0 | (
Uint8) ((ch >> 6) & 0x1F);
649 p[1] = 0x80 | (
Uint8) (ch & 0x3F);
652 }
else if (ch <= 0xFFFF) {
656 p[0] = 0xE0 | (
Uint8) ((ch >> 12) & 0x0F);
657 p[1] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
658 p[2] = 0x80 | (
Uint8) (ch & 0x3F);
661 }
else if (ch <= 0x1FFFFF) {
665 p[0] = 0xF0 | (
Uint8) ((ch >> 18) & 0x07);
666 p[1] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
667 p[2] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
668 p[3] = 0x80 | (
Uint8) (ch & 0x3F);
671 }
else if (ch <= 0x3FFFFFF) {
675 p[0] = 0xF8 | (
Uint8) ((ch >> 24) & 0x03);
676 p[1] = 0x80 | (
Uint8) ((ch >> 18) & 0x3F);
677 p[2] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
678 p[3] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
679 p[4] = 0x80 | (
Uint8) (ch & 0x3F);
686 p[0] = 0xFC | (
Uint8) ((ch >> 30) & 0x01);
687 p[1] = 0x80 | (
Uint8) ((ch >> 24) & 0x3F);
688 p[2] = 0x80 | (
Uint8) ((ch >> 18) & 0x3F);
689 p[3] = 0x80 | (
Uint8) ((ch >> 12) & 0x3F);
690 p[4] = 0x80 | (
Uint8) ((ch >> 6) & 0x3F);
691 p[5] = 0x80 | (
Uint8) (ch & 0x3F);
707 p[0] = (
Uint8) (ch >> 8);
717 W1 = 0xD800 | (
Uint16) ((ch >> 10) & 0x3FF);
718 W2 = 0xDC00 | (
Uint16) (ch & 0x3FF);
719 p[0] = (
Uint8) (W1 >> 8);
721 p[2] = (
Uint8) (W2 >> 8);
738 p[1] = (
Uint8) (ch >> 8);
748 W1 = 0xD800 | (
Uint16) ((ch >> 10) & 0x3FF);
749 W2 = 0xDC00 | (
Uint16) (ch & 0x3FF);
750 p[1] = (
Uint8) (W1 >> 8);
752 p[3] = (
Uint8) (W2 >> 8);
768 p[0] = (
Uint8) (ch >> 8);
783 p[1] = (
Uint8) (ch >> 8);
794 if (ch > 0x7FFFFFFF) {
802 p[0] = (
Uint8) (ch >> 24);
803 p[1] = (
Uint8) (ch >> 16);
804 p[2] = (
Uint8) (ch >> 8);
815 if (ch > 0x7FFFFFFF) {
823 p[3] = (
Uint8) (ch >> 24);
824 p[2] = (
Uint8) (ch >> 16);
825 p[1] = (
Uint8) (ch >> 8);
835 *inbytesleft = srclen;
837 *outbytesleft = dstlen;
868 if (!tocode || !*tocode) {
871 if (!fromcode || !*fromcode) {
880 stringsize = inbytesleft > 4 ? inbytesleft : 4;
887 outbytesleft = stringsize;
890 while (inbytesleft > 0) {
891 retCode =
SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
902 outbuf =
string + (outbuf - oldstring);
903 outbytesleft = stringsize - (outbuf -
string);
#define SDL_COMPILE_TIME_ASSERT(name, x)
DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size)
DECLSPEC void SDLCALL SDL_free(void *mem)
EGLImageKHR EGLint * name
DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c)
uint32_t Uint32
An unsigned 32-bit integer type.
EGLContext EGLenum EGLClientBuffer buffer
static struct @83 encodings[]
DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2)
#define ENCODING_UTF32NATIVE
#define SDL_arraysize(array)
#define ENCODING_UCS2NATIVE
#define ENCODING_UCS4NATIVE
uint8_t Uint8
An unsigned 8-bit integer type.
DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd)
GLsizei const GLcharARB ** string
DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
struct _SDL_iconv_t * SDL_iconv_t
uint16_t Uint16
An unsigned 16-bit integer type.
DECLSPEC char *SDLCALL SDL_getenv(const char *name)
#define ENCODING_UTF16NATIVE
DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode)
DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2)
static const char * getlocale(char *buffer, size_t bufsize)