// match_results.hpp // Copyright (c) 2015 Ben Hanson (http://www.benhanson.net/) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef LEXERTL_MATCH_RESULTS_HPP #define LEXERTL_MATCH_RESULTS_HPP #include "char_traits.hpp" #include "enums.hpp" #include #include #include namespace lexertl { template struct match_results { typedef iter iter_type; typedef typename std::iterator_traits::value_type char_type; typedef typename basic_char_traits::index_type index_type; typedef std::basic_string string; id_type id; id_type user_id; iter_type start; iter_type end; iter_type eoi; bool bol; id_type state; match_results() : id(0), user_id(npos()), start(iter_type()), end(iter_type()), eoi(iter_type()), bol(true), state(0) { } match_results(const iter_type &start_, const iter_type &end_) : id(0), user_id(npos()), start(start_), end(start_), eoi(end_), bol(true), state(0) { } virtual ~match_results() { } string str() const { return string(start, end); } string substr(const std::size_t soffset_, const std::size_t eoffset_) const { return string(start + soffset_, end - eoffset_); } virtual void clear() { id = 0; user_id = npos(); start = eoi; end = eoi; bol = true; state = 0; } virtual void reset(const iter_type &start_, const iter_type &end_) { id = 0; user_id = npos(); start = start_; end = start_; eoi = end_; bol = true; state = 0; } static id_type npos() { return ~static_cast(0); } static id_type skip() { return ~static_cast(1); } bool operator ==(const match_results &rhs_) const { return id == rhs_.id && user_id == rhs_.user_id && start == rhs_.start && end == rhs_.end && eoi == rhs_.eoi && bol == rhs_.bol && state == rhs_.state; } }; template struct recursive_match_results : public match_results { typedef std::pair id_type_pair; std::stack stack; recursive_match_results() : match_results(), stack() { } recursive_match_results(const iter &start_, const iter &end_) : match_results(start_, end_), stack() { } virtual ~recursive_match_results() { } virtual void clear() { match_results::clear(); while (!stack.empty()) stack.pop(); } virtual void reset(const iter &start_, const iter &end_) { match_results::reset(start_, end_); while (!stack.empty()) stack.pop(); } }; typedef match_results smatch; typedef match_results cmatch; typedef match_results wsmatch; typedef match_results wcmatch; typedef recursive_match_results srmatch; typedef recursive_match_results crmatch; typedef recursive_match_results wsrmatch; typedef recursive_match_results wcrmatch; } #endif