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_SET_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_SET_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
14 # pragma warning(push)
15 # pragma warning(disable : 4127) // conditional expression constant
16 # pragma warning(disable : 4100) // unreferenced formal parameter
17 # pragma warning(disable : 4351) // vc8 new behavior: elements of array 'foo' will be default initialized
21 #include <boost/mpl/assert.hpp>
22 #include <boost/type_traits/same_traits.hpp>
23 #include <boost/xpressive/detail/detail_fwd.hpp>
24 #include <boost/xpressive/detail/core/quant_style.hpp>
25 #include <boost/xpressive/detail/core/state.hpp>
27 namespace boost { namespace xpressive { namespace detail
30 ///////////////////////////////////////////////////////////////////////////////
33 template<typename Traits, typename Size>
35 : quant_style_fixed_width<1>
37 typedef typename Traits::char_type char_type;
38 char_type set_[ Size::value ];
51 this->not_ = !this->not_;
54 void nocase(Traits const &tr)
58 for(int i = 0; i < Size::value; ++i)
60 this->set_[i] = tr.translate_nocase(this->set_[i]);
64 bool in_set(Traits const &tr, char_type ch) const
66 char_type const *begin = &this->set_[0], *end = begin + Size::value;
67 ch = this->icase_ ? tr.translate_nocase(ch) : tr.translate(ch);
68 return end != std::find(begin, end, ch);
71 template<typename BidiIter, typename Next>
72 bool match(match_state<BidiIter> &state, Next const &next) const
74 if(state.eos() || this->not_ == this->in_set(traits_cast<Traits>(state), *state.cur_))
79 if(++state.cur_, next.match(state))
84 return --state.cur_, false;
88 ///////////////////////////////////////////////////////////////////////////////
90 struct set_initializer
98 }}} // namespace boost::xpressive::detail