[ghex/expand-search-options: 7/14] hexdoc: Add case insensitivity to regex search




commit 3cd4f72c198f38bbf7465db341f4ceb1ce4aa8d4
Author: Logan Rathbone <poprocks gmail com>
Date:   Fri Apr 15 00:46:28 2022 -0400

    hexdoc: Add case insensitivity to regex search
    
    Also move fetching of target data to search, but that's just a code
    organization/cosmetic thing to segregate that from the regex stuff.

 src/hex-document.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/src/hex-document.c b/src/hex-document.c
index cbc6130..a232b6d 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -1127,19 +1127,23 @@ hex_document_compare_data_full (HexDocument *doc,
                GRegex *regex;
                GMatchInfo *match_info;
                char *regex_search_str;
+               GRegexCompileFlags regex_compile_flags;
 
                /* GRegex doesn't let you specify the length of the search string, so
                 * it needs to be NULL-terminated.
                 */
                regex_search_str = g_malloc (find_data->len+1);
-
                memcpy (regex_search_str, find_data->what, find_data->len);
                regex_search_str[find_data->len] = 0;
 
-               cp = hex_buffer_get_data (doc->buffer, pos, REGEX_SEARCH_LEN);
+               /* match string doesn't have to be UTF-8 */
+               regex_compile_flags = G_REGEX_RAW;
+
+               if (flags & HEX_SEARCH_IGNORE_CASE)
+                       regex_compile_flags |= G_REGEX_CASELESS;
 
                regex = g_regex_new (regex_search_str,
-                               G_REGEX_RAW,
+                               regex_compile_flags,
                                G_REGEX_MATCH_ANCHORED,
                                &local_error);
 
@@ -1152,6 +1156,8 @@ hex_document_compare_data_full (HexDocument *doc,
                        goto out;
                }
 
+               cp = hex_buffer_get_data (doc->buffer, pos, REGEX_SEARCH_LEN);
+
                if (g_regex_match_full (regex, cp,
                                        REGEX_SEARCH_LEN,       /* length of string being searched */
                                        0,                                      /* start pos */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]