ncmpc  0.30
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 "Compiler.h"
25 
26 #ifdef ENABLE_LOCALE
27 const char *
28 charset_init();
29 #endif
30 
35 unsigned
36 utf8_width(const char *str);
37 
42 unsigned
43 locale_width(const char *p);
44 
51 unsigned
52 utf8_cut_width(char *p, unsigned max_width);
53 
54 char *utf8_to_locale(const char *str);
55 char *locale_to_utf8(const char *str);
56 
62 char *
63 replace_utf8_to_locale(char *src);
64 
69 char *
70 replace_locale_to_utf8(char *src);
71 
77 class Utf8ToLocale {
78 #ifdef ENABLE_LOCALE
79  char *const value;
80 #else
81  const char *const value;
82 #endif
83 
84 public:
85 #ifdef ENABLE_LOCALE
86  explicit Utf8ToLocale(const char *src)
87  :value(utf8_to_locale(src)) {}
88 
89  ~Utf8ToLocale();
90 
91  Utf8ToLocale(const Utf8ToLocale &) = delete;
92  Utf8ToLocale &operator=(const Utf8ToLocale &) = delete;
93 #else
94  explicit Utf8ToLocale(const char *src)
95  :value(src) {}
96 #endif
97 
98  const char *c_str() const {
99  return value;
100  }
101 };
102 
109 #ifdef ENABLE_LOCALE
110  char *const value;
111 #else
112  const char *const value;
113 #endif
114 
115 public:
116 #ifdef ENABLE_LOCALE
117  explicit LocaleToUtf8(const char *src)
118  :value(locale_to_utf8(src)) {}
119 
120  ~LocaleToUtf8();
121 
122  LocaleToUtf8(const LocaleToUtf8 &) = delete;
123  LocaleToUtf8 &operator=(const LocaleToUtf8 &) = delete;
124 #else
125  explicit LocaleToUtf8(const char *src)
126  :value(src) {}
127 #endif
128 
129  const char *c_str() const {
130  return value;
131  }
132 };
133 
134 #endif
LocaleToUtf8(const char *src)
Definition: charset.hxx:125
const char * c_str() const
Definition: charset.hxx:129
Definition: charset.hxx:77
char * utf8_to_locale(const char *str)
Utf8ToLocale(const char *src)
Definition: charset.hxx:94
char * replace_locale_to_utf8(char *src)
char * locale_to_utf8(const char *str)
char * replace_utf8_to_locale(char *src)
gcc_pure unsigned locale_width(const char *p)
unsigned utf8_cut_width(char *p, unsigned max_width)
const char * c_str() const
Definition: charset.hxx:98
gcc_pure unsigned utf8_width(const char *str)
#define gcc_pure
Definition: Compiler.h:101
Definition: charset.hxx:108