Mercurial > sdl-ios-xcode
comparison src/stdlib/SDL_iconv.c @ 2184:8f8516e79a13
Merged Ryan's patch from revision 3238 in SDL 1.2
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 12 Jul 2007 08:07:30 +0000 |
parents | 9f31740cad2e |
children | 99210400e8b9 |
comparison
equal
deleted
inserted
replaced
2183:9f31740cad2e | 2184:8f8516e79a13 |
---|---|
135 { "UCS-4", ENCODING_UCS4 }, | 135 { "UCS-4", ENCODING_UCS4 }, |
136 /* *INDENT-ON* */ | 136 /* *INDENT-ON* */ |
137 }; | 137 }; |
138 | 138 |
139 static const char * | 139 static const char * |
140 getlocale() | 140 getlocale(char *buffer, size_t bufsize) |
141 { | 141 { |
142 const char *lang; | 142 const char *lang; |
143 char *ptr; | |
143 | 144 |
144 lang = SDL_getenv("LC_ALL"); | 145 lang = SDL_getenv("LC_ALL"); |
145 if (!lang) { | 146 if (!lang) { |
146 lang = SDL_getenv("LC_CTYPE"); | 147 lang = SDL_getenv("LC_CTYPE"); |
147 } | 148 } |
152 lang = SDL_getenv("LANG"); | 153 lang = SDL_getenv("LANG"); |
153 } | 154 } |
154 if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) { | 155 if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) { |
155 lang = "ASCII"; | 156 lang = "ASCII"; |
156 } | 157 } |
157 return lang; | 158 |
159 /* We need to trim down strings like "en_US.UTF-8@blah" to "UTF-8" */ | |
160 ptr = SDL_strchr(lang, '.'); | |
161 if (ptr != NULL) { | |
162 lang = ptr + 1; | |
163 } | |
164 | |
165 SDL_strlcpy(buffer, lang, bufsize); | |
166 ptr = SDL_strchr(buffer, '@'); | |
167 if (ptr != NULL) { | |
168 *ptr = '\0'; /* chop end of string. */ | |
169 } | |
170 | |
171 return buffer; | |
158 } | 172 } |
159 | 173 |
160 SDL_iconv_t | 174 SDL_iconv_t |
161 SDL_iconv_open(const char *tocode, const char *fromcode) | 175 SDL_iconv_open(const char *tocode, const char *fromcode) |
162 { | 176 { |
163 int src_fmt = ENCODING_UNKNOWN; | 177 int src_fmt = ENCODING_UNKNOWN; |
164 int dst_fmt = ENCODING_UNKNOWN; | 178 int dst_fmt = ENCODING_UNKNOWN; |
165 int i; | 179 int i; |
180 char fromcode_buffer[64]; | |
181 char tocode_buffer[64]; | |
166 | 182 |
167 if (!fromcode || !*fromcode) { | 183 if (!fromcode || !*fromcode) { |
168 fromcode = getlocale(); | 184 fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer)); |
169 } | 185 } |
170 if (!tocode || !*tocode) { | 186 if (!tocode || !*tocode) { |
171 fromcode = getlocale(); | 187 tocode = getlocale(tocode_buffer, sizeof(tocode_buffer)); |
172 } | 188 } |
173 for (i = 0; i < SDL_arraysize(encodings); ++i) { | 189 for (i = 0; i < SDL_arraysize(encodings); ++i) { |
174 if (SDL_strcasecmp(fromcode, encodings[i].name) == 0) { | 190 if (SDL_strcasecmp(fromcode, encodings[i].name) == 0) { |
175 src_fmt = encodings[i].format; | 191 src_fmt = encodings[i].format; |
176 if (dst_fmt != ENCODING_UNKNOWN) { | 192 if (dst_fmt != ENCODING_UNKNOWN) { |