1 // Copyright Vladimir Prus 2004.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt
4 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_CONVERT_HPP_VP_2004_04_28
7 #define BOOST_CONVERT_HPP_VP_2004_04_28
9 #include <boost/program_options/config.hpp>
11 #if !defined(BOOST_NO_STD_WSTRING)
13 #include <boost/detail/workaround.hpp>
22 #if defined(BOOST_NO_STDC_NAMESPACE)
32 /** Converts from local 8 bit encoding into wchar_t string using
33 the specified locale facet. */
34 BOOST_PROGRAM_OPTIONS_DECL std::wstring
35 from_8_bit(const std::string& s,
36 const std::codecvt<wchar_t, char, std::mbstate_t>& cvt);
38 /** Converts from wchar_t string into local 8 bit encoding into using
39 the specified locale facet. */
40 BOOST_PROGRAM_OPTIONS_DECL std::string
41 to_8_bit(const std::wstring& s,
42 const std::codecvt<wchar_t, char, std::mbstate_t>& cvt);
45 /** Converts 's', which is assumed to be in UTF8 encoding, into wide
47 BOOST_PROGRAM_OPTIONS_DECL std::wstring
48 from_utf8(const std::string& s);
50 /** Converts wide string 's' into string in UTF8 encoding. */
51 BOOST_PROGRAM_OPTIONS_DECL std::string
52 to_utf8(const std::wstring& s);
54 /** Converts wide string 's' into local 8 bit encoding determined by
55 the current locale. */
56 BOOST_PROGRAM_OPTIONS_DECL std::string
57 to_local_8_bit(const std::wstring& s);
59 /** Converts 's', which is assumed to be in local 8 bit encoding, into wide
61 BOOST_PROGRAM_OPTIONS_DECL std::wstring
62 from_local_8_bit(const std::string& s);
64 namespace program_options
66 /** Convert the input string into internal encoding used by
67 program_options. Presence of this function allows to avoid
68 specializing all methods which access input on wchar_t.
70 BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::string&);
72 BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::wstring&);
75 std::vector<std::string> to_internal(const std::vector<T>& s)
77 std::vector<std::string> result;
78 for (unsigned i = 0; i < s.size(); ++i)
79 result.push_back(to_internal(s[i]));
93 namespace program_options{
94 BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::string&);
97 std::vector<std::string> to_internal(const std::vector<T>& s)
99 std::vector<std::string> result;
100 for (unsigned i = 0; i < s.size(); ++i)
101 result.push_back(to_internal(s[i]));