diff libpurple/protocols/yahoo/util.c @ 27769:c9b4fdb3fdb1

adapted to the transition to utf-8 of yahoo-jp.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 27 Feb 2008 14:54:42 +0000
parents e9cf897bd873
children 839cc551cad9
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/util.c	Wed Feb 27 12:21:29 2008 +0000
+++ b/libpurple/protocols/yahoo/util.c	Wed Feb 27 14:54:42 2008 +0000
@@ -112,12 +112,13 @@
 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8)
 {
 	struct yahoo_data *yd = gc->proto_data;
-	char *ret, *strtmp;
-	int newlen;
+	char *ret = NULL;
+	size_t newlen;
 	const char *to_codeset;
 
-	if (yd->jp && utf8 && *utf8)
-		*utf8 = FALSE;
+	if (yd->jp && utf8 && *utf8) {
+		return botch_utf((gchar *)str, strlen((gchar *)str), &newlen);
+	}
 
 	if (utf8 && *utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */
 		return g_strdup(str);
@@ -127,12 +128,7 @@
 	else
 		to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
 
-//	strtmp = sanitize_utf((char *)str, strlen((char *)str), &newlen);
-    strtmp = g_strdup(str);
-
-	ret = g_convert_with_fallback(strtmp, strlen(strtmp), to_codeset, "UTF-8", "?", NULL, NULL, NULL);
-
-	g_free(strtmp);
+	ret = g_convert_with_fallback(str, strlen(str), to_codeset, "UTF-8", "?", NULL, NULL, NULL);
 
 	if (ret)
 		return ret;
@@ -153,14 +149,15 @@
 	struct yahoo_data *yd = gc->proto_data;
 	char *ret, *tmp;
 	char *from_codeset;
-	int newlen;
+	size_t newlen;
 
 	if (utf8) {
-		if (g_utf8_validate(str, -1, NULL))
-			return g_strdup(str);
+		ret = sanitize_utf((gchar *)str, strlen((gchar *)str), &newlen);
+		if (g_utf8_validate(ret, -1, NULL))
+			return ret;
 	}
 
-	if (yd->jp)
+	if (yd->jp && !utf8)
 		from_codeset = "SHIFT_JIS";
 	else
 		from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
@@ -176,8 +173,7 @@
 
 	if (ret){
 		tmp = ret;
-//		ret = botch_utf(tmp, strlen(tmp), &newlen);
-        ret = g_strdup(tmp);
+		ret = sanitize_utf((gchar *)tmp, strlen((gchar *)tmp), &newlen);
 		g_free(tmp);
 		return ret;
 	}