Chris@16: // Chris@16: // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: #ifndef BOOST_LOCALE_ENCODING_HPP_INCLUDED Chris@16: #define BOOST_LOCALE_ENCODING_HPP_INCLUDED Chris@16: Chris@16: #include Chris@16: #ifdef BOOST_MSVC Chris@16: # pragma warning(push) Chris@16: # pragma warning(disable : 4275 4251 4231 4660) Chris@16: #endif Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: Chris@16: namespace boost { Chris@16: namespace locale { Chris@16: Chris@16: /// Chris@16: /// \brief Namespace that contains all functions related to character set conversion Chris@16: /// Chris@16: namespace conv { Chris@16: /// Chris@16: /// \defgroup codepage Character conversion functions Chris@16: /// Chris@16: /// @{ Chris@16: Chris@16: /// Chris@16: /// convert string to UTF string from text in range [begin,end) encoded with \a charset according to policy \a how Chris@16: /// Chris@16: template Chris@16: std::basic_string to_utf(char const *begin,char const *end,std::string const &charset,method_type how=default_method); Chris@16: Chris@16: /// Chris@16: /// convert UTF text in range [begin,end) to a text encoded with \a charset according to policy \a how Chris@16: /// Chris@16: template Chris@16: std::string from_utf(CharType const *begin,CharType const *end,std::string const &charset,method_type how=default_method); Chris@16: Chris@16: /// Chris@16: /// convert string to UTF string from text in range [begin,end) encoded according to locale \a loc according to policy \a how Chris@16: /// Chris@16: /// \note throws std::bad_cast if the loc does not have \ref info facet installed Chris@16: /// Chris@16: template Chris@16: std::basic_string to_utf(char const *begin,char const *end,std::locale const &loc,method_type how=default_method) Chris@16: { Chris@16: return to_utf(begin,end,std::use_facet(loc).encoding(),how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// convert UTF text in range [begin,end) to a text encoded according to locale \a loc according to policy \a how Chris@16: /// Chris@16: /// \note throws std::bad_cast if the loc does not have \ref info facet installed Chris@16: /// Chris@16: template Chris@16: std::string from_utf(CharType const *begin,CharType const *end,std::locale const &loc,method_type how=default_method) Chris@16: { Chris@16: return from_utf(begin,end,std::use_facet(loc).encoding(),how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// convert a string \a text encoded with \a charset to UTF string Chris@16: /// Chris@16: Chris@16: template Chris@16: std::basic_string to_utf(std::string const &text,std::string const &charset,method_type how=default_method) Chris@16: { Chris@16: return to_utf(text.c_str(),text.c_str()+text.size(),charset,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text from \a charset to UTF string Chris@16: /// Chris@16: template Chris@16: std::string from_utf(std::basic_string const &text,std::string const &charset,method_type how=default_method) Chris@16: { Chris@16: return from_utf(text.c_str(),text.c_str()+text.size(),charset,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text from \a charset to UTF string Chris@16: /// Chris@16: template Chris@16: std::basic_string to_utf(char const *text,std::string const &charset,method_type how=default_method) Chris@16: { Chris@16: char const *text_end = text; Chris@16: while(*text_end) Chris@16: text_end++; Chris@16: return to_utf(text,text_end,charset,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text from UTF to \a charset Chris@16: /// Chris@16: template Chris@16: std::string from_utf(CharType const *text,std::string const &charset,method_type how=default_method) Chris@16: { Chris@16: CharType const *text_end = text; Chris@16: while(*text_end) Chris@16: text_end++; Chris@16: return from_utf(text,text_end,charset,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text in locale encoding given by \a loc to UTF Chris@16: /// Chris@16: /// \note throws std::bad_cast if the loc does not have \ref info facet installed Chris@16: /// Chris@16: template Chris@16: std::basic_string to_utf(std::string const &text,std::locale const &loc,method_type how=default_method) Chris@16: { Chris@16: return to_utf(text.c_str(),text.c_str()+text.size(),loc,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text in UTF to locale encoding given by \a loc Chris@16: /// Chris@16: /// \note throws std::bad_cast if the loc does not have \ref info facet installed Chris@16: /// Chris@16: template Chris@16: std::string from_utf(std::basic_string const &text,std::locale const &loc,method_type how=default_method) Chris@16: { Chris@16: return from_utf(text.c_str(),text.c_str()+text.size(),loc,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text in locale encoding given by \a loc to UTF Chris@16: /// Chris@16: /// \note throws std::bad_cast if the loc does not have \ref info facet installed Chris@16: /// Chris@16: template Chris@16: std::basic_string to_utf(char const *text,std::locale const &loc,method_type how=default_method) Chris@16: { Chris@16: char const *text_end = text; Chris@16: while(*text_end) Chris@16: text_end++; Chris@16: return to_utf(text,text_end,loc,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text in UTF to locale encoding given by \a loc Chris@16: /// Chris@16: /// \note throws std::bad_cast if the loc does not have \ref info facet installed Chris@16: /// Chris@16: template Chris@16: std::string from_utf(CharType const *text,std::locale const &loc,method_type how=default_method) Chris@16: { Chris@16: CharType const *text_end = text; Chris@16: while(*text_end) Chris@16: text_end++; Chris@16: return from_utf(text,text_end,loc,how); Chris@16: } Chris@16: Chris@16: Chris@16: /// Chris@16: /// Convert a text in range [begin,end) to \a to_encoding from \a from_encoding Chris@16: /// Chris@16: Chris@16: BOOST_LOCALE_DECL Chris@16: std::string between(char const *begin, Chris@16: char const *end, Chris@16: std::string const &to_encoding, Chris@16: std::string const &from_encoding, Chris@16: method_type how=default_method); Chris@16: Chris@16: /// Chris@16: /// Convert a \a text to \a to_encoding from \a from_encoding Chris@16: /// Chris@16: Chris@16: inline Chris@16: std::string between(char const *text, Chris@16: std::string const &to_encoding, Chris@16: std::string const &from_encoding, Chris@16: method_type how=default_method) Chris@16: { Chris@16: char const *end=text; Chris@16: while(*end) Chris@16: end++; Chris@16: return boost::locale::conv::between(text,end,to_encoding,from_encoding,how); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Convert a \a text to \a to_encoding from \a from_encoding Chris@16: /// Chris@16: inline Chris@16: std::string between(std::string const &text, Chris@16: std::string const &to_encoding, Chris@16: std::string const &from_encoding, Chris@16: method_type how=default_method) Chris@16: { Chris@16: return boost::locale::conv::between(text.c_str(),text.c_str()+text.size(),to_encoding,from_encoding,how); Chris@16: } Chris@16: Chris@16: /// \cond INTERNAL Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::basic_string to_utf(char const *begin,char const *end,std::string const &charset,method_type how); Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::string from_utf(char const *begin,char const *end,std::string const &charset,method_type how); Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::basic_string to_utf(char const *begin,char const *end,std::string const &charset,method_type how); Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::string from_utf(wchar_t const *begin,wchar_t const *end,std::string const &charset,method_type how); Chris@16: Chris@16: #ifdef BOOST_HAS_CHAR16_T Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::basic_string to_utf(char const *begin,char const *end,std::string const &charset,method_type how); Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::string from_utf(char16_t const *begin,char16_t const *end,std::string const &charset,method_type how); Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_HAS_CHAR32_T Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::basic_string to_utf(char const *begin,char const *end,std::string const &charset,method_type how); Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL std::string from_utf(char32_t const *begin,char32_t const *end,std::string const &charset,method_type how); Chris@16: #endif Chris@16: Chris@16: Chris@16: /// \endcond Chris@16: Chris@16: /// @} Chris@16: Chris@16: } // conv Chris@16: Chris@16: } // locale Chris@16: } // boost Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif Chris@16: Chris@16: // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 Chris@16: