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.
24 #include "util/Compiler.h"
32 * Returns the number of terminal cells occupied by this string.
36 locale_width(const char *p);
38 char *utf8_to_locale(const char *str);
39 char *locale_to_utf8(const char *str);
42 * Converts the UTF-8 string to the locale, and frees the source
43 * pointer. Returns the source pointer as-is if no conversion is
47 replace_utf8_to_locale(char *src);
50 * Converts the locale string to UTF-8, and frees the source pointer.
51 * Returns the source pointer as-is if no conversion is required.
54 replace_locale_to_utf8(char *src);
57 * Convert an UTF-8 string to the locale charset. The source string
58 * must remain valid while this object is used. If no conversion is
59 * necessary, then this class is a no-op.
65 const char *const value;
70 explicit Utf8ToLocale(const char *src)
71 :value(utf8_to_locale(src)) {}
75 Utf8ToLocale(const Utf8ToLocale &) = delete;
76 Utf8ToLocale &operator=(const Utf8ToLocale &) = delete;
78 explicit Utf8ToLocale(const char *src)
82 const char *c_str() const {
88 * Convert an locale charset string to UTF-8. The source string must
89 * remain valid while this object is used. If no conversion is
90 * necessary, then this class is a no-op.
96 const char *const value;
101 explicit LocaleToUtf8(const char *src)
102 :value(locale_to_utf8(src)) {}
106 LocaleToUtf8(const LocaleToUtf8 &) = delete;
107 LocaleToUtf8 &operator=(const LocaleToUtf8 &) = delete;
109 explicit LocaleToUtf8(const char *src)
113 const char *c_str() const {