1 /*=============================================================================
2 Copyright (c) 2001-2014 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_X3_LITERAL_CHAR_APRIL_16_2006_1051AM)
8 #define BOOST_SPIRIT_X3_LITERAL_CHAR_APRIL_16_2006_1051AM
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>
14 namespace boost { namespace spirit { namespace x3
16 template <typename Encoding, typename Attribute = typename Encoding::char_type>
17 struct literal_char : char_parser<literal_char<Encoding, Attribute>>
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;
25 template <typename Char>
27 : ch(static_cast<char_type>(ch)) {}
29 template <typename Char, typename Context>
30 bool test(Char ch_, Context const& context) const
32 return ((sizeof(Char) <= sizeof(char_type)) || encoding::ischar(ch_))
33 && (get_case_compare<encoding>(context)(ch, char_type(ch_)) == 0);
39 template <typename Encoding, typename Attribute>
40 struct get_info<literal_char<Encoding, Attribute>>
42 typedef std::string result_type;
43 std::string operator()(literal_char<Encoding, Attribute> const& p) const
45 return '\'' + to_utf8(Encoding::toucs4(p.ch)) + '\'';