From bc542a3229df64e30d4c2f15f49d183ee6e08b67 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 3 Feb 2026 18:52:06 +0100 Subject: [PATCH] add text_search_match --- application/note.c | 32 ++++++++++++++++++++++++++++---- application/note.h | 13 +++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/application/note.c b/application/note.c index 61e27e8..075b054 100644 --- a/application/note.c +++ b/application/note.c @@ -347,6 +347,31 @@ int text_search( regex_t *regex, int *result_begin, int *result_end) +{ + regmatch_t match; + return text_search_match( + text, + search, + pos, + backwards, + case_sensitive, + regex, + result_begin, + result_end, + &match, 1); +} + +int text_search_match( + cxstring text, + cxstring search, + int pos, + bool backwards, + bool case_sensitive, + regex_t *regex, + int *result_begin, + int *result_end, + regmatch_t *match, + size_t nmatch) { cxstring result = (cxstring){NULL,0}; if(!backwards) { @@ -360,12 +385,11 @@ int text_search( } } else { // case_sensitive parameter is ignored in regex mode - regmatch_t match; - if(regexec(regex, subtext.ptr, 1, &match, 0) != 0) { + if(regexec(regex, subtext.ptr, nmatch, match, 0) != 0) { return 0; } - *result_begin = match.rm_so + pos; - *result_end = match.rm_eo + pos; + *result_begin = match->rm_so + pos; + *result_end = match->rm_eo + pos; return 1; } } else { diff --git a/application/note.h b/application/note.h index 3e099e0..58357ad 100644 --- a/application/note.h +++ b/application/note.h @@ -84,6 +84,19 @@ int text_search( int *result_begin, int *result_end); +int text_search_match( + cxstring text, + cxstring search, + int pos, + bool backwards, + bool case_sensitive, + regex_t *regex, + int *result_begin, + int *result_end, + regmatch_t *match, + size_t nmatch); + + void note_search_next(NoteModel *note); void note_search_prev(NoteModel *note); void note_replace(NoteModel *note); -- 2.47.3