Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:14

0001 // Copyright Vladimir Prus 2004.
0002 // Distributed under the Boost Software License, Version 1.0.
0003 // (See accompanying file LICENSE_1_0.txt
0004 // or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_CONVERT_HPP_VP_2004_04_28
0007 #define BOOST_CONVERT_HPP_VP_2004_04_28
0008 
0009 #include <boost/program_options/config.hpp>
0010 
0011 #if !defined(BOOST_NO_STD_WSTRING)
0012 
0013 #include <boost/detail/workaround.hpp>
0014 
0015 #include <string>
0016 #include <vector>
0017 #include <locale>
0018 // for mbstate_t
0019 #include <cwchar>
0020 #include <stdexcept>
0021 
0022 #if defined(BOOST_NO_STDC_NAMESPACE)
0023 #include <wchar.h>
0024 namespace std
0025 {
0026     using ::mbstate_t;
0027 }    
0028 #endif
0029 
0030 namespace boost {
0031 
0032     /** Converts from local 8 bit encoding into wchar_t string using
0033         the specified locale facet. */
0034     BOOST_PROGRAM_OPTIONS_DECL std::wstring 
0035     from_8_bit(const std::string& s, 
0036                const std::codecvt<wchar_t, char, std::mbstate_t>& cvt);
0037 
0038     /** Converts from wchar_t string into local 8 bit encoding into using
0039         the specified locale facet. */
0040     BOOST_PROGRAM_OPTIONS_DECL std::string 
0041     to_8_bit(const std::wstring& s, 
0042              const std::codecvt<wchar_t, char, std::mbstate_t>& cvt);
0043 
0044 
0045     /** Converts 's', which is assumed to be in UTF8 encoding, into wide
0046         string. */
0047     BOOST_PROGRAM_OPTIONS_DECL std::wstring
0048     from_utf8(const std::string& s);
0049     
0050     /** Converts wide string 's' into string in UTF8 encoding. */
0051     BOOST_PROGRAM_OPTIONS_DECL std::string
0052     to_utf8(const std::wstring& s);
0053 
0054     /** Converts wide string 's' into local 8 bit encoding determined by
0055         the current locale. */
0056     BOOST_PROGRAM_OPTIONS_DECL std::string
0057     to_local_8_bit(const std::wstring& s);
0058 
0059     /** Converts 's', which is assumed to be in local 8 bit encoding, into wide
0060         string. */
0061     BOOST_PROGRAM_OPTIONS_DECL std::wstring
0062     from_local_8_bit(const std::string& s);
0063 
0064     namespace program_options
0065     {
0066         /** Convert the input string into internal encoding used by
0067             program_options. Presence of this function allows to avoid
0068             specializing all methods which access input on wchar_t.
0069         */
0070         BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::string&);
0071         /** @overload */
0072         BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::wstring&);
0073 
0074         template<class T>
0075         std::vector<std::string> to_internal(const std::vector<T>& s)
0076         {
0077             std::vector<std::string> result;
0078             for (unsigned i = 0; i < s.size(); ++i)
0079                 result.push_back(to_internal(s[i]));            
0080             return result;
0081         }
0082 
0083     }
0084 
0085 
0086   
0087 }
0088 
0089 #else
0090 #include <vector>
0091 #include <string>
0092 namespace boost{
0093    namespace program_options{
0094         BOOST_PROGRAM_OPTIONS_DECL std::string to_internal(const std::string&);
0095 
0096         template<class T>
0097         std::vector<std::string> to_internal(const std::vector<T>& s)
0098         {
0099             std::vector<std::string> result;
0100             for (unsigned i = 0; i < s.size(); ++i)
0101                 result.push_back(to_internal(s[i]));            
0102             return result;
0103         }
0104    }
0105 }
0106 #endif
0107 #endif