// match_results.hpp // Copyright (c) 2015-2018 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 { using iter_type = iter; using char_type = typename std::iterator_traits::value_type; using index_type = typename basic_char_traits::index_type; using string = std::basic_string; id_type id; id_type user_id; iter_type first; iter_type second; iter_type eoi; bool bol; id_type state; match_results() : id(0), user_id(npos()), first(iter_type()), second(iter_type()), eoi(iter_type()), bol(true), state(0) { } match_results(const iter_type &start_, const iter_type &end_) : id(0), user_id(npos()), first(start_), second(start_), eoi(end_), bol(true), state(0) { } virtual ~match_results() { } string str() const { return string(first, second); } string substr(const std::size_t soffset_, const std::size_t eoffset_) const { return string(first + soffset_, second - eoffset_); } virtual void clear() { id = 0; user_id = npos(); first = eoi; second = eoi; bol = true; state = 0; } virtual void reset(const iter_type &start_, const iter_type &end_) { id = 0; user_id = npos(); first = start_; second = 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 && first == rhs_.first && second == rhs_.second && eoi == rhs_.eoi && bol == rhs_.bol && state == rhs_.state; } }; template struct recursive_match_results : public match_results { using id_type_pair = std::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() override { } virtual void clear() override { match_results::clear(); while (!stack.empty()) stack.pop(); } virtual void reset(const iter &start_, const iter &end_) override { match_results::reset(start_, end_); while (!stack.empty()) stack.pop(); } }; using smatch = match_results; using cmatch = match_results; using wsmatch = match_results; using wcmatch = match_results; using u32smatch = match_results; using u32cmatch = match_results; using srmatch = recursive_match_results; using crmatch = recursive_match_results; using wsrmatch = recursive_match_results; using wcrmatch = recursive_match_results; using u32srmatch = recursive_match_results; using u32crmatch = recursive_match_results; } #endif