diff options
author | Max Kellermann <max@duempel.org> | 2008-10-02 19:01:11 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-02 19:01:11 +0200 |
commit | 299b9c138b3104b92fafb47082a220f906946c66 (patch) | |
tree | cee70bce805d28da86f2a37e12bcb616a595e160 /src/charset.c | |
parent | de5c385e46039d2f7410b5ba4a61f92725d7ca9a (diff) | |
download | mpd-299b9c138b3104b92fafb47082a220f906946c66.tar.gz mpd-299b9c138b3104b92fafb47082a220f906946c66.tar.xz mpd-299b9c138b3104b92fafb47082a220f906946c66.zip |
charset: convert strings with fallback
Use g_convert_with_fallback() for charset conversion, and don't print
a status bar message on error.
Diffstat (limited to '')
-rw-r--r-- | src/charset.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/src/charset.c b/src/charset.c index 701fd2105..42c0e6034 100644 --- a/src/charset.c +++ b/src/charset.c @@ -18,14 +18,11 @@ */ #include "charset.h" -#include "i18n.h" #include <assert.h> #include <string.h> #include <glib.h> -extern void screen_status_printf(const char *format, ...); - static bool noconvert = true; static const char *charset; @@ -61,7 +58,6 @@ char * utf8_to_locale(const char *utf8str) { gchar *str; - gsize rb, wb; GError *error; assert(utf8str != NULL); @@ -69,16 +65,11 @@ utf8_to_locale(const char *utf8str) if (noconvert) return g_strdup(utf8str); - rb = 0; /* bytes read */ - wb = 0; /* bytes written */ - error = NULL; - str = g_locale_from_utf8(utf8str, - strlen(utf8str), - &wb, &rb, - &error); - if (error) { - screen_status_printf(_("Error: Unable to convert characters to %s"), - charset); + str = g_convert_with_fallback(utf8str, strlen(utf8str), + charset, "utf-8", + NULL, NULL, NULL, + &error); + if (str == NULL) { g_error_free(error); return g_strdup(utf8str); } @@ -90,7 +81,6 @@ char * locale_to_utf8(const char *localestr) { gchar *str; - gsize rb, wb; GError *error; assert(localestr != NULL); @@ -98,15 +88,11 @@ locale_to_utf8(const char *localestr) if (noconvert) return g_strdup(localestr); - rb = 0; /* bytes read */ - wb = 0; /* bytes written */ - error = NULL; - str = g_locale_to_utf8(localestr, - strlen(localestr), - &wb, &rb, - &error); - if (error) { - screen_status_printf(_("Error: Unable to convert characters to UTF-8")); + str = g_convert_with_fallback(localestr, strlen(localestr), + "utf-8", charset, + NULL, NULL, NULL, + &error); + if (str == NULL) { g_error_free(error); return g_strdup(localestr); } |