/*============================================================================= Copyright (c) 2001-2014 Joel de Guzman Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #if !defined(BOOST_SPIRIT_X3_CHAR_SET_OCT_12_2014_1051AM) #define BOOST_SPIRIT_X3_CHAR_SET_OCT_12_2014_1051AM #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace x3 { /////////////////////////////////////////////////////////////////////////// // Parser for a character range /////////////////////////////////////////////////////////////////////////// template struct char_range : char_parser< char_range > { typedef typename Encoding::char_type char_type; typedef Encoding encoding; typedef Attribute attribute_type; static bool const has_attribute = !is_same::value; char_range(char_type from_, char_type to_) : from(from_), to(to_) {} template bool test(Char ch_, Context& context) const { char_type ch = char_type(ch_); // optimize for token based parsing return ((sizeof(Char) <= sizeof(char_type)) || encoding::ischar(ch_)) && (get_case_compare(context)(ch, from) >= 0 ) && (get_case_compare(context)(ch , to) <= 0 ); } char_type from, to; }; /////////////////////////////////////////////////////////////////////////// // Parser for a character set /////////////////////////////////////////////////////////////////////////// template struct char_set : char_parser> { typedef typename Encoding::char_type char_type; typedef Encoding encoding; typedef Attribute attribute_type; static bool const has_attribute = !is_same::value; template char_set(String const& str) { using spirit::x3::detail::cast_char; typedef typename remove_const< typename traits::char_type_of::type >::type in_type; in_type const* definition = (in_type const*)traits::get_c_string(str); in_type ch = *definition++; while (ch) { in_type next = *definition++; if (next == '-') { next = *definition++; if (next == 0) { chset.set(cast_char(ch)); chset.set('-'); break; } chset.set( cast_char(ch), cast_char(next) ); } else { chset.set(cast_char(ch)); } ch = next; } } template bool test(Char ch_, Context const& context) const { return ((sizeof(Char) <= sizeof(char_type)) || encoding::ischar(ch_)) && get_case_compare(context).in_set(ch_,chset); } support::detail::basic_chset chset; }; template struct get_info> { typedef std::string result_type; std::string operator()(char_set const& /* p */) const { return "char-set"; } }; template struct get_info> { typedef std::string result_type; std::string operator()(char_range const& p) const { return "char_range \"" + to_utf8(Encoding::toucs4(p.from)) + '-' + to_utf8(Encoding::toucs4(p.to))+ '"'; } }; }}} #endif