1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | // traits_utils.hpp |
---|
3 | // |
---|
4 | // Copyright 2004 Eric Niebler. Distributed under the Boost |
---|
5 | // Software License, Version 1.0. (See accompanying file |
---|
6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | |
---|
8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_TRAITS_UTILS_HPP_EAN_10_04_2005 |
---|
9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_TRAITS_UTILS_HPP_EAN_10_04_2005 |
---|
10 | |
---|
11 | // MS compatible compilers support #pragma once |
---|
12 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
13 | # pragma once |
---|
14 | # pragma warning(push) |
---|
15 | # pragma warning(disable : 4100) // unreferenced formal parameter |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <string> |
---|
19 | #include <boost/mpl/bool.hpp> |
---|
20 | #include <boost/mpl/assert.hpp> |
---|
21 | #include <boost/utility/enable_if.hpp> |
---|
22 | #include <boost/type_traits/is_same.hpp> |
---|
23 | |
---|
24 | namespace boost { namespace xpressive { namespace detail |
---|
25 | { |
---|
26 | |
---|
27 | /////////////////////////////////////////////////////////////////////////////// |
---|
28 | // char_cast |
---|
29 | // |
---|
30 | template<typename ToChar, typename FromChar, typename Traits> |
---|
31 | inline ToChar |
---|
32 | char_cast(FromChar from, Traits const &, typename enable_if<is_same<ToChar, FromChar> >::type * = 0) |
---|
33 | { |
---|
34 | return from; |
---|
35 | } |
---|
36 | |
---|
37 | template<typename ToChar, typename FromChar, typename Traits> |
---|
38 | inline ToChar |
---|
39 | char_cast(FromChar from, Traits const &traits, typename disable_if<is_same<ToChar, FromChar> >::type * = 0) |
---|
40 | { |
---|
41 | BOOST_MPL_ASSERT((is_same<FromChar, char>)); |
---|
42 | return traits.widen(from); |
---|
43 | } |
---|
44 | |
---|
45 | /////////////////////////////////////////////////////////////////////////////// |
---|
46 | // string_cast |
---|
47 | // |
---|
48 | template<typename ToChar, typename FromChar, typename Traits> |
---|
49 | inline std::basic_string<ToChar> const & |
---|
50 | string_cast(std::basic_string<FromChar> const &from, Traits const &, typename enable_if<is_same<ToChar, FromChar> >::type * = 0) |
---|
51 | { |
---|
52 | return from; |
---|
53 | } |
---|
54 | |
---|
55 | template<typename ToChar, typename FromChar, typename Traits> |
---|
56 | inline std::basic_string<ToChar> const |
---|
57 | string_cast(std::basic_string<FromChar> const &from, Traits const &traits, typename disable_if<is_same<ToChar, FromChar> >::type * = 0) |
---|
58 | { |
---|
59 | BOOST_MPL_ASSERT((is_same<FromChar, char>)); |
---|
60 | std::basic_string<ToChar> to; |
---|
61 | to.reserve(from.size()); |
---|
62 | for(typename std::basic_string<FromChar>::size_type i = 0; i < from.size(); ++i) |
---|
63 | { |
---|
64 | to.push_back(traits.widen(from[i])); |
---|
65 | } |
---|
66 | return to; |
---|
67 | } |
---|
68 | |
---|
69 | /////////////////////////////////////////////////////////////////////////////// |
---|
70 | // translate |
---|
71 | // |
---|
72 | template<typename Char, typename Traits> |
---|
73 | inline Char translate(Char ch, Traits const &traits, mpl::false_) // case-sensitive |
---|
74 | { |
---|
75 | return traits.translate(ch); |
---|
76 | } |
---|
77 | |
---|
78 | template<typename Char, typename Traits> |
---|
79 | inline Char translate(Char ch, Traits const &traits, mpl::true_) // case-insensitive |
---|
80 | { |
---|
81 | return traits.translate_nocase(ch); |
---|
82 | } |
---|
83 | |
---|
84 | }}} // namespace boost::xpressive::detail |
---|
85 | |
---|
86 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
87 | # pragma warning(pop) |
---|
88 | #endif |
---|
89 | |
---|
90 | #endif |
---|