src/stdlib/SDL_iconv.c
branchSDL-1.2
changeset 4053 0aadbc81c497
parent 3998 098ac044cd2f
child 4054 64bf737873a2
     1.1 --- a/src/stdlib/SDL_iconv.c	Thu Jul 12 05:30:17 2007 +0000
     1.2 +++ b/src/stdlib/SDL_iconv.c	Thu Jul 12 07:29:19 2007 +0000
     1.3 @@ -107,10 +107,8 @@
     1.4  	const char *name;
     1.5  	int format;
     1.6  } encodings[] = {
     1.7 -	{ "646",	ENCODING_ASCII },
     1.8  	{ "ASCII",	ENCODING_ASCII },
     1.9  	{ "US-ASCII",	ENCODING_ASCII },
    1.10 -	{ "LATIN1",	ENCODING_LATIN1 },
    1.11  	{ "8859-1",	ENCODING_LATIN1 },
    1.12  	{ "ISO-8859-1",	ENCODING_LATIN1 },
    1.13  	{ "UTF8",	ENCODING_UTF8 },
    1.14 @@ -133,12 +131,38 @@
    1.15  	{ "UCS-4",	ENCODING_UCS4 },
    1.16  };
    1.17  
    1.18 +static const char *getlocale()
    1.19 +{
    1.20 +	const char *lang;
    1.21 +
    1.22 +	lang = SDL_getenv("LC_ALL");
    1.23 +	if ( !lang ) {
    1.24 +		lang = SDL_getenv("LC_CTYPE");
    1.25 +	}
    1.26 +	if ( !lang ) {
    1.27 +		lang = SDL_getenv("LC_MESSAGES");
    1.28 +	}
    1.29 +	if ( !lang ) {
    1.30 +		lang = SDL_getenv("LANG");
    1.31 +	}
    1.32 +	if ( !lang || !*lang || SDL_strcmp(lang, "C") == 0 ) {
    1.33 +		lang = "ASCII";
    1.34 +	}
    1.35 +	return lang;
    1.36 +}
    1.37 +
    1.38  SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
    1.39  {
    1.40  	int src_fmt = ENCODING_UNKNOWN;
    1.41  	int dst_fmt = ENCODING_UNKNOWN;
    1.42  	int i;
    1.43  
    1.44 +	if ( !fromcode || !*fromcode ) {
    1.45 +		fromcode = getlocale();
    1.46 +	}
    1.47 +	if ( !tocode || !*tocode ) {
    1.48 +		fromcode = getlocale();
    1.49 +	}
    1.50  	for ( i = 0; i < SDL_arraysize(encodings); ++i ) {
    1.51  		if ( SDL_strcasecmp(fromcode, encodings[i].name) == 0 ) {
    1.52  			src_fmt = encodings[i].format;
    1.53 @@ -772,26 +796,6 @@
    1.54  
    1.55  #endif /* !HAVE_ICONV */
    1.56  
    1.57 -static const char *getlocale()
    1.58 -{
    1.59 -	const char *lang;
    1.60 -
    1.61 -	lang = SDL_getenv("LC_ALL");
    1.62 -	if ( !lang ) {
    1.63 -		lang = SDL_getenv("LC_CTYPE");
    1.64 -	}
    1.65 -	if ( !lang ) {
    1.66 -		lang = SDL_getenv("LC_MESSAGES");
    1.67 -	}
    1.68 -	if ( !lang ) {
    1.69 -		lang = SDL_getenv("LANG");
    1.70 -	}
    1.71 -	if ( !lang || SDL_strcmp(lang, "C") == 0 ) {
    1.72 -		lang = "ASCII";
    1.73 -	}
    1.74 -	return lang;
    1.75 -}
    1.76 -
    1.77  char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
    1.78  {
    1.79  	SDL_iconv_t cd;
    1.80 @@ -801,12 +805,6 @@
    1.81  	size_t outbytesleft;
    1.82  	size_t retCode = 0;
    1.83  
    1.84 -	if ( !fromcode || !*fromcode ) {
    1.85 -		fromcode = getlocale();
    1.86 -	}
    1.87 -	if ( !tocode || !*tocode ) {
    1.88 -		tocode = getlocale();
    1.89 -	}
    1.90  	cd = SDL_iconv_open(tocode, fromcode);
    1.91  	if ( cd == (SDL_iconv_t)-1 ) {
    1.92  		return NULL;