diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2017-02-16 22:48:13 +0100 |
---|---|---|
committer | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2017-06-04 00:52:53 +0200 |
commit | 79bbca4644cad7f2dee89c7ac6b8f9acc2c8b427 (patch) | |
tree | 86b908491ac1ab00cb079526b1f32a5d294d75a6 /src/fe-text | |
parent | 31b9d115b065570020ce9be1a1d8cd49212f70a9 (diff) | |
download | irssi-79bbca4644cad7f2dee89c7ac6b8f9acc2c8b427.zip |
Refactor regex and implement UTF8 mode for GRegex
- with non-unicode byte to Private Use Area A mapping
- move all ifdefs to iregex.h file only
Diffstat (limited to 'src/fe-text')
-rw-r--r-- | src/fe-text/textbuffer.c | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 3668f4c7..eb841096 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -24,13 +24,10 @@ #include "misc.h" #include "formats.h" #include "utf8.h" +#include "iregex.h" #include "textbuffer.h" -#ifndef USE_GREGEX -# include <regex.h> -#endif - #define TEXT_CHUNK_USABLE_SIZE (LINE_TEXT_CHUNK_SIZE-2-(int)sizeof(char*)) TEXT_BUFFER_REC *textbuffer_create(void) @@ -545,11 +542,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, int before, int after, int regexp, int fullword, int case_sensitive) { -#ifdef USE_GREGEX - GRegex *preg; -#else - regex_t preg; -#endif + Regex *preg; LINE_REC *line, *pre_line; GList *matches; GString *str; @@ -559,23 +552,14 @@ 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); + preg = i_regex_new(text, case_sensitive ? 0 : G_REGEX_CASELESS, 0, NULL); if (preg == NULL) return NULL; } -#else - if (regexp) { - int flags = REG_EXTENDED | REG_NOSUB | - (case_sensitive ? 0 : REG_ICASE); - if (regcomp(&preg, text, flags) != 0) - return NULL; - } -#endif matches = NULL; match_after = 0; str = g_string_new(NULL); @@ -592,17 +576,16 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, (line->info.level & nolevel) == 0; if (*text != '\0') { + const char *tmp = NULL; textbuffer_line2text(line, FALSE, str); 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 + i_regex_match(preg, str->str, 0, NULL, &tmp) : match_func(str->str, text) != NULL; } + if (tmp && tmp != str->str) + g_free_not_null((char *)tmp); } if (line_matched) { @@ -631,12 +614,8 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, } } -#ifdef USE_GREGEX if (preg != NULL) - g_regex_unref(preg); -#else - if (regexp) regfree(&preg); -#endif + i_regex_unref(preg); g_string_free(str, TRUE); return matches; } |