]>
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_CHAR_CLASS_APRIL_16_2006_1051AM) | |
8 | #define BOOST_SPIRIT_X3_CHAR_CLASS_APRIL_16_2006_1051AM | |
9 | ||
10 | #include <boost/spirit/home/x3/char/char_parser.hpp> | |
11 | #include <boost/spirit/home/x3/char/detail/cast_char.hpp> | |
12 | #include <boost/spirit/home/support/char_encoding/standard.hpp> | |
13 | #include <boost/spirit/home/support/char_encoding/standard_wide.hpp> | |
14 | #include <boost/spirit/home/support/char_encoding/ascii.hpp> | |
15 | #include <boost/spirit/home/support/char_encoding/iso8859_1.hpp> | |
16 | #include <boost/spirit/home/x3/char/char_class_tags.hpp> | |
17 | namespace boost { namespace spirit { namespace x3 | |
18 | { | |
19 | /////////////////////////////////////////////////////////////////////////// | |
20 | template <typename Encoding> | |
21 | struct char_class_base | |
22 | { | |
1e59de90 | 23 | typedef typename Encoding::classify_type char_type; |
7c673cae | 24 | |
92f5a8d4 | 25 | #define BOOST_SPIRIT_X3_CLASSIFY(name) \ |
7c673cae FG |
26 | template <typename Char> \ |
27 | static bool \ | |
28 | is(name##_tag, Char ch) \ | |
29 | { \ | |
30 | return Encoding::is##name \ | |
31 | BOOST_PREVENT_MACRO_SUBSTITUTION \ | |
32 | (detail::cast_char<char_type>(ch)); \ | |
33 | } \ | |
34 | /***/ | |
35 | ||
36 | BOOST_SPIRIT_X3_CLASSIFY(char) | |
37 | BOOST_SPIRIT_X3_CLASSIFY(alnum) | |
38 | BOOST_SPIRIT_X3_CLASSIFY(alpha) | |
39 | BOOST_SPIRIT_X3_CLASSIFY(digit) | |
40 | BOOST_SPIRIT_X3_CLASSIFY(xdigit) | |
41 | BOOST_SPIRIT_X3_CLASSIFY(cntrl) | |
42 | BOOST_SPIRIT_X3_CLASSIFY(graph) | |
43 | BOOST_SPIRIT_X3_CLASSIFY(lower) | |
44 | BOOST_SPIRIT_X3_CLASSIFY(print) | |
45 | BOOST_SPIRIT_X3_CLASSIFY(punct) | |
46 | BOOST_SPIRIT_X3_CLASSIFY(space) | |
47 | BOOST_SPIRIT_X3_CLASSIFY(blank) | |
48 | BOOST_SPIRIT_X3_CLASSIFY(upper) | |
49 | ||
50 | #undef BOOST_SPIRIT_X3_CLASSIFY | |
51 | }; | |
52 | ||
53 | template <typename Encoding, typename Tag> | |
54 | struct char_class | |
55 | : char_parser<char_class<Encoding, Tag>> | |
56 | { | |
57 | typedef Encoding encoding; | |
58 | typedef Tag tag; | |
59 | typedef typename Encoding::char_type char_type; | |
60 | typedef char_type attribute_type; | |
61 | static bool const has_attribute = true; | |
62 | ||
63 | template <typename Char, typename Context> | |
64 | bool test(Char ch, Context const& context) const | |
65 | { | |
92f5a8d4 | 66 | return encoding::ischar(ch) |
7c673cae FG |
67 | && char_class_base<Encoding>::is( |
68 | get_case_compare<Encoding>(context).get_char_class_tag(tag()), ch); | |
69 | } | |
70 | }; | |
71 | ||
72 | #define BOOST_SPIRIT_X3_CHAR_CLASS(encoding, name) \ | |
92f5a8d4 | 73 | typedef char_class<char_encoding::encoding, name##_tag> name##_type; \ |
f67539c2 | 74 | constexpr name##_type name = name##_type(); \ |
7c673cae FG |
75 | /***/ |
76 | ||
77 | #define BOOST_SPIRIT_X3_CHAR_CLASSES(encoding) \ | |
92f5a8d4 TL |
78 | namespace encoding \ |
79 | { \ | |
7c673cae FG |
80 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, alnum) \ |
81 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, alpha) \ | |
82 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, digit) \ | |
83 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, xdigit) \ | |
84 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, cntrl) \ | |
85 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, graph) \ | |
86 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, lower) \ | |
87 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, print) \ | |
88 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, punct) \ | |
89 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, space) \ | |
90 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, blank) \ | |
91 | BOOST_SPIRIT_X3_CHAR_CLASS(encoding, upper) \ | |
92f5a8d4 | 92 | } \ |
7c673cae FG |
93 | /***/ |
94 | ||
95 | BOOST_SPIRIT_X3_CHAR_CLASSES(standard) | |
b32b8144 | 96 | #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE |
7c673cae | 97 | BOOST_SPIRIT_X3_CHAR_CLASSES(standard_wide) |
b32b8144 | 98 | #endif |
7c673cae FG |
99 | BOOST_SPIRIT_X3_CHAR_CLASSES(ascii) |
100 | BOOST_SPIRIT_X3_CHAR_CLASSES(iso8859_1) | |
101 | ||
102 | #undef BOOST_SPIRIT_X3_CHAR_CLASS | |
103 | #undef BOOST_SPIRIT_X3_CHAR_CLASSES | |
104 | ||
105 | using standard::alnum_type; | |
106 | using standard::alpha_type; | |
107 | using standard::digit_type; | |
108 | using standard::xdigit_type; | |
109 | using standard::cntrl_type; | |
110 | using standard::graph_type; | |
111 | using standard::lower_type; | |
112 | using standard::print_type; | |
113 | using standard::punct_type; | |
114 | using standard::space_type; | |
115 | using standard::blank_type; | |
116 | using standard::upper_type; | |
117 | ||
118 | using standard::alnum; | |
119 | using standard::alpha; | |
120 | using standard::digit; | |
121 | using standard::xdigit; | |
122 | using standard::cntrl; | |
123 | using standard::graph; | |
124 | using standard::lower; | |
125 | using standard::print; | |
126 | using standard::punct; | |
127 | using standard::space; | |
128 | using standard::blank; | |
129 | using standard::upper; | |
130 | }}} | |
131 | ||
132 | #endif |