Fixed bug #455
If passed "" for the character set, let iconv_open() interpret it as locale. This was merged from revision 3234,3235 from SDL 1.2 --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402503
This commit is contained in:
parent
4a00054e18
commit
fc4cf4c9fc
1 changed files with 37 additions and 8 deletions
|
@ -111,10 +111,8 @@ static struct
|
||||||
int format;
|
int format;
|
||||||
} encodings[] = {
|
} encodings[] = {
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
{ "646", ENCODING_ASCII },
|
|
||||||
{ "ASCII", ENCODING_ASCII },
|
{ "ASCII", ENCODING_ASCII },
|
||||||
{ "US-ASCII", ENCODING_ASCII },
|
{ "US-ASCII", ENCODING_ASCII },
|
||||||
{ "LATIN1", ENCODING_LATIN1 },
|
|
||||||
{ "8859-1", ENCODING_LATIN1 },
|
{ "8859-1", ENCODING_LATIN1 },
|
||||||
{ "ISO-8859-1", ENCODING_LATIN1 },
|
{ "ISO-8859-1", ENCODING_LATIN1 },
|
||||||
{ "UTF8", ENCODING_UTF8 },
|
{ "UTF8", ENCODING_UTF8 },
|
||||||
|
@ -138,6 +136,27 @@ static struct
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
getlocale()
|
||||||
|
{
|
||||||
|
const char *lang;
|
||||||
|
|
||||||
|
lang = SDL_getenv("LC_ALL");
|
||||||
|
if (!lang) {
|
||||||
|
lang = SDL_getenv("LC_CTYPE");
|
||||||
|
}
|
||||||
|
if (!lang) {
|
||||||
|
lang = SDL_getenv("LC_MESSAGES");
|
||||||
|
}
|
||||||
|
if (!lang) {
|
||||||
|
lang = SDL_getenv("LANG");
|
||||||
|
}
|
||||||
|
if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) {
|
||||||
|
lang = "ASCII";
|
||||||
|
}
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_iconv_t
|
SDL_iconv_t
|
||||||
SDL_iconv_open(const char *tocode, const char *fromcode)
|
SDL_iconv_open(const char *tocode, const char *fromcode)
|
||||||
{
|
{
|
||||||
|
@ -145,6 +164,12 @@ SDL_iconv_open(const char *tocode, const char *fromcode)
|
||||||
int dst_fmt = ENCODING_UNKNOWN;
|
int dst_fmt = ENCODING_UNKNOWN;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (!fromcode || !*fromcode) {
|
||||||
|
fromcode = getlocale();
|
||||||
|
}
|
||||||
|
if (!tocode || !*tocode) {
|
||||||
|
fromcode = getlocale();
|
||||||
|
}
|
||||||
for (i = 0; i < SDL_arraysize(encodings); ++i) {
|
for (i = 0; i < SDL_arraysize(encodings); ++i) {
|
||||||
if (SDL_strcasecmp(fromcode, encodings[i].name) == 0) {
|
if (SDL_strcasecmp(fromcode, encodings[i].name) == 0) {
|
||||||
src_fmt = encodings[i].format;
|
src_fmt = encodings[i].format;
|
||||||
|
@ -805,13 +830,17 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
|
||||||
size_t outbytesleft;
|
size_t outbytesleft;
|
||||||
size_t retCode = 0;
|
size_t retCode = 0;
|
||||||
|
|
||||||
if (!fromcode || !*fromcode) {
|
|
||||||
fromcode = getlocale();
|
|
||||||
}
|
|
||||||
if (!tocode || !*tocode) {
|
|
||||||
tocode = getlocale();
|
|
||||||
}
|
|
||||||
cd = SDL_iconv_open(tocode, fromcode);
|
cd = SDL_iconv_open(tocode, fromcode);
|
||||||
|
if (cd == (SDL_iconv_t) - 1) {
|
||||||
|
/* See if we can recover here (fixes iconv on Solaris 11) */
|
||||||
|
if (!tocode || !*tocode) {
|
||||||
|
tocode = "UTF-8";
|
||||||
|
}
|
||||||
|
if (!fromcode || !*fromcode) {
|
||||||
|
tocode = "UTF-8";
|
||||||
|
}
|
||||||
|
cd = SDL_iconv_open(tocode, fromcode);
|
||||||
|
}
|
||||||
if (cd == (SDL_iconv_t) - 1) {
|
if (cd == (SDL_iconv_t) - 1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue