diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-05-15 20:38:10 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-05-21 16:20:51 +1000 |
| commit | e140df8f0857125f40f9338450f73ff1ac50664d (patch) | |
| tree | 73525f5f4ca8a8106c10181f1fa2a8f64fc74b62 /src/regex_impl.hh | |
| parent | 19b4149d47019424bf304c5dfe13e132492e97fb (diff) | |
Add an idle callback to be called regularly while regex matching
This paves the way towards being able to cancel long regex matching
operations
Diffstat (limited to 'src/regex_impl.hh')
| -rw-r--r-- | src/regex_impl.hh | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/regex_impl.hh b/src/regex_impl.hh index 57f07c8b..4ba0e233 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -244,6 +244,13 @@ public: const Iterator& subject_begin, const Iterator& subject_end, RegexExecFlags flags) { + return exec(begin, end, subject_begin, subject_end, flags, []{}); + } + + bool exec(const Iterator& begin, const Iterator& end, + const Iterator& subject_begin, const Iterator& subject_end, + RegexExecFlags flags, auto&& idle_func) + { if (flags & RegexExecFlags::NotInitialNull and begin == end) return false; @@ -274,7 +281,7 @@ public: } } - return exec_program(std::move(start), config); + return exec_program(std::move(start), config, idle_func); } ArrayView<const Iterator> captures() const @@ -453,7 +460,7 @@ private: return failed(); } - bool exec_program(Iterator pos, const ExecConfig& config) + bool exec_program(Iterator pos, const ExecConfig& config, auto&& idle_func) { kak_assert(m_threads.current_is_empty() and m_threads.next_is_empty()); release_saves(m_captures); @@ -473,6 +480,8 @@ private: { if (++current_step == 0) { + idle_func(); + // We wrapped, avoid potential collision on inst.last_step by resetting them ConstArrayView<CompiledRegex::Instruction> instructions{m_program.instructions}; instructions = forward ? instructions.subrange(0, m_program.first_backward_inst) |
