1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*=============================================================================
Copyright (c) 2001-2003 Joel de Guzman
Copyright (c) 2001-2003 Daniel Nuffer
http://spirit.sourceforge.net/
Use, modification and distribution is subject to 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)
=============================================================================*/
#ifndef BOOST_XPRESSIVE_SPIRIT_BASIC_CHSET_HPP_EAN_10_04_2005
#define BOOST_XPRESSIVE_SPIRIT_BASIC_CHSET_HPP_EAN_10_04_2005
///////////////////////////////////////////////////////////////////////////////
#include <bitset>
#include <boost/mpl/bool.hpp>
#include <boost/xpressive/detail/utility/chset/range_run.ipp>
namespace boost { namespace xpressive { namespace detail
{
///////////////////////////////////////////////////////////////////////////
//
// basic_chset: basic character set implementation using range_run
//
///////////////////////////////////////////////////////////////////////////
template<typename Char>
struct basic_chset
{
basic_chset();
basic_chset(basic_chset const &arg);
bool empty() const;
void set(Char from, Char to);
template<typename Traits>
void set(Char from, Char to, Traits const &tr);
void set(Char c);
template<typename Traits>
void set(Char c, Traits const &tr);
void clear(Char from, Char to);
template<typename Traits>
void clear(Char from, Char to, Traits const &tr);
void clear(Char c);
template<typename Traits>
void clear(Char c, Traits const &tr);
void clear();
template<typename Traits>
bool test(Char v, Traits const &tr, mpl::false_) const; // case-sensitive
template<typename Traits>
bool test(Char v, Traits const &tr, mpl::true_) const; // case-insensitive
void inverse();
void swap(basic_chset& x);
basic_chset &operator |=(basic_chset const &x);
basic_chset &operator &=(basic_chset const &x);
basic_chset &operator -=(basic_chset const &x);
basic_chset &operator ^=(basic_chset const &x);
private:
range_run<Char> rr_;
};
#if(CHAR_BIT == 8)
///////////////////////////////////////////////////////////////////////////
//
// basic_chset: specializations for 8 bit chars using std::bitset
//
///////////////////////////////////////////////////////////////////////////
template<typename Char>
struct basic_chset_8bit
{
basic_chset_8bit();
basic_chset_8bit(basic_chset_8bit const &arg);
bool empty() const;
void set(Char from, Char to);
template<typename Traits>
void set(Char from, Char to, Traits const &tr);
void set(Char c);
template<typename Traits>
void set(Char c, Traits const &tr);
void clear(Char from, Char to);
template<typename Traits>
void clear(Char from, Char to, Traits const &tr);
void clear(Char c);
template<typename Traits>
void clear(Char c, Traits const &tr);
void clear();
template<typename Traits>
bool test(Char v, Traits const &tr, mpl::false_) const; // case-sensitive
template<typename Traits>
bool test(Char v, Traits const &tr, mpl::true_) const; // case-insensitive
void inverse();
void swap(basic_chset_8bit& x);
basic_chset_8bit &operator |=(basic_chset_8bit const &x);
basic_chset_8bit &operator &=(basic_chset_8bit const &x);
basic_chset_8bit &operator -=(basic_chset_8bit const &x);
basic_chset_8bit &operator ^=(basic_chset_8bit const &x);
std::bitset<256> const &base() const;
private:
std::bitset<256> bset_; // BUGBUG range-checking slows this down
};
/////////////////////////////////
template<>
struct basic_chset<char>
: basic_chset_8bit<char>
{
};
/////////////////////////////////
template<>
struct basic_chset<signed char>
: basic_chset_8bit<signed char>
{
};
/////////////////////////////////
template<>
struct basic_chset<unsigned char>
: basic_chset_8bit<unsigned char>
{
};
#endif
///////////////////////////////////////////////////////////////////////////////
// is_narrow_char
template<typename Char>
struct is_narrow_char
: mpl::false_
{};
template<>
struct is_narrow_char<char>
: mpl::true_
{};
template<>
struct is_narrow_char<signed char>
: mpl::true_
{};
template<>
struct is_narrow_char<unsigned char>
: mpl::true_
{};
///////////////////////////////////////////////////////////////////////////////
// helpers
template<typename Char, typename Traits>
void set_char(basic_chset<Char> &chset, Char ch, Traits const &tr, bool icase);
template<typename Char, typename Traits>
void set_range(basic_chset<Char> &chset, Char from, Char to, Traits const &tr, bool icase);
template<typename Char, typename Traits>
void set_class(basic_chset<Char> &chset, typename Traits::char_class_type char_class, bool no, Traits const &tr);
}}} // namespace boost::xpressive::detail
#endif
|