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_1_0.txt 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/detail/convert.hpp>
12 #include <string>
13 
14 namespace boost {
15 namespace nowide {
16 
24  inline char* narrow(char* output, size_t output_size, const wchar_t* begin, const wchar_t* end)
25  {
26  return detail::convert_buffer(output, output_size, begin, end);
27  }
35  inline char* narrow(char* output, size_t output_size, const wchar_t* source)
36  {
37  return narrow(output, output_size, source, source + detail::strlen(source));
38  }
39 
47  inline wchar_t* widen(wchar_t* output, size_t output_size, const char* begin, const char* end)
48  {
49  return detail::convert_buffer(output, output_size, begin, end);
50  }
58  inline wchar_t* widen(wchar_t* output, size_t output_size, const char* source)
59  {
60  return widen(output, output_size, source, source + detail::strlen(source));
61  }
62 
70  inline std::string narrow(const wchar_t* s, size_t count)
71  {
72  return detail::convert_string<char>(s, s + count);
73  }
80  inline std::string narrow(const wchar_t* s)
81  {
82  return narrow(s, detail::strlen(s));
83  }
90  inline std::string narrow(const std::wstring& s)
91  {
92  return narrow(s.c_str(), s.size());
93  }
94 
102  inline std::wstring widen(const char* s, size_t count)
103  {
104  return detail::convert_string<wchar_t>(s, s + count);
105  }
112  inline std::wstring widen(const char* s)
113  {
114  return widen(s, detail::strlen(s));
115  }
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
wchar_t * widen(wchar_t *output, size_t output_size, const char *begin, const char *end)
Definition: convert.hpp:47
char * narrow(char *output, size_t output_size, const wchar_t *begin, const wchar_t *end)
Definition: convert.hpp:24