Boost.Locale
boost/locale/encoding.hpp
00001 //
00002 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
00003 //
00004 //  Distributed under the Boost Software License, Version 1.0. (See
00005 //  accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 //
00008 #ifndef BOOST_LOCALE_ENCODING_HPP_INCLUDED
00009 #define BOOST_LOCALE_ENCODING_HPP_INCLUDED
00010 
00011 #include <boost/locale/config.hpp>
00012 #ifdef BOOST_MSVC
00013 #  pragma warning(push)
00014 #  pragma warning(disable : 4275 4251 4231 4660)
00015 #endif
00016 #include <boost/locale/info.hpp>
00017 #include <boost/locale/encoding_errors.hpp>
00018 #include <boost/locale/encoding_utf.hpp>
00019 
00020 
00021 
00022 namespace boost {
00023     namespace locale {
00024 
00028         namespace conv {
00033 
00037             template<typename CharType>
00038             std::basic_string<CharType> to_utf(char const *begin,char const *end,std::string const &charset,method_type how=default_method);
00039 
00043             template<typename CharType>
00044             std::string from_utf(CharType const *begin,CharType const *end,std::string const &charset,method_type how=default_method);
00045 
00051             template<typename CharType>
00052             std::basic_string<CharType> to_utf(char const *begin,char const *end,std::locale const &loc,method_type how=default_method)
00053             {
00054                 return to_utf<CharType>(begin,end,std::use_facet<info>(loc).encoding(),how);
00055             }
00056 
00062             template<typename CharType>
00063             std::string from_utf(CharType const *begin,CharType const *end,std::locale const &loc,method_type how=default_method)
00064             {
00065                 return from_utf(begin,end,std::use_facet<info>(loc).encoding(),how);
00066             }
00067 
00071             
00072             template<typename CharType>
00073             std::basic_string<CharType> to_utf(std::string const &text,std::string const &charset,method_type how=default_method)
00074             {
00075                 return to_utf<CharType>(text.c_str(),text.c_str()+text.size(),charset,how);
00076             }
00077 
00081             template<typename CharType>
00082             std::string from_utf(std::basic_string<CharType> const &text,std::string const &charset,method_type how=default_method)
00083             {
00084                 return from_utf(text.c_str(),text.c_str()+text.size(),charset,how);
00085             }
00086 
00090             template<typename CharType>
00091             std::basic_string<CharType> to_utf(char const *text,std::string const &charset,method_type how=default_method)
00092             {
00093                 char const *text_end = text;
00094                 while(*text_end) 
00095                     text_end++;
00096                 return to_utf<CharType>(text,text_end,charset,how);
00097             }
00098 
00102             template<typename CharType>
00103             std::string from_utf(CharType const *text,std::string const &charset,method_type how=default_method)
00104             {
00105                 CharType const *text_end = text;
00106                 while(*text_end) 
00107                     text_end++;
00108                 return from_utf(text,text_end,charset,how);
00109             }
00110 
00116             template<typename CharType>
00117             std::basic_string<CharType> to_utf(std::string const &text,std::locale const &loc,method_type how=default_method)
00118             {
00119                 return to_utf<CharType>(text.c_str(),text.c_str()+text.size(),loc,how);
00120             }
00121 
00127             template<typename CharType>
00128             std::string from_utf(std::basic_string<CharType> const &text,std::locale const &loc,method_type how=default_method)
00129             {
00130                 return from_utf(text.c_str(),text.c_str()+text.size(),loc,how);
00131             }
00132 
00138             template<typename CharType>
00139             std::basic_string<CharType> to_utf(char const *text,std::locale const &loc,method_type how=default_method)
00140             {
00141                 char const *text_end = text;
00142                 while(*text_end) 
00143                     text_end++;
00144                 return to_utf<CharType>(text,text_end,loc,how);
00145             }
00146 
00152             template<typename CharType>
00153             std::string from_utf(CharType const *text,std::locale const &loc,method_type how=default_method)
00154             {
00155                 CharType const *text_end = text;
00156                 while(*text_end) 
00157                     text_end++;
00158                 return from_utf(text,text_end,loc,how);
00159             }
00160 
00161 
00165             
00166             BOOST_LOCALE_DECL
00167             std::string between(char const *begin,
00168                                 char const *end,
00169                                 std::string const &to_encoding,
00170                                 std::string const &from_encoding,
00171                                 method_type how=default_method);
00172 
00176             
00177             inline
00178             std::string between(char const *text,
00179                                 std::string const &to_encoding,
00180                                 std::string const &from_encoding,
00181                                 method_type how=default_method)
00182             {
00183                 char const *end=text;
00184                 while(*end)
00185                     end++;
00186                 return boost::locale::conv::between(text,end,to_encoding,from_encoding,how);
00187             }
00188 
00192             inline
00193             std::string between(std::string const &text,
00194                                 std::string const &to_encoding,
00195                                 std::string const &from_encoding,
00196                                 method_type how=default_method)
00197             {
00198                 return boost::locale::conv::between(text.c_str(),text.c_str()+text.size(),to_encoding,from_encoding,how);
00199             }
00200           
00202 
00203             template<>
00204             BOOST_LOCALE_DECL std::basic_string<char> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00205 
00206             template<>
00207             BOOST_LOCALE_DECL std::string from_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00208 
00209             template<>
00210             BOOST_LOCALE_DECL std::basic_string<wchar_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00211 
00212             template<>
00213             BOOST_LOCALE_DECL std::string from_utf(wchar_t const *begin,wchar_t const *end,std::string const &charset,method_type how);
00214 
00215             #ifdef BOOST_HAS_CHAR16_T
00216             template<>
00217             BOOST_LOCALE_DECL std::basic_string<char16_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00218 
00219             template<>
00220             BOOST_LOCALE_DECL std::string from_utf(char16_t const *begin,char16_t const *end,std::string const &charset,method_type how);
00221             #endif
00222 
00223             #ifdef BOOST_HAS_CHAR32_T
00224             template<>
00225             BOOST_LOCALE_DECL std::basic_string<char32_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00226 
00227             template<>
00228             BOOST_LOCALE_DECL std::string from_utf(char32_t const *begin,char32_t const *end,std::string const &charset,method_type how);
00229             #endif
00230 
00231 
00233 
00235 
00236         } // conv
00237 
00238     } // locale
00239 } // boost
00240 
00241 #ifdef BOOST_MSVC
00242 #pragma warning(pop)
00243 #endif
00244 
00245 #endif
00246 
00247 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
00248