]> uap-core.de Git - note.git/commitdiff
add text_search_match
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 3 Feb 2026 17:52:06 +0000 (18:52 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 3 Feb 2026 17:52:06 +0000 (18:52 +0100)
application/note.c
application/note.h

index 61e27e80bf05d8f9d9100994b3b799bcc6ca2dee..075b0546021c86292776779164c62affe2282ecb 100644 (file)
@@ -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 {
index 3e099e0046a071b906006c7c77a7a0edfb719ce8..58357ad5eb5343153b01f8297db18e4b1085763f 100644 (file)
@@ -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);