From 12d933d89651a40de34d1e75ede14cd3dfdb7716 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 23 Oct 2011 20:26:51 +0000 Subject: [PATCH] Filters: rewrote colorize_regex --- src/filters.cc | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/filters.cc b/src/filters.cc index 7459c31f..e02e212a 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -6,23 +6,29 @@ namespace Kakoune void colorize_regex(DisplayBuffer& display_buffer, const boost::regex& ex, Color color) { - for (auto atom_it = display_buffer.begin(); - atom_it != display_buffer.end(); ++atom_it) + BufferIterator display_begin = display_buffer.begin()->begin(); + BufferIterator display_end = display_buffer.back().end(); + + boost::regex_iterator re_it(display_begin, display_end, + ex, boost::match_nosubs); + boost::regex_iterator re_end; + DisplayBuffer::iterator atom_it = display_buffer.begin(); + for (; re_it != re_end; ++re_it) { - boost::match_results matches; - if (boost::regex_search(atom_it->begin(), atom_it->end(), - matches, ex, boost::match_nosubs)) + BufferIterator begin = (*re_it)[0].first; + BufferIterator end = (*re_it)[0].second; + auto begin_atom_it = display_buffer.atom_containing(begin, atom_it); + auto end_atom_it = display_buffer.atom_containing(end, atom_it); + if (begin_atom_it == end_atom_it) { - const BufferIterator& begin = matches.begin()->first; - if (begin != atom_it->begin()) - atom_it = ++display_buffer.split(atom_it, begin); + if (begin_atom_it->begin() != begin) + begin_atom_it = ++display_buffer.split(begin_atom_it, begin); + if (begin_atom_it->end() != end) + begin_atom_it = display_buffer.split(begin_atom_it, end); - const BufferIterator& end = matches.begin()->second; - if (end != atom_it->end()) - atom_it = display_buffer.split(atom_it, end); - - atom_it->fg_color() = color; + begin_atom_it->fg_color() = color; } + atom_it = begin_atom_it; } }