diff options
author | Max Kellermann <max@duempel.org> | 2008-10-15 19:36:30 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-15 19:36:30 +0200 |
commit | 8746a58ab93f0662bf1e8b91a36c261822ffeed5 (patch) | |
tree | ecacc9d8c682cb2621cbd8d3298ef7e3ee056542 /src/path.c | |
parent | e89599eaad23990973efd43f01cb802917a31cff (diff) | |
download | mpd-8746a58ab93f0662bf1e8b91a36c261822ffeed5.tar.gz mpd-8746a58ab93f0662bf1e8b91a36c261822ffeed5.tar.xz mpd-8746a58ab93f0662bf1e8b91a36c261822ffeed5.zip |
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.
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 54 |
1 files changed, 30 insertions, 24 deletions
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 <glib.h> + 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"); |