1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XPRESSIVE_DETAIL_CHSET_CHSET_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CHSET_CHSET_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
17 #include <boost/call_traits.hpp>
18 #include <boost/xpressive/detail/detail_fwd.hpp>
19 #include <boost/xpressive/detail/utility/algorithm.hpp>
20 #include <boost/xpressive/detail/utility/chset/basic_chset.ipp>
22 namespace boost { namespace xpressive { namespace detail
25 ///////////////////////////////////////////////////////////////////////////////
28 template<typename Traits>
29 struct compound_charset
30 : private basic_chset<typename Traits::char_type>
32 typedef typename Traits::char_type char_type;
33 typedef basic_chset<char_type> base_type;
34 typedef Traits traits_type;
35 typedef typename Traits::char_class_type char_class_type;
46 ///////////////////////////////////////////////////////////////////////////////
48 basic_chset<char_type> const &base() const
53 bool is_inverted() const
55 return this->complement_;
58 char_class_type posix_yes() const
60 return this->posix_yes_;
63 std::vector<char_class_type> const &posix_no() const
65 return this->posix_no_;
68 ///////////////////////////////////////////////////////////////////////////////
72 this->complement_ = !this->complement_;
75 ///////////////////////////////////////////////////////////////////////////////
77 void set_char(char_type ch, Traits const &tr, bool icase)
79 icase ? this->base_type::set(ch, tr) : this->base_type::set(ch);
82 void set_range(char_type from, char_type to, Traits const &tr, bool icase)
84 icase ? this->base_type::set(from, to, tr) : this->base_type::set(from, to);
87 void set_class(char_class_type const &m, bool no)
89 this->has_posix_ = true;
93 this->posix_no_.push_back(m);
97 this->posix_yes_ |= m;
101 ///////////////////////////////////////////////////////////////////////////////
103 template<typename ICase>
104 bool test(char_type ch, Traits const &tr, ICase) const
106 return this->complement_ !=
107 (this->base_type::test(ch, tr, ICase()) ||
108 (this->has_posix_ && this->test_posix(ch, tr)));
113 ///////////////////////////////////////////////////////////////////////////////
115 struct not_posix_pred
118 Traits const *traits_ptr_;
120 bool operator ()(typename call_traits<char_class_type>::param_type m) const
122 return !this->traits_ptr_->isctype(this->ch_, m);
126 ///////////////////////////////////////////////////////////////////////////////
128 bool test_posix(char_type ch, Traits const &tr) const
130 not_posix_pred const pred = {ch, &tr};
131 return tr.isctype(ch, this->posix_yes_)
132 || any(this->posix_no_.begin(), this->posix_no_.end(), pred);
137 char_class_type posix_yes_;
138 std::vector<char_class_type> posix_no_;
142 ///////////////////////////////////////////////////////////////////////////////
144 template<typename Char, typename Traits>
145 inline void set_char(compound_charset<Traits> &chset, Char ch, Traits const &tr, bool icase)
147 chset.set_char(ch, tr, icase);
150 template<typename Char, typename Traits>
151 inline void set_range(compound_charset<Traits> &chset, Char from, Char to, Traits const &tr, bool icase)
153 chset.set_range(from, to, tr, icase);
156 template<typename Traits>
157 inline void set_class(compound_charset<Traits> &chset, typename Traits::char_class_type char_class, bool no, Traits const &)
159 chset.set_class(char_class, no);
162 }}} // namespace boost::xpressive::detail