File indexing completed on 2025-01-18 09:53:52
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_TRAITS_UTILS_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_UTILITY_TRAITS_UTILS_HPP_EAN_10_04_2005
0010
0011
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 # pragma warning(push)
0015 # pragma warning(disable : 4100)
0016 #endif
0017
0018 #include <string>
0019 #include <boost/mpl/bool.hpp>
0020 #include <boost/mpl/assert.hpp>
0021 #include <boost/utility/enable_if.hpp>
0022 #include <boost/type_traits/is_same.hpp>
0023 #include <boost/iterator/transform_iterator.hpp>
0024 #include <boost/xpressive/detail/utility/algorithm.hpp>
0025
0026 namespace boost { namespace xpressive { namespace detail
0027 {
0028
0029
0030
0031
0032 template<typename ToChar, typename FromChar, typename Traits>
0033 inline ToChar
0034 char_cast(FromChar from, Traits const &, typename enable_if<is_same<ToChar, FromChar> >::type * = 0)
0035 {
0036 return from;
0037 }
0038
0039 template<typename ToChar, typename FromChar, typename Traits>
0040 inline ToChar
0041 char_cast(FromChar from, Traits const &tr, typename disable_if<is_same<ToChar, FromChar> >::type * = 0)
0042 {
0043 BOOST_MPL_ASSERT((is_same<FromChar, char>));
0044 return tr.widen(from);
0045 }
0046
0047
0048
0049
0050 template<typename Traits>
0051 struct widen_fun
0052 {
0053 typedef typename Traits::char_type result_type;
0054 explicit widen_fun(Traits const &tr)
0055 : traits_(tr)
0056 {}
0057
0058 result_type operator()(char ch) const
0059 {
0060 return this->traits_.widen(ch);
0061 }
0062
0063 Traits const &traits_;
0064 };
0065
0066
0067
0068
0069 template<
0070 typename To
0071 , typename From
0072 , typename ToChar = typename detail::range_data<To>::type
0073 , typename FromChar = typename detail::range_data<From>::type
0074 >
0075 struct string_cast_
0076 {
0077 BOOST_MPL_ASSERT((is_same<FromChar, char>));
0078 typedef To const result_type;
0079 template<typename Traits>
0080 result_type operator()(From const &from, Traits const &tr) const
0081 {
0082 widen_fun<Traits> widen(tr);
0083 To to(
0084 boost::make_transform_iterator(detail::data_begin(from), widen)
0085 , boost::make_transform_iterator(detail::data_end(from), widen)
0086 );
0087 return to;
0088 }
0089 };
0090
0091 template<typename To, typename From, typename Char>
0092 struct string_cast_<To, From, Char, Char>
0093 {
0094 typedef To const result_type;
0095 template<typename Traits>
0096 result_type operator()(From const &from, Traits const &) const
0097 {
0098 To to(detail::data_begin(from), detail::data_end(from));
0099 return to;
0100 }
0101 };
0102
0103 template<typename From, typename Char>
0104 struct string_cast_<From, From, Char, Char>
0105 {
0106 typedef From const &result_type;
0107 template<typename Traits>
0108 result_type operator()(From const &from, Traits const &) const
0109 {
0110 return from;
0111 }
0112 };
0113
0114
0115
0116
0117 template<typename To, typename From, typename Traits>
0118 typename string_cast_<To, From>::result_type
0119 string_cast(From const &from, Traits const &tr)
0120 {
0121 return string_cast_<To, From>()(from, tr);
0122 }
0123
0124
0125
0126
0127 template<typename Char, typename Traits>
0128 inline Char translate(Char ch, Traits const &tr, mpl::false_)
0129 {
0130 return tr.translate(ch);
0131 }
0132
0133 template<typename Char, typename Traits>
0134 inline Char translate(Char ch, Traits const &tr, mpl::true_)
0135 {
0136 return tr.translate_nocase(ch);
0137 }
0138
0139 }}}
0140
0141 #if defined(_MSC_VER)
0142 # pragma warning(pop)
0143 #endif
0144
0145 #endif