Boost.Locale
encoding_utf.hpp
1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3//
4// Distributed under the Boost Software License, Version 1.0.
5// https://www.boost.org/LICENSE_1_0.txt
6
7#ifndef BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
8#define BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
9
10#include <boost/locale/encoding_errors.hpp>
11#include <boost/locale/utf.hpp>
12#include <boost/locale/util/string.hpp>
13#include <iterator>
14
15#ifdef BOOST_MSVC
16# pragma warning(push)
17# pragma warning(disable : 4275 4251 4231 4660)
18#endif
19
20namespace boost { namespace locale { namespace conv {
24
28 template<typename CharOut, typename CharIn>
29 std::basic_string<CharOut> utf_to_utf(const CharIn* begin, const CharIn* end, method_type how = default_method)
30 {
31 std::basic_string<CharOut> result;
32 result.reserve(end - begin);
33 std::back_insert_iterator<std::basic_string<CharOut>> inserter(result);
34 while(begin != end) {
36 if(c == utf::illegal || c == utf::incomplete) {
37 if(how == stop)
38 throw conversion_error();
39 } else
41 }
42 return result;
43 }
44
48 template<typename CharOut, typename CharIn>
49 std::basic_string<CharOut> utf_to_utf(const CharIn* str, method_type how = default_method)
50 {
51 return utf_to_utf<CharOut, CharIn>(str, util::str_end(str), how);
52 }
53
57 template<typename CharOut, typename CharIn>
58 std::basic_string<CharOut> utf_to_utf(const std::basic_string<CharIn>& str, method_type how = default_method)
59 {
60 return utf_to_utf<CharOut, CharIn>(str.c_str(), str.c_str() + str.size(), how);
61 }
62
64
65}}} // namespace boost::locale::conv
66
67#ifdef BOOST_MSVC
68# pragma warning(pop)
69#endif
70
71#endif
The exception that is thrown in case of conversion error.
Definition: encoding_errors.hpp:25
std::basic_string< CharOut > utf_to_utf(const CharIn *begin, const CharIn *end, method_type how=default_method)
Definition: encoding_utf.hpp:29
method_type
enum that defines conversion policy
Definition: encoding_errors.hpp:41
@ stop
Stop conversion and throw conversion_error.
Definition: encoding_errors.hpp:43
@ default_method
Default method - skip.
Definition: encoding_errors.hpp:44
uint32_t code_point
The integral type that can hold a Unicode code point.
Definition: utf.hpp:19
constexpr code_point illegal
Special constant that defines illegal code point.
Definition: utf.hpp:22
constexpr code_point incomplete
Special constant that defines incomplete code point.
Definition: utf.hpp:24
Char * str_end(Char *str)
Return the end of a C-string, i.e. the pointer to the trailing NULL byte.
Definition: string.hpp:16
static code_point decode(Iterator &p, Iterator e)
static Iterator encode(code_point value, Iterator out)