| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2014 Joel de Guzman |
| 3 | |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | ==============================================================================*/ |
| 7 | #if !defined(BOOST_SPIRIT_X3_SUPPORT_NO_CASE_SEPT_24_2014_1125PM) |
| 8 | #define BOOST_SPIRIT_X3_SUPPORT_NO_CASE_SEPT_24_2014_1125PM |
| 9 | |
| 10 | #include <boost/spirit/home/x3/support/unused.hpp> |
| 11 | #include <boost/spirit/home/x3/support/context.hpp> |
| 12 | #include <boost/spirit/home/x3/char/char_class_tags.hpp> |
| 13 | |
| 14 | namespace boost { namespace spirit { namespace x3 |
| 15 | { |
| 16 | struct no_case_tag {}; |
| 17 | |
| 18 | template <typename Encoding> |
| 19 | struct case_compare |
| 20 | { |
| 21 | template <typename Char, typename CharSet> |
| 22 | bool in_set(Char ch, CharSet const& set) |
| 23 | { |
| 24 | return set.test(ch); |
| 25 | } |
| 26 | |
| 27 | template <typename Char> |
| 28 | int32_t operator()(Char lc, Char rc) const |
| 29 | { |
| 30 | return lc - rc; |
| 31 | } |
| 32 | |
| 33 | template <typename CharClassTag> |
| 34 | CharClassTag get_char_class_tag(CharClassTag tag) const |
| 35 | { |
| 36 | return tag; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | template <typename Encoding> |
| 41 | struct no_case_compare |
| 42 | { |
| 43 | template <typename Char, typename CharSet> |
| 44 | bool in_set(Char ch_, CharSet const& set) |
| 45 | { |
| 46 | using char_type = typename Encoding::classify_type; |
| 47 | auto ch = char_type(ch_); |
| 48 | return set.test(ch) |
| 49 | || set.test(Encoding::islower(ch) |
| 50 | ? Encoding::toupper(ch) : Encoding::tolower(ch)); |
| 51 | } |
| 52 | |
| 53 | template <typename Char> |
| 54 | int32_t operator()(Char lc_, Char const rc_) const |
| 55 | { |
| 56 | using char_type = typename Encoding::classify_type; |
| 57 | auto lc = char_type(lc_); |
| 58 | auto rc = char_type(rc_); |
| 59 | return Encoding::islower(rc) |
| 60 | ? Encoding::tolower(lc) - rc : Encoding::toupper(lc) - rc; |
| 61 | } |
| 62 | |
| 63 | template <typename CharClassTag> |
| 64 | CharClassTag get_char_class_tag(CharClassTag tag) const |
| 65 | { |
| 66 | return tag; |
| 67 | } |
| 68 | |
| 69 | alpha_tag get_char_class_tag(lower_tag ) const |
| 70 | { |
| 71 | return {}; |
| 72 | } |
| 73 | |
| 74 | alpha_tag get_char_class_tag(upper_tag ) const |
| 75 | { |
| 76 | return {}; |
| 77 | } |
| 78 | |
| 79 | }; |
| 80 | |
| 81 | template <typename Encoding> |
| 82 | case_compare<Encoding> get_case_compare_impl(unused_type const&) |
| 83 | { |
| 84 | return {}; |
| 85 | } |
| 86 | |
| 87 | template <typename Encoding> |
| 88 | no_case_compare<Encoding> get_case_compare_impl(no_case_tag const&) |
| 89 | { |
| 90 | return {}; |
| 91 | } |
| 92 | |
| 93 | template <typename Encoding, typename Context> |
| 94 | inline decltype(auto) get_case_compare(Context const& context) |
| 95 | { |
| 96 | return get_case_compare_impl<Encoding>(x3::get<no_case_tag>(context)); |
| 97 | } |
| 98 | |
| 99 | auto const no_case_compare_ = no_case_tag{}; |
| 100 | |
| 101 | }}} |
| 102 | |
| 103 | #endif |
| 104 | |