Mercurial > pidgin
comparison src/protocols/irc/parse.c @ 9644:d54f14237255
[gaim-migrate @ 10492]
Converting from utf8 to utf8 on Solaris has problems. Arvind Samptur
pin-pointed the problem and provided a patch. If only car
mechanics were as efficient.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 02 Aug 2004 04:03:48 +0000 |
| parents | d6f398e80b32 |
| children | 6ccd92a58cde |
comparison
equal
deleted
inserted
replaced
| 9643:b8aee06adc83 | 9644:d54f14237255 |
|---|---|
| 199 | 199 |
| 200 static char *irc_send_convert(struct irc_conn *irc, const char *string) | 200 static char *irc_send_convert(struct irc_conn *irc, const char *string) |
| 201 { | 201 { |
| 202 char *utf8; | 202 char *utf8; |
| 203 GError *err = NULL; | 203 GError *err = NULL; |
| 204 | 204 const gchar *charset; |
| 205 utf8 = g_convert(string, strlen(string), | 205 |
| 206 gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET), | 206 charset = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 207 "UTF-8", NULL, NULL, &err); | 207 if (!strcasecmp("UTF-8", charset)) |
| 208 return g_strdup(string); | |
| 209 | |
| 210 utf8 = g_convert(string, strlen(string), charset, "UTF-8", NULL, NULL, &err); | |
| 208 if (err) { | 211 if (err) { |
| 209 gaim_debug(GAIM_DEBUG_ERROR, "irc", "send conversion error: %s\n", err->message); | 212 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message); |
| 210 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Sending raw, which probably isn't right\n"); | 213 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", charset); |
| 211 utf8 = g_strdup(string); | 214 utf8 = g_strdup(string); |
| 212 g_error_free(err); | 215 g_error_free(err); |
| 213 } | 216 } |
| 214 | 217 |
| 215 return utf8; | 218 return utf8; |
| 216 } | 219 } |
| 217 | 220 |
| 218 static char *irc_recv_convert(struct irc_conn *irc, const char *string) | 221 static char *irc_recv_convert(struct irc_conn *irc, const char *string) |
| 219 { | 222 { |
| 220 char *utf8; | 223 char *utf8 = NULL; |
| 221 GError *err = NULL; | 224 GError *err = NULL; |
| 222 | 225 const gchar *charset; |
| 223 utf8 = g_convert(string, strlen(string), "UTF-8", | 226 |
| 224 gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET), | 227 charset = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 225 NULL, NULL, &err); | 228 |
| 229 if (!strcasecmp("UTF-8", charset)) { | |
| 230 if (g_utf8_validate(string, strlen(string), NULL)) | |
| 231 utf8 = g_strdup(string); | |
| 232 } else { | |
| 233 utf8 = g_convert(string, strlen(string), "UTF-8", charset, NULL, NULL, &err); | |
| 234 } | |
| 235 | |
| 226 if (err) { | 236 if (err) { |
| 227 gaim_debug(GAIM_DEBUG_ERROR, "irc", "recv conversion error: %s\n", err->message); | 237 gaim_debug(GAIM_DEBUG_ERROR, "irc", "recv conversion error: %s\n", err->message); |
| 238 g_error_free(err); | |
| 239 } | |
| 240 | |
| 241 if (utf8 == NULL) | |
| 228 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); | 242 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); |
| 229 g_error_free(err); | 243 |
| 230 } | |
| 231 | |
| 232 return utf8; | 244 return utf8; |
| 233 } | 245 } |
| 234 | 246 |
| 235 /* XXX tag closings are not necessarily correctly nested here! If we | 247 /* XXX tag closings are not necessarily correctly nested here! If we |
| 236 * get a ^O or reach the end of the string and there are open | 248 * get a ^O or reach the end of the string and there are open |
