From 8e5db471e4d8b052f072ce8a351222c6edb42d19 Mon Sep 17 00:00:00 2001
From: LemonBoy <thatlemon@gmail.com>
Date: Thu, 14 Jan 2016 14:10:00 +0100
Subject: Use GLib's regexp interface (backed by PCRE)

---
 src/fe-text/textbuffer.c | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)

(limited to 'src/fe-text/textbuffer.c')

diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c
index 24ee62bc..979b2a46 100644
--- a/src/fe-text/textbuffer.c
+++ b/src/fe-text/textbuffer.c
@@ -27,10 +27,6 @@
 
 #include "textbuffer.h"
 
-#ifdef HAVE_REGEX_H
-#  include <regex.h>
-#endif
-
 #define TEXT_CHUNK_USABLE_SIZE (LINE_TEXT_CHUNK_SIZE-2-(int)sizeof(char*))
 
 TEXT_BUFFER_REC *textbuffer_create(void)
@@ -537,9 +533,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
 			    int before, int after,
 			    int regexp, int fullword, int case_sensitive)
 {
-#ifdef HAVE_REGEX_H
-	regex_t preg;
-#endif
+	GRegex *preg;
         LINE_REC *line, *pre_line;
 	GList *matches;
 	GString *str;
@@ -550,14 +544,10 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
 	g_return_val_if_fail(text != NULL, NULL);
 
 	if (regexp) {
-#ifdef HAVE_REGEX_H
-		int flags = REG_EXTENDED | REG_NOSUB |
-			(case_sensitive ? 0 : REG_ICASE);
-		if (regcomp(&preg, text, flags) != 0)
+		preg = g_regex_new(text, (case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL);
+
+		if (preg == NULL)
 			return NULL;
-#else
-		return NULL;
-#endif
 	}
 
 	matches = NULL; match_after = 0;
@@ -577,12 +567,11 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
 		if (*text != '\0') {
 			textbuffer_line2text(line, FALSE, str);
 
-			if (line_matched)
-			line_matched =
-#ifdef HAVE_REGEX_H
-			regexp ? regexec(&preg, str->str, 0, NULL, 0) == 0 :
-#endif
-			match_func(str->str, text) != NULL;
+			if (line_matched) {
+				line_matched = regexp ? 
+				    g_regex_match(preg, str->str, 0, NULL) :
+				    match_func(str->str, text) != NULL;
+			}
 		}
 
 		if (line_matched) {
@@ -610,9 +599,9 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
 				matches = g_list_append(matches, NULL);
 		}
 	}
-#ifdef HAVE_REGEX_H
-	if (regexp) regfree(&preg);
-#endif
+
+	if (regexp)
+		g_regex_unref(preg);
         g_string_free(str, TRUE);
 	return matches;
 }
-- 
cgit v1.2.3