1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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_CHAR_CLASS_APRIL_16_2006_1051AM)
8 #define BOOST_SPIRIT_CHAR_CLASS_APRIL_16_2006_1051AM
14 #include <boost/spirit/home/qi/char/char_parser.hpp>
15 #include <boost/spirit/home/qi/domain.hpp>
16 #include <boost/spirit/home/support/char_class.hpp>
17 #include <boost/spirit/home/support/common_terminals.hpp>
18 #include <boost/spirit/home/support/info.hpp>
19 #include <boost/spirit/home/support/modify.hpp>
20 #include <boost/spirit/home/support/detail/get_encoding.hpp>
21 #include <boost/mpl/eval_if.hpp>
23 namespace boost { namespace spirit
25 ///////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////
28 // enables alnum, alpha, graph, etc.
29 template <typename CharClass, typename CharEncoding>
30 struct use_terminal<qi::domain, tag::char_code<CharClass, CharEncoding> >
34 namespace boost { namespace spirit { namespace qi
36 // hoist the char classification namespaces into qi sub-namespaces of the
38 namespace ascii { using namespace boost::spirit::ascii; }
39 namespace iso8859_1 { using namespace boost::spirit::iso8859_1; }
40 namespace standard { using namespace boost::spirit::standard; }
41 namespace standard_wide { using namespace boost::spirit::standard_wide; }
42 #if defined(BOOST_SPIRIT_UNICODE)
43 namespace unicode { using namespace boost::spirit::unicode; }
46 // Import the standard namespace into the qi namespace. This allows
47 // for default handling of all character/string related operations if not
48 // prefixed with a character set namespace.
49 using namespace boost::spirit::standard;
52 using spirit::encoding;
54 ///////////////////////////////////////////////////////////////////////////
55 // Generic char classification parser (for alnum, alpha, graph, etc.)
56 ///////////////////////////////////////////////////////////////////////////
57 template <typename Tag>
59 : char_parser<char_class<Tag>, typename Tag::char_encoding::char_type>
61 typedef typename Tag::char_encoding char_encoding;
62 typedef typename Tag::char_class classification;
64 template <typename CharParam, typename Context>
65 bool test(CharParam ch, Context&) const
67 using spirit::char_class::classify;
68 return traits::ischar<CharParam, char_encoding>::call(ch) &&
69 classify<char_encoding>::is(classification(), ch);
72 template <typename Context>
73 info what(Context& /*context*/) const
75 typedef spirit::char_class::what<char_encoding> what_;
76 return info(what_::is(classification()));
82 template <typename Tag, bool no_case = false>
83 struct make_char_class : mpl::identity<Tag> {};
86 struct make_char_class<tag::lower, true> : mpl::identity<tag::alpha> {};
89 struct make_char_class<tag::upper, true> : mpl::identity<tag::alpha> {};
92 ///////////////////////////////////////////////////////////////////////////
93 // Parser generators: make_xxx function (objects)
94 ///////////////////////////////////////////////////////////////////////////
95 template <typename CharClass, typename CharEncoding, typename Modifiers>
96 struct make_primitive<tag::char_code<CharClass, CharEncoding>, Modifiers>
98 static bool const no_case =
99 has_modifier<Modifiers, tag::char_code_base<tag::no_case> >::value;
102 spirit::detail::get_encoding<Modifiers, CharEncoding>::type
105 typedef tag::char_code<
106 typename detail::make_char_class<CharClass, no_case>::type
110 typedef char_class<tag> result_type;
111 result_type operator()(unused_type, unused_type) const
113 return result_type();