Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:16

0001 //
0002 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // https://www.boost.org/LICENSE_1_0.txt
0006 
0007 #ifndef BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
0008 #define BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
0009 
0010 #include <boost/locale/encoding_errors.hpp>
0011 #include <boost/locale/utf.hpp>
0012 #include <boost/locale/util/string.hpp>
0013 #include <iterator>
0014 
0015 #ifdef BOOST_MSVC
0016 #    pragma warning(push)
0017 #    pragma warning(disable : 4275 4251 4231 4660)
0018 #endif
0019 
0020 namespace boost { namespace locale { namespace conv {
0021     /// \addtogroup codepage
0022     ///
0023     /// @{
0024 
0025     /// Convert a Unicode text in range [begin,end) to other Unicode encoding
0026     ///
0027     /// \throws conversion_error: Conversion failed (e.g. \a how is \c stop and any character cannot be decoded)
0028     template<typename CharOut, typename CharIn>
0029     std::basic_string<CharOut> utf_to_utf(const CharIn* begin, const CharIn* end, method_type how = default_method)
0030     {
0031         std::basic_string<CharOut> result;
0032         result.reserve(end - begin);
0033         std::back_insert_iterator<std::basic_string<CharOut>> inserter(result);
0034         while(begin != end) {
0035             const utf::code_point c = utf::utf_traits<CharIn>::decode(begin, end);
0036             if(c == utf::illegal || c == utf::incomplete) {
0037                 if(how == stop)
0038                     throw conversion_error();
0039             } else
0040                 utf::utf_traits<CharOut>::encode(c, inserter);
0041         }
0042         return result;
0043     }
0044 
0045     /// Convert a Unicode NULL terminated string \a str other Unicode encoding
0046     ///
0047     /// \throws conversion_error: Conversion failed (e.g. \a how is \c stop and any character cannot be decoded)
0048     template<typename CharOut, typename CharIn>
0049     std::basic_string<CharOut> utf_to_utf(const CharIn* str, method_type how = default_method)
0050     {
0051         return utf_to_utf<CharOut, CharIn>(str, util::str_end(str), how);
0052     }
0053 
0054     /// Convert a Unicode string \a str other Unicode encoding
0055     ///
0056     /// \throws conversion_error: Conversion failed (e.g. \a how is \c stop and any character cannot be decoded)
0057     template<typename CharOut, typename CharIn>
0058     std::basic_string<CharOut> utf_to_utf(const std::basic_string<CharIn>& str, method_type how = default_method)
0059     {
0060         return utf_to_utf<CharOut, CharIn>(str.c_str(), str.c_str() + str.size(), how);
0061     }
0062 
0063     /// @}
0064 
0065 }}} // namespace boost::locale::conv
0066 
0067 #ifdef BOOST_MSVC
0068 #    pragma warning(pop)
0069 #endif
0070 
0071 #endif