comparison src/list.c @ 4458:a46c57f2d58b

[gaim-migrate @ 4733] (20:45:09) Trogdor: http://web.ics.purdue.edu/~eblanton/gaim/gaim-cvs-oscar-ssi-conv.diff (20:45:12) Trogdor: commit please (20:45:22) LSchiere: commit log? (20:45:48) Trogdor: Adds best-effort charset conversion to Oscar SSI aliases and group names. (20:45:55) Trogdor: oh (20:46:19) Trogdor: Also adds a gaim global function gaim_try_conv_to_utf8 () for attempting several logical encodings on a given string. (20:46:43) Trogdor: (which replaces the aptly named whatever_to_utf8) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 29 Jan 2003 01:46:44 +0000
parents fd83159169db
children 3196d9044a45
comparison
equal deleted inserted replaced
4457:16e0c6826f23 4458:a46c57f2d58b
39 #include "win32dep.h" 39 #include "win32dep.h"
40 #endif 40 #endif
41 41
42 #define PATHSIZE 1024 42 #define PATHSIZE 1024
43 43
44 /* This guy does its best to convert a string to UTF-8 from an unknown
45 * encoding by checking the locale and trying some sane defaults ...
46 * if everything fails it returns NULL. */
47 static char *whatever_to_utf8(const char *str);
48
49 void remove_buddy(struct buddy *rem_b) 44 void remove_buddy(struct buddy *rem_b)
50 { 45 {
51 if(rem_b->user->gc) { 46 if(rem_b->user->gc) {
52 struct group *rem_g = find_group_by_buddy(rem_b); 47 struct group *rem_g = find_group_by_buddy(rem_b);
53 48
261 do { 256 do {
262 if (c == NULL) 257 if (c == NULL)
263 break; 258 break;
264 if (*c == 'g') { 259 if (*c == 'g') {
265 char *utf8 = NULL; 260 char *utf8 = NULL;
266 utf8 = whatever_to_utf8(c + 2); 261 utf8 = gaim_try_conv_to_utf8(c + 2);
267 if (utf8 == NULL) { 262 if (utf8 == NULL) {
268 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); 263 g_strlcpy(current, _("Invalid Groupname"), sizeof(current));
269 } else { 264 } else {
270 g_strlcpy(current, utf8, sizeof(current)); 265 g_strlcpy(current, utf8, sizeof(current));
271 g_free(utf8); 266 g_free(utf8);
280 *a++ = '\0'; /* nul the : */ 275 *a++ = '\0'; /* nul the : */
281 } 276 }
282 277
283 g_strlcpy(nm, c + 2, sizeof(nm)); 278 g_strlcpy(nm, c + 2, sizeof(nm));
284 if (a) { 279 if (a) {
285 utf8 = whatever_to_utf8(a); 280 utf8 = gaim_try_conv_to_utf8(a);
286 if (utf8 == NULL) { 281 if (utf8 == NULL) {
287 debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm); 282 debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm);
288 } 283 }
289 } 284 }
290 if (utf8 == NULL) { 285 if (utf8 == NULL) {
1208 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { 1203 char *gaim_buddy_get_setting(struct buddy *b, const char *key) {
1209 if(!b) 1204 if(!b)
1210 return NULL; 1205 return NULL;
1211 return g_strdup(g_hash_table_lookup(b->settings, key)); 1206 return g_strdup(g_hash_table_lookup(b->settings, key));
1212 } 1207 }
1213
1214 static char *whatever_to_utf8(const char *str)
1215 {
1216 int converted;
1217 char *utf8;
1218
1219 if (g_utf8_validate(str, -1, NULL)) {
1220 return g_strdup(str);
1221 }
1222
1223 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
1224 if (utf8 && converted == strlen (str)) {
1225 return(utf8);
1226 } else if (utf8) {
1227 g_free(utf8);
1228 }
1229
1230 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
1231 if (utf8 && converted == strlen (str)) {
1232 return(utf8);
1233 } else if (utf8) {
1234 g_free(utf8);
1235 }
1236
1237 return(NULL);
1238 }