File indexing completed on 2025-01-18 09:39:16
0001
0002
0003
0004
0005
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
0022
0023
0024
0025
0026
0027
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
0046
0047
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
0055
0056
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 }}}
0066
0067 #ifdef BOOST_MSVC
0068 # pragma warning(pop)
0069 #endif
0070
0071 #endif