Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 ==============================================================================*/
|
Chris@16
|
7 #if !defined(BOOST_SPIRIT_CHAR_CLASS_APRIL_16_2006_1051AM)
|
Chris@16
|
8 #define BOOST_SPIRIT_CHAR_CLASS_APRIL_16_2006_1051AM
|
Chris@16
|
9
|
Chris@16
|
10 #if defined(_MSC_VER)
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/spirit/home/qi/char/char_parser.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/qi/domain.hpp>
|
Chris@16
|
16 #include <boost/spirit/home/support/char_class.hpp>
|
Chris@16
|
17 #include <boost/spirit/home/support/common_terminals.hpp>
|
Chris@16
|
18 #include <boost/spirit/home/support/info.hpp>
|
Chris@16
|
19 #include <boost/spirit/home/support/modify.hpp>
|
Chris@16
|
20 #include <boost/spirit/home/support/detail/get_encoding.hpp>
|
Chris@16
|
21 #include <boost/mpl/eval_if.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost { namespace spirit
|
Chris@16
|
24 {
|
Chris@16
|
25 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
26 // Enablers
|
Chris@16
|
27 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
28 // enables alnum, alpha, graph, etc.
|
Chris@16
|
29 template <typename CharClass, typename CharEncoding>
|
Chris@16
|
30 struct use_terminal<qi::domain, tag::char_code<CharClass, CharEncoding> >
|
Chris@16
|
31 : mpl::true_ {};
|
Chris@16
|
32 }}
|
Chris@16
|
33
|
Chris@16
|
34 namespace boost { namespace spirit { namespace qi
|
Chris@16
|
35 {
|
Chris@16
|
36 // hoist the char classification namespaces into qi sub-namespaces of the
|
Chris@16
|
37 // same name
|
Chris@16
|
38 namespace ascii { using namespace boost::spirit::ascii; }
|
Chris@16
|
39 namespace iso8859_1 { using namespace boost::spirit::iso8859_1; }
|
Chris@16
|
40 namespace standard { using namespace boost::spirit::standard; }
|
Chris@16
|
41 namespace standard_wide { using namespace boost::spirit::standard_wide; }
|
Chris@16
|
42 #if defined(BOOST_SPIRIT_UNICODE)
|
Chris@16
|
43 namespace unicode { using namespace boost::spirit::unicode; }
|
Chris@16
|
44 #endif
|
Chris@16
|
45
|
Chris@16
|
46 // Import the standard namespace into the qi namespace. This allows
|
Chris@16
|
47 // for default handling of all character/string related operations if not
|
Chris@16
|
48 // prefixed with a character set namespace.
|
Chris@16
|
49 using namespace boost::spirit::standard;
|
Chris@16
|
50
|
Chris@16
|
51 // Import encoding
|
Chris@16
|
52 using spirit::encoding;
|
Chris@16
|
53
|
Chris@16
|
54 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
55 // Generic char classification parser (for alnum, alpha, graph, etc.)
|
Chris@16
|
56 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
57 template <typename Tag>
|
Chris@16
|
58 struct char_class
|
Chris@16
|
59 : char_parser<char_class<Tag>, typename Tag::char_encoding::char_type>
|
Chris@16
|
60 {
|
Chris@16
|
61 typedef typename Tag::char_encoding char_encoding;
|
Chris@16
|
62 typedef typename Tag::char_class classification;
|
Chris@16
|
63
|
Chris@16
|
64 template <typename CharParam, typename Context>
|
Chris@16
|
65 bool test(CharParam ch, Context&) const
|
Chris@16
|
66 {
|
Chris@16
|
67 using spirit::char_class::classify;
|
Chris@16
|
68 return traits::ischar<CharParam, char_encoding>::call(ch) &&
|
Chris@16
|
69 classify<char_encoding>::is(classification(), ch);
|
Chris@16
|
70 }
|
Chris@16
|
71
|
Chris@16
|
72 template <typename Context>
|
Chris@16
|
73 info what(Context& /*context*/) const
|
Chris@16
|
74 {
|
Chris@16
|
75 typedef spirit::char_class::what<char_encoding> what_;
|
Chris@16
|
76 return info(what_::is(classification()));
|
Chris@16
|
77 }
|
Chris@16
|
78 };
|
Chris@16
|
79
|
Chris@16
|
80 namespace detail
|
Chris@16
|
81 {
|
Chris@16
|
82 template <typename Tag, bool no_case = false>
|
Chris@16
|
83 struct make_char_class : mpl::identity<Tag> {};
|
Chris@16
|
84
|
Chris@16
|
85 template <>
|
Chris@16
|
86 struct make_char_class<tag::lower, true> : mpl::identity<tag::alpha> {};
|
Chris@16
|
87
|
Chris@16
|
88 template <>
|
Chris@16
|
89 struct make_char_class<tag::upper, true> : mpl::identity<tag::alpha> {};
|
Chris@16
|
90 }
|
Chris@16
|
91
|
Chris@16
|
92 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
93 // Parser generators: make_xxx function (objects)
|
Chris@16
|
94 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
95 template <typename CharClass, typename CharEncoding, typename Modifiers>
|
Chris@16
|
96 struct make_primitive<tag::char_code<CharClass, CharEncoding>, Modifiers>
|
Chris@16
|
97 {
|
Chris@16
|
98 static bool const no_case =
|
Chris@16
|
99 has_modifier<Modifiers, tag::char_code_base<tag::no_case> >::value;
|
Chris@16
|
100
|
Chris@16
|
101 typedef typename
|
Chris@16
|
102 spirit::detail::get_encoding<Modifiers, CharEncoding>::type
|
Chris@16
|
103 char_encoding;
|
Chris@16
|
104
|
Chris@16
|
105 typedef tag::char_code<
|
Chris@16
|
106 typename detail::make_char_class<CharClass, no_case>::type
|
Chris@16
|
107 , char_encoding>
|
Chris@16
|
108 tag;
|
Chris@16
|
109
|
Chris@16
|
110 typedef char_class<tag> result_type;
|
Chris@16
|
111 result_type operator()(unused_type, unused_type) const
|
Chris@16
|
112 {
|
Chris@16
|
113 return result_type();
|
Chris@16
|
114 }
|
Chris@16
|
115 };
|
Chris@16
|
116 }}}
|
Chris@16
|
117
|
Chris@16
|
118 #endif
|