perl_matcher.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 551 行 · 第 1/2 页
HPP
551 行
start_pos = p->start_pos; } } ~repeater_count() { *stack = next; } std::size_t get_count() { return count; } int get_id() { return state_id; } std::size_t operator++() { return ++count; } bool check_null_repeat(const BidiIterator& pos, std::size_t max) { // this is called when we are about to start a new repeat, // if the last one was NULL move our count to max, // otherwise save the current position. bool result = (count == 0) ? false : (pos == start_pos); if(result) count = max; else start_pos = pos; return result; }};struct saved_state;enum saved_state_type{ saved_type_end = 0, saved_type_paren = 1, saved_type_recurse = 2, saved_type_assertion = 3, saved_state_alt = 4, saved_state_repeater_count = 5, saved_state_extra_block = 6, saved_state_greedy_single_repeat = 7, saved_state_rep_slow_dot = 8, saved_state_rep_fast_dot = 9, saved_state_rep_char = 10, saved_state_rep_short_set = 11, saved_state_rep_long_set = 12, saved_state_non_greedy_long_repeat = 13, saved_state_count = 14};#ifdef BOOST_MSVC#pragma warning(push)#pragma warning(disable : 4251 4231 4660)#endiftemplate <class BidiIterator, class Allocator, class traits>class perl_matcher{public: typedef typename traits::char_type char_type; typedef perl_matcher<BidiIterator, Allocator, traits> self_type; typedef bool (self_type::*matcher_proc_type)(void); typedef std::size_t traits_size_type; typedef typename is_byte<char_type>::width_type width_type; typedef typename regex_iterator_traits<BidiIterator>::difference_type difference_type; perl_matcher(BidiIterator first, BidiIterator end, match_results<BidiIterator, Allocator>& what, const basic_regex<char_type, traits>& e, match_flag_type f, BidiIterator l_base) : m_result(what), base(first), last(end), position(first), backstop(l_base), re(e), traits_inst(e.get_traits()), m_independent(false), next_count(&rep_obj), rep_obj(&next_count) { construct_init(e, f); } bool match(); bool find(); void setf(match_flag_type f) { m_match_flags |= f; } void unsetf(match_flag_type f) { m_match_flags &= ~f; }private: void construct_init(const basic_regex<char_type, traits>& e, match_flag_type f); bool find_imp(); bool match_imp();#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD typedef bool (perl_matcher::*protected_proc_type)(); bool protected_call(protected_proc_type);#endif void estimate_max_state_count(std::random_access_iterator_tag*); void estimate_max_state_count(void*); bool match_prefix(); bool match_all_states(); // match procs, stored in s_match_vtable: bool match_startmark(); bool match_endmark(); bool match_literal(); bool match_start_line(); bool match_end_line(); bool match_wild(); bool match_match(); bool match_word_boundary(); bool match_within_word(); bool match_word_start(); bool match_word_end(); bool match_buffer_start(); bool match_buffer_end(); bool match_backref(); bool match_long_set(); bool match_set(); bool match_jump(); bool match_alt(); bool match_rep(); bool match_combining(); bool match_soft_buffer_end(); bool match_restart_continue(); bool match_long_set_repeat(); bool match_set_repeat(); bool match_char_repeat(); bool match_dot_repeat_fast(); bool match_dot_repeat_slow(); bool match_backstep(); bool match_assert_backref(); bool match_toggle_case();#ifdef BOOST_REGEX_RECURSIVE bool backtrack_till_match(std::size_t count);#endif // find procs stored in s_find_vtable: bool find_restart_any(); bool find_restart_word(); bool find_restart_line(); bool find_restart_buf(); bool find_restart_lit();private: // final result structure to be filled in: match_results<BidiIterator, Allocator>& m_result; // temporary result for POSIX matches: scoped_ptr<match_results<BidiIterator, Allocator> > m_temp_match; // pointer to actual result structure to fill in: match_results<BidiIterator, Allocator>* m_presult; // start of sequence being searched: BidiIterator base; // end of sequence being searched: BidiIterator last; // current character being examined: BidiIterator position; // where to restart next search after failed match attempt: BidiIterator restart; // where the current search started from, acts as base for $` during grep: BidiIterator search_base; // how far we can go back when matching lookbehind: BidiIterator backstop; // the expression being examined: const basic_regex<char_type, traits>& re; // the expression's traits class: const ::boost::regex_traits_wrapper<traits>& traits_inst; // the next state in the machine being matched: const re_syntax_base* pstate; // matching flags in use: match_flag_type m_match_flags; // how many states we have examined so far: boost::uintmax_t state_count; // max number of states to examine before giving up: boost::uintmax_t max_state_count; // whether we should ignore case or not: bool icase; // set to true when (position == last), indicates that we may have a partial match: bool m_has_partial_match; // set to true whenever we get a match: bool m_has_found_match; // set to true whenever we're inside an independent sub-expression: bool m_independent; // the current repeat being examined: repeater_count<BidiIterator>* next_count; // the first repeat being examined (top of linked list): repeater_count<BidiIterator> rep_obj; // the mask to pass when matching word boundaries: typename traits::char_class_type m_word_mask; // the bitmask to use when determining whether a match_any matches a newline or not: unsigned char match_any_mask;#ifdef BOOST_REGEX_NON_RECURSIVE // // additional members for non-recursive version: // typedef bool (self_type::*unwind_proc_type)(bool); void extend_stack(); bool unwind(bool); bool unwind_end(bool); bool unwind_paren(bool); bool unwind_recursion_stopper(bool); bool unwind_assertion(bool); bool unwind_alt(bool); bool unwind_repeater_counter(bool); bool unwind_extra_block(bool); bool unwind_greedy_single_repeat(bool); bool unwind_slow_dot_repeat(bool); bool unwind_fast_dot_repeat(bool); bool unwind_char_repeat(bool); bool unwind_short_set_repeat(bool); bool unwind_long_set_repeat(bool); bool unwind_non_greedy_repeat(bool); void destroy_single_repeat(); void push_matched_paren(int index, const sub_match<BidiIterator>& sub); void push_recursion_stopper(); void push_assertion(const re_syntax_base* ps, bool positive); void push_alt(const re_syntax_base* ps); void push_repeater_count(int i, repeater_count<BidiIterator>** s); void push_single_repeat(std::size_t c, const re_repeat* r, BidiIterator last_position, int state_id); void push_non_greedy_repeat(const re_syntax_base* ps); // pointer to base of stack: saved_state* m_stack_base; // pointer to current stack position: saved_state* m_backup_state; // determines what value to return when unwinding from recursion, // allows for mixed recursive/non-recursive algorithm: bool m_recursive_result; // how many memory blocks have we used up?: unsigned used_block_count;#endif // these operations aren't allowed, so are declared private, // bodies are provided to keep explicit-instantiation requests happy: perl_matcher& operator=(const perl_matcher&) { return *this; } perl_matcher(const perl_matcher& that) : m_result(that.m_result), re(that.re), traits_inst(that.traits_inst), rep_obj(0) {}};#ifdef BOOST_MSVC#pragma warning(pop)#endif} // namespace re_detail#ifdef BOOST_MSVC#pragma warning(push)#pragma warning(disable: 4103)#endif#ifdef BOOST_HAS_ABI_HEADERS# include BOOST_ABI_SUFFIX#endif#ifdef BOOST_MSVC#pragma warning(pop)#endif} // namespace boost#ifdef BOOST_MSVC# pragma warning(pop)#endif//// include the implementation of perl_matcher://#ifdef BOOST_REGEX_RECURSIVE#include <boost/regex/v4/perl_matcher_recursive.hpp>#else#include <boost/regex/v4/perl_matcher_non_recursive.hpp>#endif// this one has to be last:#include <boost/regex/v4/perl_matcher_common.hpp>#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?