blocxx
IConv.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2005 Novell, Inc. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6*
7* - Redistributions of source code must retain the above copyright notice,
8* this list of conditions and the following disclaimer.
9*
10* - Redistributions in binary form must reproduce the above copyright notice,
11* this list of conditions and the following disclaimer in the documentation
12* and/or other materials provided with the distribution.
13*
14* - Neither the name of Novell, Inc., nor the names of its
15* contributors may be used to endorse or promote products derived from this
16* software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc., OR THE
22* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*******************************************************************************/
33
34#ifndef BLOCXX_ICONV_HPP_INCLUDE_GUARD_HPP_
35#define BLOCXX_ICONV_HPP_INCLUDE_GUARD_HPP_
36#include "blocxx/BLOCXX_config.h"
37
38#if defined(BLOCXX_HAVE_ICONV_SUPPORT)
39#include "blocxx/String.hpp"
40#include "blocxx/Array.hpp"
41#include <string>
42#include <iconv.h>
43
44namespace BLOCXX_NAMESPACE
45{
46
51class BLOCXX_COMMON_API IConv_t
52{
53public:
57 IConv_t();
58
71 IConv_t(const String &fromEncoding, const String &toEncoding);
72
76 ~IConv_t();
77
88 bool open(const String &fromEncoding, const String &toEncoding);
89
104 size_t convert(char **istr, size_t *ibytesleft,
105 char **ostr, size_t *obytesleft);
106
114 bool close();
115
116private:
117 iconv_t m_iconv;
118};
119
124namespace IConv
125{
138 BLOCXX_COMMON_API String
139 fromByteString(const String &enc, const char *str, size_t len);
140
152 BLOCXX_COMMON_API String
153 fromByteString(const String &enc, const std::string &str);
154
155#ifdef BLOCXX_HAVE_STD_WSTRING
167 BLOCXX_COMMON_API String
168 fromWideString(const String &enc, const std::wstring &str);
169#endif
170
182 BLOCXX_COMMON_API std::string
183 toByteString(const String &enc, const String &utf8);
184
185#ifdef BLOCXX_HAVE_STD_WSTRING
197 BLOCXX_COMMON_API std::wstring
198 toWideString(const String &enc, const String &utf8);
199#endif
200
201#if 0
202 /*
203 * Retrieve an array of supported encoding names.
204 *
205 * @return array with supported encoding names.
206 */
207 BLOCXX_COMMON_API StringArray
208 encodings();
209#endif
210
211} // End of IConv namespace
212} // End of BLOCXX_NAMESPACE
213
214#endif // BLOCXX_HAVE_ICONV_SUPPORT
215#endif // INCLUDE_GUARD_HPP_
216
217/* vim: set ts=8 sts=8 sw=8 ai noet: */
218
BLOCXX_COMMON_API int close(const FileHandle &hdl)
Close file handle.
Taken from RFC 1321.
Array< String > StringArray
Definition CommonFwd.hpp:73