From 8746a58ab93f0662bf1e8b91a36c261822ffeed5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Oct 2008 19:36:30 +0200 Subject: path, tag_id3: use g_convert() instead of charConv.c GLib provides an easier API for character set conversion than iconv(). Use g_convert() / g_convert_with_fallback() for all character conversions. We should optimize the path.h API later to return a newly allocated buffer, so we can just pass GLib's return value. --- src/path.c | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index 8d1b0018d..0728aee64 100644 --- a/src/path.c +++ b/src/path.c @@ -18,7 +18,6 @@ #include "path.h" #include "log.h" -#include "charConv.h" #include "conf.h" #include "utf8.h" #include "utils.h" @@ -32,28 +31,48 @@ #endif #endif +#include + const char *musicDir; static const char *playlistDir; static size_t music_dir_len; static size_t playlist_dir_len; static char *fsCharset; -static char *path_conv_charset(char *dest, const char *to, - const char *from, const char *str) -{ - return setCharSetConversion(to, from) ? NULL : char_conv_str(dest, str); -} - char *fs_charset_to_utf8(char *dst, const char *str) { - char *ret = path_conv_charset(dst, "UTF-8", fsCharset, str); - return (ret && !validUtf8String(ret, strlen(ret))) ? NULL : ret; + gchar *p; + GError *error = NULL; + + p = g_convert(str, -1, + fsCharset, "utf-8", + NULL, NULL, &error); + if (p == NULL) + /* no fallback */ + return NULL; + + g_strlcpy(dst, p, MPD_PATH_MAX); + g_free(p); + return dst; } char *utf8_to_fs_charset(char *dst, const char *str) { - char *ret = path_conv_charset(dst, fsCharset, "UTF-8", str); - return ret ? ret : strcpy(dst, str); + gchar *p; + GError *error = NULL; + + p = g_convert(str, -1, + "utf-8", fsCharset, + NULL, NULL, &error); + if (p == NULL) { + /* fall back to UTF-8 */ + g_error_free(error); + return strcpy(dst, str); + } + + g_strlcpy(dst, p, MPD_PATH_MAX); + g_free(p); + return dst; } void setFsCharset(const char *charset) @@ -67,19 +86,6 @@ void setFsCharset(const char *charset) DEBUG("setFsCharset: fs charset is: %s\n", fsCharset); - if (setCharSetConversion("UTF-8", fsCharset) != 0) { - WARNING("fs charset conversion problem: " - "not able to convert from \"%s\" to \"%s\"\n", - fsCharset, "UTF-8"); - error = 1; - } - if (setCharSetConversion(fsCharset, "UTF-8") != 0) { - WARNING("fs charset conversion problem: " - "not able to convert from \"%s\" to \"%s\"\n", - "UTF-8", fsCharset); - error = 1; - } - if (error) { free(fsCharset); WARNING("setting fs charset to ISO-8859-1!\n"); -- cgit v1.2.3