summaryrefslogtreecommitdiff
path: root/src/fe-common
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2017-02-16 22:48:13 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2017-06-04 00:52:53 +0200
commit79bbca4644cad7f2dee89c7ac6b8f9acc2c8b427 (patch)
tree86b908491ac1ab00cb079526b1f32a5d294d75a6 /src/fe-common
parent31b9d115b065570020ce9be1a1d8cd49212f70a9 (diff)
downloadirssi-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-common')
-rw-r--r--src/fe-common/core/fe-ignore.c5
-rw-r--r--src/fe-common/core/hilight-text.c51
-rw-r--r--src/fe-common/core/hilight-text.h12
3 files changed, 13 insertions, 55 deletions
diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c
index 800e881d..03fd4dd2 100644
--- a/src/fe-common/core/fe-ignore.c
+++ b/src/fe-common/core/fe-ignore.c
@@ -58,13 +58,8 @@ static void ignore_print(int index, IGNORE_REC *rec)
g_string_append(options, "-regexp ");
if (rec->pattern == NULL)
g_string_append(options, "[INVALID! -pattern missing] ");
-#ifdef USE_GREGEX
else if (rec->preg == NULL)
g_string_append(options, "[INVALID!] ");
-#else
- else if (!rec->regexp_compiled)
- g_string_append(options, "[INVALID!] ");
-#endif
}
if (rec->fullword) g_string_append(options, "-full ");
if (rec->replies) g_string_append(options, "-replies ");
diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c
index dd38be87..6a2c97dc 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -26,6 +26,7 @@
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
+#include "iregex.h"
#include "servers.h"
#include "channels.h"
@@ -101,11 +102,7 @@ static void hilight_destroy(HILIGHT_REC *rec)
{
g_return_if_fail(rec != NULL);
-#ifdef USE_GREGEX
- if (rec->preg != NULL) g_regex_unref(rec->preg);
-#else
- if (rec->regexp_compiled) regfree(&rec->preg);
-#endif
+ if (rec->preg != NULL) i_regex_unref(rec->preg);
if (rec->channels != NULL) g_strfreev(rec->channels);
g_free_not_null(rec->color);
g_free_not_null(rec->act_color);
@@ -122,19 +119,10 @@ static void hilights_destroy_all(void)
static void hilight_init_rec(HILIGHT_REC *rec)
{
-#ifdef USE_GREGEX
if (rec->preg != NULL)
- g_regex_unref(rec->preg);
+ i_regex_unref(rec->preg);
- rec->preg = g_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, NULL);
-#else
- if (rec->regexp_compiled) regfree(&rec->preg);
- if (!rec->regexp)
- rec->regexp_compiled = FALSE;
- else
- rec->regexp_compiled = regcomp(&rec->preg, rec->text,
- rec->case_sensitive ? REG_EXTENDED : (REG_EXTENDED|REG_ICASE)) == 0;
-#endif
+ rec->preg = i_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_CASELESS, 0, NULL);
}
void hilight_create(HILIGHT_REC *rec)
@@ -207,30 +195,18 @@ static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text,
gboolean ret = FALSE;
if (rec->regexp) {
-#ifdef USE_GREGEX
if (rec->preg != NULL) {
- GMatchInfo *match;
+ MatchInfo *match;
+ const char *new_text = NULL;
- g_regex_match (rec->preg, text, 0, &match);
+ i_regex_match(rec->preg, text, 0, &match, &new_text);
- if (g_match_info_matches(match))
- ret = g_match_info_fetch_pos(match, 0, match_beg, match_end);
+ if (i_match_info_matches(match))
+ ret = i_match_info_fetch_pos(match, 0, match_beg, match_end, new_text);
- g_match_info_free(match);
+ i_match_info_free(match);
+ g_free_not_null((char *)new_text);
}
-#else
- regmatch_t rmatch[1];
-
- if (rec->regexp_compiled &&
- regexec(&rec->preg, text, 1, rmatch, 0) == 0) {
- if (rmatch[0].rm_so > 0 &&
- match_beg != NULL && match_end != NULL) {
- *match_beg = rmatch[0].rm_so;
- *match_end = rmatch[0].rm_eo;
- }
- ret = TRUE;
- }
-#endif
} else {
char *match;
@@ -524,13 +500,8 @@ static void hilight_print(int index, HILIGHT_REC *rec)
if (rec->case_sensitive) g_string_append(options, "-matchcase ");
if (rec->regexp) {
g_string_append(options, "-regexp ");
-#ifdef USE_GREGEX
if (rec->preg == NULL)
g_string_append(options, "[INVALID!] ");
-#else
- if (!rec->regexp_compiled)
- g_string_append(options, "[INVALID!] ");
-#endif
}
if (rec->priority != 0)
diff --git a/src/fe-common/core/hilight-text.h b/src/fe-common/core/hilight-text.h
index 76beec1f..1d942f29 100644
--- a/src/fe-common/core/hilight-text.h
+++ b/src/fe-common/core/hilight-text.h
@@ -1,10 +1,7 @@
#ifndef __HILIGHT_TEXT_H
#define __HILIGHT_TEXT_H
-#ifndef USE_GREGEX
-# include <regex.h>
-#endif
-
+#include "iregex.h"
#include "formats.h"
struct _HILIGHT_REC {
@@ -24,12 +21,7 @@ struct _HILIGHT_REC {
unsigned int fullword:1; /* match `text' only for full words */
unsigned int regexp:1; /* `text' is a regular expression */
unsigned int case_sensitive:1;/* `text' must match case */
-#ifdef USE_GREGEX
- GRegex *preg;
-#else
- unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */
- regex_t preg;
-#endif
+ Regex *preg;
char *servertag;
};