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