]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | { | |
92f5a8d4 TL |
21 | template <typename Char, typename CharSet> |
22 | bool in_set(Char ch, CharSet const& set) | |
7c673cae FG |
23 | { |
24 | return set.test(ch); | |
25 | } | |
26 | ||
92f5a8d4 TL |
27 | template <typename Char> |
28 | int32_t operator()(Char lc, Char rc) const | |
7c673cae FG |
29 | { |
30 | return lc - rc; | |
31 | } | |
32 | ||
7c673cae FG |
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 | { | |
92f5a8d4 TL |
43 | template <typename Char, typename CharSet> |
44 | bool in_set(Char ch_, CharSet const& set) | |
7c673cae | 45 | { |
92f5a8d4 TL |
46 | using char_type = typename Encoding::classify_type; |
47 | auto ch = char_type(ch_); | |
7c673cae | 48 | return set.test(ch) |
92f5a8d4 TL |
49 | || set.test(Encoding::islower(ch) |
50 | ? Encoding::toupper(ch) : Encoding::tolower(ch)); | |
7c673cae FG |
51 | } |
52 | ||
92f5a8d4 TL |
53 | template <typename Char> |
54 | int32_t operator()(Char lc_, Char const rc_) const | |
7c673cae | 55 | { |
92f5a8d4 TL |
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; | |
7c673cae FG |
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 | } | |
92f5a8d4 | 98 | |
7c673cae FG |
99 | auto const no_case_compare_ = no_case_tag{}; |
100 | ||
101 | }}} | |
102 | ||
103 | #endif |