blocxx
|
00001 /******************************************************************************* 00002 * Copyright (C) 2005 Novell, Inc. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, 00008 * this list of conditions and the following disclaimer. 00009 * 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 00014 * - Neither the name of Novell, Inc., nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc., OR THE 00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00025 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00027 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00028 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 *******************************************************************************/ 00034 #ifndef BLOCXX_ICONV_HPP_INCLUDE_GUARD_HPP_ 00035 #define BLOCXX_ICONV_HPP_INCLUDE_GUARD_HPP_ 00036 #include "blocxx/BLOCXX_config.h" 00037 00038 #if defined(BLOCXX_HAVE_ICONV_SUPPORT) 00039 #include "blocxx/String.hpp" 00040 #include "blocxx/Array.hpp" 00041 #include <string> 00042 #include <iconv.h> 00043 00044 namespace BLOCXX_NAMESPACE 00045 { 00046 00051 class BLOCXX_COMMON_API IConv_t 00052 { 00053 public: 00057 IConv_t(); 00058 00071 IConv_t(const String &fromEncoding, const String &toEncoding); 00072 00076 ~IConv_t(); 00077 00088 bool open(const String &fromEncoding, const String &toEncoding); 00089 00104 size_t convert(char **istr, size_t *ibytesleft, 00105 char **ostr, size_t *obytesleft); 00106 00114 bool close(); 00115 00116 private: 00117 iconv_t m_iconv; 00118 }; 00119 00124 namespace IConv 00125 { 00138 BLOCXX_COMMON_API String 00139 fromByteString(const String &enc, const char *str, size_t len); 00140 00152 BLOCXX_COMMON_API String 00153 fromByteString(const String &enc, const std::string &str); 00154 00155 #ifdef BLOCXX_HAVE_STD_WSTRING 00156 00167 BLOCXX_COMMON_API String 00168 fromWideString(const String &enc, const std::wstring &str); 00169 #endif 00170 00182 BLOCXX_COMMON_API std::string 00183 toByteString(const String &enc, const String &utf8); 00184 00185 #ifdef BLOCXX_HAVE_STD_WSTRING 00186 00197 BLOCXX_COMMON_API std::wstring 00198 toWideString(const String &enc, const String &utf8); 00199 #endif 00200 00201 #if 0 00202 /* 00203 * Retrieve an array of supported encoding names. 00204 * 00205 * @return array with supported encoding names. 00206 */ 00207 BLOCXX_COMMON_API StringArray 00208 encodings(); 00209 #endif 00210 00211 } // End of IConv namespace 00212 } // End of BLOCXX_NAMESPACE 00213 00214 #endif // BLOCXX_HAVE_ICONV_SUPPORT 00215 #endif // INCLUDE_GUARD_HPP_ 00216 00217 /* vim: set ts=8 sts=8 sw=8 ai noet: */ 00218