Chris@16: // Copyright Vladimir Prus 2004. Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt Chris@16: // or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_CONVERT_HPP_VP_2004_04_28 Chris@16: #define BOOST_CONVERT_HPP_VP_2004_04_28 Chris@16: Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_NO_STD_WSTRING) Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: // for mbstate_t Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_NO_STDC_NAMESPACE) Chris@16: #include Chris@16: namespace std Chris@16: { Chris@16: using ::mbstate_t; Chris@16: } Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: /** Converts from local 8 bit encoding into wchar_t string using Chris@16: the specified locale facet. */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::wstring Chris@16: from_8_bit(const std::string& s, Chris@16: const std::codecvt& cvt); Chris@16: Chris@16: /** Converts from wchar_t string into local 8 bit encoding into using Chris@16: the specified locale facet. */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::string Chris@16: to_8_bit(const std::wstring& s, Chris@16: const std::codecvt& cvt); Chris@16: Chris@16: Chris@16: /** Converts 's', which is assumed to be in UTF8 encoding, into wide Chris@16: string. */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::wstring Chris@16: from_utf8(const std::string& s); Chris@16: Chris@16: /** Converts wide string 's' into string in UTF8 encoding. */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::string Chris@16: to_utf8(const std::wstring& s); Chris@16: Chris@16: /** Converts wide string 's' into local 8 bit encoding determined by Chris@16: the current locale. */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::string Chris@16: to_local_8_bit(const std::wstring& s); Chris@16: Chris@16: /** Converts 's', which is assumed to be in local 8 bit encoding, into wide Chris@16: string. */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::wstring Chris@16: from_local_8_bit(const std::string& s); Chris@16: Chris@16: namespace program_options Chris@16: { Chris@16: /** Convert the input string into internal encoding used by Chris@16: program_options. Presence of this function allows to avoid Chris@16: specializing all methods which access input on wchar_t. Chris@16: */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::string&); Chris@16: /** @overload */ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::wstring&); Chris@16: Chris@16: template Chris@16: std::vector to_internal(const std::vector& s) Chris@16: { Chris@16: std::vector result; Chris@16: for (unsigned i = 0; i < s.size(); ++i) Chris@16: result.push_back(to_internal(s[i])); Chris@16: return result; Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: Chris@16: Chris@16: } Chris@16: Chris@16: #else Chris@16: #include Chris@16: #include Chris@16: namespace boost{ Chris@16: namespace program_options{ Chris@16: BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::string&); Chris@16: Chris@16: template Chris@16: std::vector to_internal(const std::vector& s) Chris@16: { Chris@16: std::vector result; Chris@16: for (unsigned i = 0; i < s.size(); ++i) Chris@16: result.push_back(to_internal(s[i])); Chris@16: return result; Chris@16: } Chris@16: } Chris@16: } Chris@16: #endif Chris@16: #endif