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> literal_charboost::spirit::x3::literal_char26 constexpr literal_char(Char ch) 27 : ch(static_cast<char_type>(ch)) {} 28 29 template <typename Char, typename Context> testboost::spirit::x3::literal_char30 bool test(Char ch_, Context const& context) const 31 { 32 return get_case_compare<encoding>(context)(ch, char_type(ch_)) == 0; 33 } 34 35 char_type ch; 36 }; 37 38 template <typename Encoding, typename Attribute> 39 struct get_info<literal_char<Encoding, Attribute>> 40 { 41 typedef std::string result_type; operator ()boost::spirit::x3::get_info42 std::string operator()(literal_char<Encoding, Attribute> const& p) const 43 { 44 return '\'' + to_utf8(Encoding::toucs4(p.ch)) + '\''; 45 } 46 }; 47 }}} 48 49 #endif 50