From cce9683658d89b7b2b5cd5ab5ca598b3627bb1ec Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Sun, 9 Dec 2007 16:10:07 +0000 Subject: [PATCH] Simplify is_valid_charset by just checking with g_iconv_open that the conversion is supported. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4665 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/recode.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/recode.c b/src/core/recode.c index a2ff2e26..77ae10c5 100644 --- a/src/core/recode.c +++ b/src/core/recode.c @@ -52,10 +52,8 @@ static gboolean is_translit(const char *charset) gboolean is_valid_charset(const char *charset) { - const char *from="UTF-8"; - const char *str="irssi"; - char *recoded, *to = NULL; - gboolean valid; + GIConv cd; + char *to = NULL; if (!charset || *charset == '\0') return FALSE; @@ -63,11 +61,13 @@ gboolean is_valid_charset(const char *charset) if (settings_get_bool("recode_transliterate") && !is_translit(charset)) charset = to = g_strconcat(charset, "//TRANSLIT", NULL); - recoded = g_convert(str, strlen(str), charset, from, NULL, NULL, NULL); - valid = (recoded != NULL); - g_free(recoded); + cd = g_iconv_open(charset, "UTF-8"); g_free(to); - return valid; + if (cd != (GIConv)-1) { + g_iconv_close(cd); + return TRUE; + } + return FALSE; } static char *find_conversion(const SERVER_REC *server, const char *target)