diff options
Diffstat (limited to 'src/fs/Charset.cxx')
-rw-r--r-- | src/fs/Charset.cxx | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/fs/Charset.cxx b/src/fs/Charset.cxx index dad5779f9..2d289c3b8 100644 --- a/src/fs/Charset.cxx +++ b/src/fs/Charset.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -22,11 +22,14 @@ #include "Domain.hxx" #include "Limits.hxx" #include "system/FatalError.hxx" -#include "util/Error.hxx" -#include "util/Domain.hxx" #include "Log.hxx" +#include "Traits.hxx" +#ifdef HAVE_GLIB #include <glib.h> +#endif + +#include <algorithm> #include <assert.h> #include <string.h> @@ -41,6 +44,7 @@ */ static constexpr size_t MPD_PATH_MAX_UTF8 = (MPD_PATH_MAX - 1) * 4 + 1; +#ifdef HAVE_GLIB static std::string fs_charset; gcc_pure @@ -70,10 +74,29 @@ SetFSCharset(const char *charset) "SetFSCharset: fs charset is: %s", fs_charset.c_str()); } +#endif + const char * GetFSCharset() { - return fs_charset.empty() ? "utf-8" : fs_charset.c_str(); +#ifdef HAVE_GLIB + return fs_charset.empty() ? "UTF-8" : fs_charset.c_str(); +#else + return "UTF-8"; +#endif +} + +static inline void FixSeparators(std::string &s) +{ +#ifdef WIN32 + // For whatever reason GCC can't convert constexpr to value reference. + // This leads to link errors when passing separators directly. + auto from = PathTraitsFS::SEPARATOR; + auto to = PathTraitsUTF8::SEPARATOR; + std::replace(s.begin(), s.end(), from, to); +#else + (void)s; +#endif } std::string @@ -81,8 +104,14 @@ PathToUTF8(const char *path_fs) { assert(path_fs != nullptr); - if (fs_charset.empty()) - return std::string(path_fs); +#ifdef HAVE_GLIB + if (fs_charset.empty()) { +#endif + auto result = std::string(path_fs); + FixSeparators(result); + return result; +#ifdef HAVE_GLIB + } GIConv conv = g_iconv_open("utf-8", fs_charset.c_str()); if (conv == reinterpret_cast<GIConv>(-1)) @@ -103,9 +132,14 @@ PathToUTF8(const char *path_fs) if (ret == static_cast<size_t>(-1) || in_left > 0) return std::string(); - return std::string(path_utf8, sizeof(path_utf8) - out_left); + auto result_path = std::string(path_utf8, sizeof(path_utf8) - out_left); + FixSeparators(result_path); + return result_path; +#endif } +#ifdef HAVE_GLIB + char * PathFromUTF8(const char *path_utf8) { @@ -118,3 +152,5 @@ PathFromUTF8(const char *path_utf8) fs_charset.c_str(), "utf-8", nullptr, nullptr, nullptr); } + +#endif |