File indexing completed on 2025-01-18 09:38:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HELPER_HPP_INCLUDED
0029 #define BOOST_IOSTREAMS_DETAIL_CODECVT_HELPER_HPP_INCLUDED
0030
0031 #if defined(_MSC_VER)
0032 # pragma once
0033 #endif
0034
0035 #include <boost/config.hpp> // Put size_t in std, BOOST_MSVC, Dinkum.
0036 #include <boost/detail/workaround.hpp>
0037 #include <algorithm> // min.
0038 #include <cstddef> // size_t.
0039 #include <locale> // locale, codecvt_base, codecvt.
0040 #include <boost/iostreams/detail/config/codecvt.hpp>
0041
0042
0043
0044 namespace boost { namespace iostreams { namespace detail {
0045
0046 #if !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
0047
0048 template<typename T>
0049 struct codecvt_intern { typedef typename T::intern_type type; };
0050
0051 template<typename T>
0052 struct codecvt_extern { typedef typename T::extern_type type; };
0053
0054 #else
0055
0056 template<typename T>
0057 struct codecvt_intern { typedef typename T::from_type type; };
0058
0059 template<typename T>
0060 struct codecvt_extern { typedef typename T::to_type type; };
0061
0062 #endif
0063
0064 template<typename T>
0065 struct codecvt_state { typedef typename T::state_type type; };
0066
0067 } } }
0068
0069
0070
0071 #if defined(BOOST_IOSTREAMS_NO_PRIMARY_CODECVT_DEFINITION) || \
0072 defined(BOOST_IOSTREAMS_EMPTY_PRIMARY_CODECVT_DEFINITION) || \
0073 defined(BOOST_IOSTREAMS_NO_LOCALE) \
0074
0075
0076 namespace boost { namespace iostreams { namespace detail {
0077
0078 template<typename Intern, typename Extern, typename State>
0079 struct codecvt_impl : std::locale::facet, std::codecvt_base {
0080 public:
0081 typedef Intern intern_type;
0082 typedef Extern extern_type;
0083 typedef State state_type;
0084
0085 codecvt_impl(std::size_t refs = 0) : std::locale::facet(refs) { }
0086
0087 std::codecvt_base::result
0088 in( State& state, const Extern* first1, const Extern* last1,
0089 const Extern*& next1, Intern* first2, Intern* last2,
0090 Intern*& next2 ) const
0091 {
0092 return do_in(state, first1, last1, next1, first2, last2, next2);
0093 }
0094
0095 std::codecvt_base::result
0096 out( State& state, const Intern* first1, const Intern* last1,
0097 const Intern*& next1, Extern* first2, Extern* last2,
0098 Extern*& next2 ) const
0099 {
0100 return do_out(state, first1, last1, next1, first2, last2, next2);
0101 }
0102
0103 std::codecvt_base::result
0104 unshift(State& state, Extern* first2, Extern* last2, Extern*& next2) const
0105 {
0106 return do_unshift(state, first2, last2, next2);
0107 }
0108
0109 bool always_noconv() const throw() { return do_always_noconv(); }
0110
0111 int max_length() const throw() { return do_max_length(); }
0112
0113 int encoding() const throw() { return do_encoding(); }
0114
0115 int length( BOOST_IOSTREAMS_CODECVT_CV_QUALIFIER State& state,
0116 const Extern* first1, const Extern* last1,
0117 std::size_t len2 ) const throw()
0118 {
0119 return do_length(state, first1, last1, len2);
0120 }
0121 protected:
0122 std::codecvt_base::result
0123 virtual do_in( State&, const Extern*, const Extern*, const Extern*&,
0124 Intern*, Intern*, Intern*& ) const
0125 {
0126 return std::codecvt_base::noconv;
0127 }
0128
0129 std::codecvt_base::result
0130 virtual do_out( State&, const Intern*, const Intern*, const Intern*&,
0131 Extern*, Extern*, Extern*& ) const
0132 {
0133 return std::codecvt_base::noconv;
0134 }
0135
0136 std::codecvt_base::result
0137 virtual do_unshift(State&, Extern*, Extern*, Extern*&) const
0138 {
0139 return std::codecvt_base::ok;
0140 }
0141
0142 virtual bool do_always_noconv() const throw() { return true; }
0143
0144 virtual int do_max_length() const throw() { return 1; }
0145
0146 virtual int do_encoding() const throw() { return 1; }
0147
0148 virtual int do_length( BOOST_IOSTREAMS_CODECVT_CV_QUALIFIER State&,
0149 const Extern* first1, const Extern* last1,
0150 std::size_t len2 ) const throw()
0151 {
0152 return (std::min)(static_cast<std::size_t>(last1 - first1), len2);
0153 }
0154 };
0155
0156 } } }
0157
0158 #endif
0159
0160
0161
0162 #if defined(BOOST_IOSTREAMS_NO_PRIMARY_CODECVT_DEFINITION) || \
0163 defined(BOOST_IOSTREAMS_EMPTY_PRIMARY_CODECVT_DEFINITION) \
0164
0165 # define BOOST_IOSTREAMS_CODECVT_SPEC(state) \
0166 namespace std { \
0167 template<typename Intern, typename Extern> \
0168 class codecvt<Intern, Extern, state> \
0169 : public ::boost::iostreams::detail::codecvt_impl< \
0170 Intern, Extern, state \
0171 > \
0172 { \
0173 public: \
0174 codecvt(std::size_t refs = 0) \
0175 : ::boost::iostreams::detail::codecvt_impl< \
0176 Intern, Extern, state \
0177 >(refs) \
0178 { } \
0179 static std::locale::id id; \
0180 }; \
0181 template<typename Intern, typename Extern> \
0182 std::locale::id codecvt<Intern, Extern, state>::id; \
0183 } \
0184
0185 #else
0186 # define BOOST_IOSTREAMS_CODECVT_SPEC(state)
0187 #endif
0188
0189 namespace boost { namespace iostreams { namespace detail {
0190
0191
0192
0193 template<typename Intern, typename Extern, typename State>
0194 struct codecvt_helper : std::codecvt<Intern, Extern, State> {
0195 typedef Intern intern_type;
0196 typedef Extern extern_type;
0197 typedef State state_type;
0198 codecvt_helper(std::size_t refs = 0)
0199 #if !defined(BOOST_IOSTREAMS_NO_CODECVT_CTOR_FROM_SIZE_T)
0200 : std::codecvt<Intern, Extern, State>(refs)
0201 #else
0202 : std::codecvt<Intern, Extern, State>()
0203 #endif
0204 { }
0205 #ifdef BOOST_IOSTREAMS_NO_CODECVT_MAX_LENGTH
0206 int max_length() const throw() { return do_max_length(); }
0207 protected:
0208 virtual int do_max_length() const throw() { return 1; }
0209 #endif
0210 };
0211
0212 } } }
0213
0214 #endif