]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/nowide/convert.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / nowide / convert.hpp
1 //
2 // Copyright (c) 2012 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOST_NOWIDE_CONVERT_HPP_INCLUDED
9 #define BOOST_NOWIDE_CONVERT_HPP_INCLUDED
10
11 #include <boost/nowide/utf/convert.hpp>
12 #include <string>
13
14 namespace boost {
15 namespace nowide {
16
17 ///
18 /// Convert wide string (UTF-16/32) in range [begin,end) to NULL terminated narrow string (UTF-8)
19 /// stored in \a output of size \a output_size (including NULL)
20 ///
21 /// If there is not enough room NULL is returned, else output is returned.
22 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
23 ///
24 inline char* narrow(char* output, size_t output_size, const wchar_t* begin, const wchar_t* end)
25 {
26 return utf::convert_buffer(output, output_size, begin, end);
27 }
28 ///
29 /// Convert NULL terminated wide string (UTF-16/32) to NULL terminated narrow string (UTF-8)
30 /// stored in \a output of size \a output_size (including NULL)
31 ///
32 /// If there is not enough room NULL is returned, else output is returned.
33 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
34 ///
35 inline char* narrow(char* output, size_t output_size, const wchar_t* source)
36 {
37 return narrow(output, output_size, source, source + utf::strlen(source));
38 }
39
40 ///
41 /// Convert narrow string (UTF-8) in range [begin,end) to NULL terminated wide string (UTF-16/32)
42 /// stored in \a output of size \a output_size (including NULL)
43 ///
44 /// If there is not enough room NULL is returned, else output is returned.
45 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
46 ///
47 inline wchar_t* widen(wchar_t* output, size_t output_size, const char* begin, const char* end)
48 {
49 return utf::convert_buffer(output, output_size, begin, end);
50 }
51 ///
52 /// Convert NULL terminated narrow string (UTF-8) to NULL terminated wide string (UTF-16/32)
53 /// most output_size (including NULL)
54 ///
55 /// If there is not enough room NULL is returned, else output is returned.
56 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
57 ///
58 inline wchar_t* widen(wchar_t* output, size_t output_size, const char* source)
59 {
60 return widen(output, output_size, source, source + utf::strlen(source));
61 }
62
63 ///
64 /// Convert wide string (UTF-16/32) to narrow string (UTF-8).
65 ///
66 /// \param s Input string
67 /// \param count Number of characters to convert
68 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
69 ///
70 inline std::string narrow(const wchar_t* s, size_t count)
71 {
72 return utf::convert_string<char>(s, s + count);
73 }
74 ///
75 /// Convert wide string (UTF-16/32) to narrow string (UTF-8).
76 ///
77 /// \param s NULL terminated input string
78 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
79 ///
80 inline std::string narrow(const wchar_t* s)
81 {
82 return narrow(s, utf::strlen(s));
83 }
84 ///
85 /// Convert wide string (UTF-16/32) to narrow string (UTF-8).
86 ///
87 /// \param s Input string
88 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
89 ///
90 inline std::string narrow(const std::wstring& s)
91 {
92 return narrow(s.c_str(), s.size());
93 }
94
95 ///
96 /// Convert narrow string (UTF-8) to wide string (UTF-16/32).
97 ///
98 /// \param s Input string
99 /// \param count Number of characters to convert
100 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
101 ///
102 inline std::wstring widen(const char* s, size_t count)
103 {
104 return utf::convert_string<wchar_t>(s, s + count);
105 }
106 ///
107 /// Convert narrow string (UTF-8) to wide string (UTF-16/32).
108 ///
109 /// \param s NULL terminated input string
110 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
111 ///
112 inline std::wstring widen(const char* s)
113 {
114 return widen(s, utf::strlen(s));
115 }
116 ///
117 /// Convert narrow string (UTF-8) to wide string (UTF-16/32).
118 ///
119 /// \param s Input string
120 /// Any illegal sequences are replaced with the replacement character, see #BOOST_NOWIDE_REPLACEMENT_CHARACTER
121 ///
122 inline std::wstring widen(const std::string& s)
123 {
124 return widen(s.c_str(), s.size());
125 }
126 } // namespace nowide
127 } // namespace boost
128
129 #endif