diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2017-01-03 12:45:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-03 12:45:27 +0100 |
commit | 5787e2b4befb61585fc312843bd7a5efd0101dce (patch) | |
tree | c0073992aa598692aceffa8a10a4695cdb068585 /src/fe-text | |
parent | 91f48c6f0e03e53c0968a5433d672ea966006e59 (diff) | |
parent | 1f72b8e66a06b484dde20b6031c766a2129e0bd2 (diff) | |
download | irssi-5787e2b4befb61585fc312843bd7a5efd0101dce.zip |
Merge pull request #412 from LemonBoy/pcre-regexp
Use GLib's regexp interface (backed by PCRE)
Diffstat (limited to 'src/fe-text')
-rw-r--r-- | src/fe-text/textbuffer.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 24ee62bc..ae4636a5 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -27,7 +27,7 @@ #include "textbuffer.h" -#ifdef HAVE_REGEX_H +#ifndef USE_GREGEX # include <regex.h> #endif @@ -537,7 +537,9 @@ 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 +#ifdef USE_GREGEX + GRegex *preg; +#else regex_t preg; #endif LINE_REC *line, *pre_line; @@ -549,16 +551,23 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, g_return_val_if_fail(buffer != NULL, NULL); g_return_val_if_fail(text != NULL, NULL); +#ifdef USE_GREGEX + preg = NULL; + + if (regexp) { + preg = g_regex_new(text, G_REGEX_RAW | (case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL); + + if (preg == NULL) + return NULL; + } +#else if (regexp) { -#ifdef HAVE_REGEX_H int flags = REG_EXTENDED | REG_NOSUB | (case_sensitive ? 0 : REG_ICASE); if (regcomp(&preg, text, flags) != 0) return NULL; -#else - return NULL; -#endif } +#endif matches = NULL; match_after = 0; str = g_string_new(NULL); @@ -577,12 +586,15 @@ 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 : + if (line_matched) { + line_matched = regexp ? +#ifdef USE_GREGEX + g_regex_match(preg, str->str, 0, NULL) +#else + regexec(&preg, str->str, 0, NULL, 0) == 0 #endif - match_func(str->str, text) != NULL; + : match_func(str->str, text) != NULL; + } } if (line_matched) { @@ -610,7 +622,11 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, matches = g_list_append(matches, NULL); } } -#ifdef HAVE_REGEX_H + +#ifdef USE_GREGEX + if (preg != NULL) + g_regex_unref(preg); +#else if (regexp) regfree(&preg); #endif g_string_free(str, TRUE); |