MPD  0.20.6
Converter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.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 MPD_ICU_CONVERTER_HXX
21 #define MPD_ICU_CONVERTER_HXX
22 
23 #include "check.h"
24 #include "Compiler.h"
25 
26 #ifdef HAVE_ICU
27 #include "thread/Mutex.hxx"
28 #define HAVE_ICU_CONVERTER
29 #elif defined(HAVE_ICONV)
30 #include <iconv.h>
31 #define HAVE_ICU_CONVERTER
32 #endif
33 
34 #ifdef HAVE_ICU_CONVERTER
35 
36 #ifdef HAVE_ICU
37 struct UConverter;
38 #endif
39 
40 template<typename T> class AllocatedString;
41 
46 class IcuConverter {
47 #ifdef HAVE_ICU
48 
52  mutable Mutex mutex;
53 
54  UConverter *const converter;
55 
56  IcuConverter(UConverter *_converter):converter(_converter) {}
57 #elif defined(HAVE_ICONV)
58  const iconv_t to_utf8, from_utf8;
59 
60  IcuConverter(iconv_t _to, iconv_t _from)
61  :to_utf8(_to), from_utf8(_from) {}
62 #endif
63 
64 public:
65 #ifdef HAVE_ICU
66  ~IcuConverter();
67 #elif defined(HAVE_ICONV)
68  ~IcuConverter() {
69  iconv_close(to_utf8);
70  iconv_close(from_utf8);
71  }
72 #endif
73 
77  static IcuConverter *Create(const char *charset);
78 
85  AllocatedString<char> ToUTF8(const char *s) const;
86 
93  AllocatedString<char> FromUTF8(const char *s) const;
94 };
95 
96 #endif
97 
98 #endif
#define gcc_nonnull_all
Definition: Compiler.h:122
Definition: Mutex.hxx:43
A string pointer whose memory is managed by this class.
Definition: Collate.hxx:26
#define gcc_pure
Definition: Compiler.h:116