File indexing completed on 2025-01-31 10:02:34
0001
0002
0003
0004
0005
0006
0007 #if !defined(BOOST_SPIRIT_X3_CHAR_SET_OCT_12_2014_1051AM)
0008 #define BOOST_SPIRIT_X3_CHAR_SET_OCT_12_2014_1051AM
0009
0010 #include <boost/spirit/home/x3/char/char_parser.hpp>
0011 #include <boost/spirit/home/x3/char/detail/cast_char.hpp>
0012 #include <boost/spirit/home/x3/support/traits/string_traits.hpp>
0013 #include <boost/spirit/home/x3/support/utility/utf8.hpp>
0014 #include <boost/spirit/home/x3/support/no_case.hpp>
0015 #include <boost/spirit/home/support/char_set/basic_chset.hpp>
0016
0017 #include <boost/type_traits/is_same.hpp>
0018
0019 namespace boost { namespace spirit { namespace x3
0020 {
0021
0022
0023
0024 template <typename Encoding, typename Attribute = typename Encoding::char_type>
0025 struct char_range
0026 : char_parser< char_range<Encoding, Attribute> >
0027 {
0028
0029 typedef typename Encoding::char_type char_type;
0030 typedef Encoding encoding;
0031 typedef Attribute attribute_type;
0032 static bool const has_attribute =
0033 !is_same<unused_type, attribute_type>::value;
0034
0035
0036 constexpr char_range(char_type from_, char_type to_)
0037 : from(from_), to(to_) {}
0038
0039 template <typename Char, typename Context>
0040 bool test(Char ch_, Context const& context) const
0041 {
0042
0043 char_type ch = char_type(ch_);
0044 return (get_case_compare<encoding>(context)(ch, from) >= 0)
0045 && (get_case_compare<encoding>(context)(ch , to) <= 0);
0046 }
0047
0048 char_type from, to;
0049 };
0050
0051
0052
0053
0054
0055 template <typename Encoding, typename Attribute = typename Encoding::char_type>
0056 struct char_set : char_parser<char_set<Encoding, Attribute>>
0057 {
0058 typedef typename Encoding::char_type char_type;
0059 typedef Encoding encoding;
0060 typedef Attribute attribute_type;
0061 static bool const has_attribute =
0062 !is_same<unused_type, attribute_type>::value;
0063
0064 template <typename String>
0065 char_set(String const& str)
0066 {
0067 using spirit::x3::detail::cast_char;
0068
0069 auto* definition = traits::get_c_string(str);
0070 auto ch = *definition++;
0071 while (ch)
0072 {
0073 auto next = *definition++;
0074 if (next == '-')
0075 {
0076 next = *definition++;
0077 if (next == 0)
0078 {
0079 chset.set(cast_char<char_type>(ch));
0080 chset.set('-');
0081 break;
0082 }
0083 chset.set(
0084 cast_char<char_type>(ch),
0085 cast_char<char_type>(next)
0086 );
0087 }
0088 else
0089 {
0090 chset.set(cast_char<char_type>(ch));
0091 }
0092 ch = next;
0093 }
0094 }
0095
0096 template <typename Char, typename Context>
0097 bool test(Char ch_, Context const& context) const
0098 {
0099 return get_case_compare<encoding>(context).in_set(ch_, chset);
0100 }
0101
0102 support::detail::basic_chset<char_type> chset;
0103 };
0104
0105 template <typename Encoding, typename Attribute>
0106 struct get_info<char_set<Encoding, Attribute>>
0107 {
0108 typedef std::string result_type;
0109 std::string operator()(char_set<Encoding, Attribute> const& ) const
0110 {
0111 return "char-set";
0112 }
0113 };
0114
0115 template <typename Encoding, typename Attribute>
0116 struct get_info<char_range<Encoding, Attribute>>
0117 {
0118 typedef std::string result_type;
0119 std::string operator()(char_range<Encoding, Attribute> const& p) const
0120 {
0121 return "char_range \"" + to_utf8(Encoding::toucs4(p.from)) + '-' + to_utf8(Encoding::toucs4(p.to))+ '"';
0122 }
0123 };
0124
0125 }}}
0126
0127 #endif