]>
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_LITERAL_CHAR_APRIL_16_2006_1051AM) | |
8 | #define BOOST_SPIRIT_X3_LITERAL_CHAR_APRIL_16_2006_1051AM | |
9 | ||
10 | #include <boost/spirit/home/x3/char/char_parser.hpp> | |
11 | #include <boost/spirit/home/x3/support/utility/utf8.hpp> | |
12 | #include <boost/type_traits/is_same.hpp> | |
13 | ||
14 | namespace boost { namespace spirit { namespace x3 | |
15 | { | |
16 | template <typename Encoding, typename Attribute = typename Encoding::char_type> | |
17 | struct literal_char : char_parser<literal_char<Encoding, Attribute>> | |
18 | { | |
19 | typedef typename Encoding::char_type char_type; | |
20 | typedef Encoding encoding; | |
21 | typedef Attribute attribute_type; | |
22 | static bool const has_attribute = | |
23 | !is_same<unused_type, attribute_type>::value; | |
24 | ||
25 | template <typename Char> | |
26 | literal_char(Char ch) | |
27 | : ch(static_cast<char_type>(ch)) {} | |
28 | ||
29 | template <typename Char, typename Context> | |
30 | bool test(Char ch_, Context const& context) const | |
31 | { | |
32 | return ((sizeof(Char) <= sizeof(char_type)) || encoding::ischar(ch_)) | |
33 | && (get_case_compare<encoding>(context)(ch, char_type(ch_)) == 0); | |
34 | } | |
35 | ||
36 | char_type ch; | |
37 | }; | |
38 | ||
39 | template <typename Encoding, typename Attribute> | |
40 | struct get_info<literal_char<Encoding, Attribute>> | |
41 | { | |
42 | typedef std::string result_type; | |
43 | std::string operator()(literal_char<Encoding, Attribute> const& p) const | |
44 | { | |
45 | return '\'' + to_utf8(Encoding::toucs4(p.ch)) + '\''; | |
46 | } | |
47 | }; | |
48 | }}} | |
49 | ||
50 | #endif |