ncmpc  0.31
charset.hxx
Go to the documentation of this file.
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2018 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
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.
9  *
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.
14  *
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.
18  */
19 
20 #ifndef CHARSET_H
21 #define CHARSET_H
22 
23 #include "config.h"
24 #include "util/Compiler.h"
25 
26 #ifdef ENABLE_LOCALE
27 const char *
28 charset_init();
29 #endif
30 
31 char *utf8_to_locale(const char *str);
32 char *locale_to_utf8(const char *str);
33 
39 char *
40 replace_utf8_to_locale(char *src);
41 
46 char *
47 replace_locale_to_utf8(char *src);
48 
54 class Utf8ToLocale {
55 #ifdef ENABLE_LOCALE
56  char *const value;
57 #else
58  const char *const value;
59 #endif
60 
61 public:
62 #ifdef ENABLE_LOCALE
63  explicit Utf8ToLocale(const char *src)
64  :value(utf8_to_locale(src)) {}
65 
66  ~Utf8ToLocale();
67 
68  Utf8ToLocale(const Utf8ToLocale &) = delete;
69  Utf8ToLocale &operator=(const Utf8ToLocale &) = delete;
70 #else
71  explicit Utf8ToLocale(const char *src)
72  :value(src) {}
73 #endif
74 
75  const char *c_str() const {
76  return value;
77  }
78 };
79 
85 class LocaleToUtf8 {
86 #ifdef ENABLE_LOCALE
87  char *const value;
88 #else
89  const char *const value;
90 #endif
91 
92 public:
93 #ifdef ENABLE_LOCALE
94  explicit LocaleToUtf8(const char *src)
95  :value(locale_to_utf8(src)) {}
96 
97  ~LocaleToUtf8();
98 
99  LocaleToUtf8(const LocaleToUtf8 &) = delete;
100  LocaleToUtf8 &operator=(const LocaleToUtf8 &) = delete;
101 #else
102  explicit LocaleToUtf8(const char *src)
103  :value(src) {}
104 #endif
105 
106  const char *c_str() const {
107  return value;
108  }
109 };
110 
111 #endif
LocaleToUtf8(const char *src)
Definition: charset.hxx:102
const char * c_str() const
Definition: charset.hxx:106
Definition: charset.hxx:54
char * utf8_to_locale(const char *str)
Utf8ToLocale(const char *src)
Definition: charset.hxx:71
char * replace_locale_to_utf8(char *src)
char * locale_to_utf8(const char *str)
char * replace_utf8_to_locale(char *src)
const char * c_str() const
Definition: charset.hxx:75
Definition: charset.hxx:85