Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file code_conversion.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 08.11.2008
|
Chris@16
|
11 *
|
Chris@16
|
12 * \brief This header is the Boost.Log library implementation, see the library documentation
|
Chris@16
|
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
|
Chris@16
|
14 */
|
Chris@16
|
15
|
Chris@16
|
16 #ifndef BOOST_LOG_DETAIL_CODE_CONVERSION_HPP_INCLUDED_
|
Chris@16
|
17 #define BOOST_LOG_DETAIL_CODE_CONVERSION_HPP_INCLUDED_
|
Chris@16
|
18
|
Chris@16
|
19 #include <locale>
|
Chris@16
|
20 #include <string>
|
Chris@16
|
21 #include <boost/log/detail/config.hpp>
|
Chris@16
|
22 #include <boost/log/detail/header.hpp>
|
Chris@16
|
23
|
Chris@16
|
24 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
25 #pragma once
|
Chris@16
|
26 #endif
|
Chris@16
|
27
|
Chris@16
|
28 namespace boost {
|
Chris@16
|
29
|
Chris@16
|
30 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
31
|
Chris@16
|
32 namespace aux {
|
Chris@16
|
33
|
Chris@16
|
34 //! The function converts one string to the character type of another
|
Chris@16
|
35 BOOST_LOG_API void code_convert(const wchar_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale());
|
Chris@16
|
36 //! The function converts one string to the character type of another
|
Chris@16
|
37 BOOST_LOG_API void code_convert(const char* str1, std::size_t len, std::wstring& str2, std::locale const& loc = std::locale());
|
Chris@101
|
38
|
Chris@101
|
39 // Note: MSVC 2015 (aka VC14) implement char16_t and char32_t types but not codecvt locale facets
|
Chris@101
|
40 #if !defined(BOOST_MSVC)
|
Chris@16
|
41 #if !defined(BOOST_NO_CXX11_CHAR16_T)
|
Chris@16
|
42 //! The function converts one string to the character type of another
|
Chris@16
|
43 BOOST_LOG_API void code_convert(const char16_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale());
|
Chris@16
|
44 //! The function converts one string to the character type of another
|
Chris@16
|
45 BOOST_LOG_API void code_convert(const char* str1, std::size_t len, std::u16string& str2, std::locale const& loc = std::locale());
|
Chris@16
|
46 #endif
|
Chris@16
|
47 #if !defined(BOOST_NO_CXX11_CHAR32_T)
|
Chris@16
|
48 //! The function converts one string to the character type of another
|
Chris@16
|
49 BOOST_LOG_API void code_convert(const char32_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale());
|
Chris@16
|
50 //! The function converts one string to the character type of another
|
Chris@16
|
51 BOOST_LOG_API void code_convert(const char* str1, std::size_t len, std::u32string& str2, std::locale const& loc = std::locale());
|
Chris@16
|
52 #endif
|
Chris@101
|
53 #endif // !defined(BOOST_MSVC)
|
Chris@16
|
54
|
Chris@16
|
55 //! The function converts one string to the character type of another
|
Chris@16
|
56 template< typename CharT, typename SourceTraitsT, typename SourceAllocatorT, typename TargetTraitsT, typename TargetAllocatorT >
|
Chris@16
|
57 inline void code_convert(std::basic_string< CharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< CharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale())
|
Chris@16
|
58 {
|
Chris@16
|
59 str2.append(str1.c_str(), str1.size());
|
Chris@16
|
60 }
|
Chris@16
|
61 //! The function converts one string to the character type of another
|
Chris@16
|
62 template< typename CharT, typename TargetTraitsT, typename TargetAllocatorT >
|
Chris@16
|
63 inline void code_convert(const CharT* str1, std::size_t len, std::basic_string< CharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale())
|
Chris@16
|
64 {
|
Chris@16
|
65 str2.append(str1, len);
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 //! The function converts one string to the character type of another
|
Chris@16
|
69 template< typename SourceCharT, typename SourceTraitsT, typename SourceAllocatorT, typename TargetCharT, typename TargetTraitsT, typename TargetAllocatorT >
|
Chris@16
|
70 inline void code_convert(std::basic_string< SourceCharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< TargetCharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& loc = std::locale())
|
Chris@16
|
71 {
|
Chris@16
|
72 aux::code_convert(str1.c_str(), str1.size(), str2, loc);
|
Chris@16
|
73 }
|
Chris@16
|
74
|
Chris@16
|
75 //! The function converts the passed string to the narrow-character encoding
|
Chris@16
|
76 inline std::string const& to_narrow(std::string const& str)
|
Chris@16
|
77 {
|
Chris@16
|
78 return str;
|
Chris@16
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 //! The function converts the passed string to the narrow-character encoding
|
Chris@16
|
82 inline std::string const& to_narrow(std::string const& str, std::locale const&)
|
Chris@16
|
83 {
|
Chris@16
|
84 return str;
|
Chris@16
|
85 }
|
Chris@16
|
86
|
Chris@16
|
87 //! The function converts the passed string to the narrow-character encoding
|
Chris@16
|
88 inline std::string to_narrow(std::wstring const& str, std::locale const& loc = std::locale())
|
Chris@16
|
89 {
|
Chris@16
|
90 std::string res;
|
Chris@16
|
91 aux::code_convert(str, res, loc);
|
Chris@16
|
92 return res;
|
Chris@16
|
93 }
|
Chris@16
|
94
|
Chris@16
|
95 //! The function converts the passed string to the wide-character encoding
|
Chris@16
|
96 inline std::wstring const& to_wide(std::wstring const& str)
|
Chris@16
|
97 {
|
Chris@16
|
98 return str;
|
Chris@16
|
99 }
|
Chris@16
|
100
|
Chris@16
|
101 //! The function converts the passed string to the wide-character encoding
|
Chris@16
|
102 inline std::wstring const& to_wide(std::wstring const& str, std::locale const&)
|
Chris@16
|
103 {
|
Chris@16
|
104 return str;
|
Chris@16
|
105 }
|
Chris@16
|
106
|
Chris@16
|
107 //! The function converts the passed string to the wide-character encoding
|
Chris@16
|
108 inline std::wstring to_wide(std::string const& str, std::locale const& loc = std::locale())
|
Chris@16
|
109 {
|
Chris@16
|
110 std::wstring res;
|
Chris@16
|
111 aux::code_convert(str, res, loc);
|
Chris@16
|
112 return res;
|
Chris@16
|
113 }
|
Chris@16
|
114
|
Chris@16
|
115 } // namespace aux
|
Chris@16
|
116
|
Chris@16
|
117 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
118
|
Chris@16
|
119 } // namespace boost
|
Chris@16
|
120
|
Chris@16
|
121 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
122
|
Chris@16
|
123 #endif // BOOST_LOG_DETAIL_CODE_CONVERSION_HPP_INCLUDED_
|