Add regex search
This allows regex search and replace, as requested in #9 (closed).
But as this is based on the use of a GtkSourceSearchContext
, this involves significant changes, that is more or less a complete rewrite of the search and replace (and highlight) procedure.
I tried to minimize the magnitude of the changes though, by keeping the existing structure, with most of the work done in mousepad-util.c
, based on the MousepadSearchFlags
.
While this is globally a simplification of the code, because most of the work is done in the GtkSourceSearchContext
(and we can expect it is well done), this may not be as fast as it is today, especially in the replace-all
case, when one has to count all the occurrences of the searched text in the document.
Perhaps there exists a better way to do this than the way I did it in mousepad_util_search()
, but I fear that no synchronous way will be better than what is implemented today, because even when the counting of all occurrences is done in one search (which is then totally done in the GtkSourceSearchContext
), this is slower than the current code.
To see the difference, one has to open quite big files though.
I tested for instance a ~ 14 000 lines html file, with ~ 20 000 occurrences of <
, on a modest laptop.
The current code finds them in ~ 0.3 seconds, while the patched code finds them in ~ 0.9 seconds.
A better way to do this would probably be to use asynchronous functions, but this is an other story, because the basic functions gtk_source_search_context_forward_async()
and gtk_source_search_context_forward_finish()
are not sufficient here, unless I missed something, which is possible!