From 3cdf50170ff5117a3d250ea04477ebdbc1d4bbba Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Wed, 20 Sep 2006 23:04:40 +0000 Subject: [PATCH] Add public is_utf8 function by refactoring existing code. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4368 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/recode.c | 13 +++++++++++-- src/core/recode.h | 1 + src/fe-common/core/formats.c | 16 +++------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/core/recode.c b/src/core/recode.c index 5bf05f9d..d15fc90b 100644 --- a/src/core/recode.c +++ b/src/core/recode.c @@ -25,7 +25,6 @@ #include "lib-config/iconfig.h" #include "misc.h" -#ifdef HAVE_GLIB2 static gboolean recode_get_charset(const char **charset) { *charset = settings_get_str("term_charset"); @@ -33,9 +32,19 @@ static gboolean recode_get_charset(const char **charset) /* we use the same test as in src/fe-text/term.c:123 */ return !g_strcasecmp(*charset, "utf-8"); +#ifdef HAVE_GLIB2 return g_get_charset(charset); -} +#else + return FALSE; #endif +} + +gboolean is_utf8(void) +{ + const char *charset; + + return recode_get_charset(&charset); +} static gboolean is_translit(const char *charset) { diff --git a/src/core/recode.h b/src/core/recode.h index f6c59e7c..9698ae2f 100644 --- a/src/core/recode.h +++ b/src/core/recode.h @@ -4,6 +4,7 @@ char *recode_in (const SERVER_REC *server, const char *str, const char *target); char *recode_out (const SERVER_REC *server, const char *str, const char *target); gboolean is_valid_charset(const char *charset); +gboolean is_utf8(void); void recode_init (void); void recode_deinit (void); diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c index 3fcb8066..ccfad968 100644 --- a/src/fe-common/core/formats.c +++ b/src/fe-common/core/formats.c @@ -33,6 +33,7 @@ #include "themes.h" #include "translation.h" #ifdef HAVE_GLIB2 +#include "recode.h" #include "utf8.h" #endif @@ -299,17 +300,6 @@ void format_create_dest_tag(TEXT_DEST_REC *dest, void *server, window_find_closest(server, target, level); } #ifdef HAVE_GLIB2 -static gboolean term_is_utf8 (void) -{ - const char *charset; - - charset = settings_get_str("term_charset"); - if (*charset) - return ! g_strcasecmp(charset, "utf-8"); - - return g_get_charset(&charset); -} - static int advance (char const **str, gboolean utf8) { if (utf8) { @@ -338,7 +328,7 @@ int format_get_length(const char *str) g_return_val_if_fail(str != NULL, 0); #ifdef HAVE_GLIB2 - utf8 = term_is_utf8() && g_utf8_validate(str, -1, NULL); + utf8 = is_utf8() && g_utf8_validate(str, -1, NULL); #endif tmp = g_string_new(NULL); @@ -382,7 +372,7 @@ int format_real_length(const char *str, int len) g_return_val_if_fail(len >= 0, 0); #ifdef HAVE_GLIB2 - utf8 = term_is_utf8() && g_utf8_validate(str, -1, NULL); + utf8 = is_utf8() && g_utf8_validate(str, -1, NULL); #endif start = str;