2 // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_LEXER_CHARSET_HPP
7 #define BOOST_LEXER_CHARSET_HPP
10 #include "../size_t.hpp"
11 #include "../string_token.hpp"
19 template<typename CharT>
22 typedef basic_string_token<CharT> token;
23 typedef std::set<std::size_t> index_set;
32 basic_charset (const token &token_, const std::size_t index_) :
35 _index_set.insert (index_);
40 return _token.empty () && _index_set.empty ();
43 void intersect (basic_charset &rhs_, basic_charset &overlap_)
45 _token.intersect (rhs_._token, overlap_._token);
47 if (!overlap_._token.empty ())
49 typename index_set::const_iterator iter_ = _index_set.begin ();
50 typename index_set::const_iterator end_ = _index_set.end ();
52 for (; iter_ != end_; ++iter_)
54 overlap_._index_set.insert (*iter_);
57 iter_ = rhs_._index_set.begin ();
58 end_ = rhs_._index_set.end ();
60 for (; iter_ != end_; ++iter_)
62 overlap_._index_set.insert (*iter_);
70 if (rhs_._token.empty ())
72 rhs_._index_set.clear ();