1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2018 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "charset.hxx"
21 #include "util/ScopeExit.hxx"
22 #include "util/StringUTF8.hxx"
29 static bool noconvert = true;
30 static const char *charset;
35 noconvert = g_get_charset(&charset);
41 locale_width(const char *p)
43 #if defined(ENABLE_LOCALE) && defined(ENABLE_MULTIBYTE)
49 utf8 = locale_to_utf8(p);
50 AtScopeExit(utf8) { g_free(utf8); };
52 return utf8_width(utf8);
59 utf8_to_locale(const char *utf8str)
62 assert(utf8str != nullptr);
65 return g_strdup(utf8str);
67 gchar *str = g_convert_with_fallback(utf8str, -1,
69 nullptr, nullptr, nullptr, nullptr);
71 return g_strdup(utf8str);
75 return g_strdup(utf8str);
80 locale_to_utf8(const char *localestr)
83 assert(localestr != nullptr);
86 return g_strdup(localestr);
88 gchar *str = g_convert_with_fallback(localestr, -1,
90 nullptr, nullptr, nullptr, nullptr);
92 return g_strdup(localestr);
96 return g_strdup(localestr);
101 replace_utf8_to_locale(char *src)
104 assert(src != nullptr);
109 AtScopeExit(src) { g_free(src); };
110 return utf8_to_locale(src);
118 replace_locale_to_utf8(char *src)
121 assert(src != nullptr);
126 AtScopeExit(src) { g_free(src); };
127 return locale_to_utf8(src);
135 Utf8ToLocale::~Utf8ToLocale()
140 LocaleToUtf8::~LocaleToUtf8()