comparison DEPENDENCIES/generic/include/boost/spirit/home/x3/char/char_class.hpp @ 102:f46d142149f5

Whoops, finish that update
author Chris Cannam
date Mon, 07 Sep 2015 11:13:41 +0100
parents
children
comparison
equal deleted inserted replaced
101:c530137014c0 102:f46d142149f5
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 #if defined(_MSC_VER)
11 #pragma once
12 #endif
13
14 #include <boost/spirit/home/x3/char/char_parser.hpp>
15 #include <boost/spirit/home/x3/char/detail/cast_char.hpp>
16 #include <boost/spirit/home/support/char_encoding/standard.hpp>
17 #include <boost/spirit/home/support/char_encoding/standard_wide.hpp>
18 #include <boost/spirit/home/support/char_encoding/ascii.hpp>
19 #include <boost/spirit/home/support/char_encoding/iso8859_1.hpp>
20
21 namespace boost { namespace spirit { namespace x3
22 {
23 ///////////////////////////////////////////////////////////////////////////
24 struct char_tag {};
25 struct alnum_tag {};
26 struct alpha_tag {};
27 struct blank_tag {};
28 struct cntrl_tag {};
29 struct digit_tag {};
30 struct graph_tag {};
31 struct print_tag {};
32 struct punct_tag {};
33 struct space_tag {};
34 struct xdigit_tag {};
35 struct lower_tag {};
36 struct upper_tag {};
37
38 ///////////////////////////////////////////////////////////////////////////
39 template <typename Encoding>
40 struct char_class_base
41 {
42 typedef typename Encoding::char_type char_type;
43
44 #define BOOST_SPIRIT_X3_CLASSIFY(name) \
45 template <typename Char> \
46 static bool \
47 is(name##_tag, Char ch) \
48 { \
49 return Encoding::is##name \
50 BOOST_PREVENT_MACRO_SUBSTITUTION \
51 (detail::cast_char<char_type>(ch)); \
52 } \
53 /***/
54
55 BOOST_SPIRIT_X3_CLASSIFY(char)
56 BOOST_SPIRIT_X3_CLASSIFY(alnum)
57 BOOST_SPIRIT_X3_CLASSIFY(alpha)
58 BOOST_SPIRIT_X3_CLASSIFY(digit)
59 BOOST_SPIRIT_X3_CLASSIFY(xdigit)
60 BOOST_SPIRIT_X3_CLASSIFY(cntrl)
61 BOOST_SPIRIT_X3_CLASSIFY(graph)
62 BOOST_SPIRIT_X3_CLASSIFY(lower)
63 BOOST_SPIRIT_X3_CLASSIFY(print)
64 BOOST_SPIRIT_X3_CLASSIFY(punct)
65 BOOST_SPIRIT_X3_CLASSIFY(space)
66 BOOST_SPIRIT_X3_CLASSIFY(blank)
67 BOOST_SPIRIT_X3_CLASSIFY(upper)
68
69 #undef BOOST_SPIRIT_X3_CLASSIFY
70 };
71
72 template <typename Encoding, typename Tag>
73 struct char_class
74 : char_parser<char_class<Encoding, Tag>>
75 {
76 typedef Encoding encoding;
77 typedef Tag tag;
78 typedef typename Encoding::char_type char_type;
79 typedef char_type attribute_type;
80 static bool const has_attribute = true;
81
82 template <typename Char, typename Context>
83 bool test(Char ch, Context const&) const
84 {
85 return ((sizeof(Char) <= sizeof(char_type)) || encoding::ischar(ch))
86 && char_class_base<Encoding>::is(tag(), ch);
87 }
88 };
89
90 #define BOOST_SPIRIT_X3_CHAR_CLASS(encoding, name) \
91 typedef char_class<char_encoding::encoding, name##_tag> name##_type; \
92 name##_type const name = name##_type(); \
93 /***/
94
95 #define BOOST_SPIRIT_X3_CHAR_CLASSES(encoding) \
96 namespace encoding \
97 { \
98 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, alnum) \
99 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, alpha) \
100 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, digit) \
101 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, xdigit) \
102 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, cntrl) \
103 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, graph) \
104 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, lower) \
105 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, print) \
106 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, punct) \
107 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, space) \
108 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, blank) \
109 BOOST_SPIRIT_X3_CHAR_CLASS(encoding, upper) \
110 } \
111 /***/
112
113 BOOST_SPIRIT_X3_CHAR_CLASSES(standard)
114 BOOST_SPIRIT_X3_CHAR_CLASSES(standard_wide)
115 BOOST_SPIRIT_X3_CHAR_CLASSES(ascii)
116 BOOST_SPIRIT_X3_CHAR_CLASSES(iso8859_1)
117
118 #undef BOOST_SPIRIT_X3_CHAR_CLASS
119 #undef BOOST_SPIRIT_X3_CHAR_CLASSES
120
121 using standard::alnum_type;
122 using standard::alpha_type;
123 using standard::digit_type;
124 using standard::xdigit_type;
125 using standard::cntrl_type;
126 using standard::graph_type;
127 using standard::lower_type;
128 using standard::print_type;
129 using standard::punct_type;
130 using standard::space_type;
131 using standard::blank_type;
132 using standard::upper_type;
133
134 using standard::alnum;
135 using standard::alpha;
136 using standard::digit;
137 using standard::xdigit;
138 using standard::cntrl;
139 using standard::graph;
140 using standard::lower;
141 using standard::print;
142 using standard::punct;
143 using standard::space;
144 using standard::blank;
145 using standard::upper;
146 }}}
147
148 #endif