Boost.Locale: boost/locale/encoding_utf.hpp Source File

| Boost.Locale

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

encoding_utf.hpp
1 //
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
9 #define BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
10
11 #include <boost/locale/utf.hpp>
12 #include <boost/locale/encoding_errors.hpp>
13 #include <iterator>
14 #ifdef BOOST_MSVC
15 # pragma warning(push)
16 # pragma warning(disable : 4275 4251 4231 4660)
17 #endif
18
19
20
21 namespace boost {
22 namespace locale {
23 namespace conv {
28
32 template<typename CharOut,typename CharIn>
33 std::basic_string<CharOut>
34 utf_to_utf(CharIn const *begin,CharIn const *end,method_type how = default_method)
35 {
36 std::basic_string<CharOut> result;
37 result.reserve(end-begin);
38 typedef std::back_insert_iterator<std::basic_string<CharOut> > inserter_type;
39 inserter_type inserter(result);
40 utf::code_point c;
41 while(begin!=end) {
42 c=utf::utf_traits<CharIn>::template decode<CharIn const *>(begin,end);
43 if(c==utf::illegal || c==utf::incomplete) {
44 if(how==stop)
45 throw conversion_error();
46 }
47 else {
48 utf::utf_traits<CharOut>::template encode<inserter_type>(c,inserter);
49 }
50 }
51 return result;
52 }
53
57 template<typename CharOut,typename CharIn>
58 std::basic_string<CharOut>
59 utf_to_utf(CharIn const *str,method_type how = default_method)
60 {
61 CharIn const *end = str;
62 while(*end)
63 end++;
64 return utf_to_utf<CharOut,CharIn>(str,end,how);
65 }
66
67
71 template<typename CharOut,typename CharIn>
72 std::basic_string<CharOut>
73 utf_to_utf(std::basic_string<CharIn> const &str,method_type how = default_method)
74 {
75 return utf_to_utf<CharOut,CharIn>(str.c_str(),str.c_str()+str.size(),how);
76 }
77
78
80
81 } // conv
82
83 } // locale
84 } // boost
85
86 #ifdef BOOST_MSVC
87 #pragma warning(pop)
88 #endif
89
90 #endif
91
92 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
93
boost::locale::utf::incomplete
static const code_point incomplete
Special constant that defines incomplete code point.
Definition: utf.hpp:44
boost::locale::conv::conversion_error
The excepton that is thrown in case of conversion error.
Definition: encoding_errors.hpp:31
boost::locale::utf::code_point
uint32_t code_point
The integral type that can hold a Unicode code point.
Definition: utf.hpp:34
boost::locale::utf::illegal
static const code_point illegal
Special constant that defines illegal code point.
Definition: utf.hpp:39
boost::locale::utf::utf_traits
UTF Traits class - functions to convert UTF sequences to and from Unicode code points.
Definition: utf.hpp:63
boost::locale::conv::utf_to_utf
std::basic_string< CharOut > utf_to_utf(CharIn const *begin, CharIn const *end, method_type how=default_method)
Definition: encoding_utf.hpp:34
boost::locale::conv::default_method
Default method - skip.
Definition: encoding_errors.hpp:57
boost::locale::conv::stop
Stop conversion and throw conversion_error.
Definition: encoding_errors.hpp:56
boost::locale::conv::method_type
method_type
Definition: encoding_errors.hpp:54
- © Copyright 2009-2012 Artyom Beilis, Distributed under the Boost Software License, Version 1.0.