summaryrefslogtreecommitdiff
path: root/src/fe-common/core
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2016-01-14 14:10:00 +0100
committerAilin Nemui <ailin@z30a.localdomain>2017-01-02 17:50:14 +0100
commit8e5db471e4d8b052f072ce8a351222c6edb42d19 (patch)
treed2eb11ae5ef3440db5e23ffbfcb433bb220f29d7 /src/fe-common/core
parent91f48c6f0e03e53c0968a5433d672ea966006e59 (diff)
downloadirssi-8e5db471e4d8b052f072ce8a351222c6edb42d19.zip
Use GLib's regexp interface (backed by PCRE)
Diffstat (limited to 'src/fe-common/core')
-rw-r--r--src/fe-common/core/fe-ignore.c2
-rw-r--r--src/fe-common/core/hilight-text.c39
-rw-r--r--src/fe-common/core/hilight-text.h8
3 files changed, 17 insertions, 32 deletions
diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c
index 52b11e6b..addfa0b8 100644
--- a/src/fe-common/core/fe-ignore.c
+++ b/src/fe-common/core/fe-ignore.c
@@ -58,10 +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 HAVE_REGEX_H
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 4691a708..83b6f67e 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -101,9 +101,7 @@ static void hilight_destroy(HILIGHT_REC *rec)
{
g_return_if_fail(rec != NULL);
-#ifdef HAVE_REGEX_H
- if (rec->regexp_compiled) regfree(&rec->preg);
-#endif
+ if (rec->regexp_compiled) g_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);
@@ -120,14 +118,15 @@ static void hilights_destroy_all(void)
static void hilight_init_rec(HILIGHT_REC *rec)
{
-#ifdef HAVE_REGEX_H
- if (rec->regexp_compiled) regfree(&rec->preg);
- if (!rec->regexp)
+ if (rec->regexp_compiled) {
+ g_regex_unref(rec->preg);
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 = g_regex_new(rec->text, G_REGEX_CASELESS, 0, NULL);
+
+ if (rec->preg != NULL)
+ rec->regexp_compiled = TRUE;
}
void hilight_create(HILIGHT_REC *rec)
@@ -200,19 +199,15 @@ static int hilight_match_text(HILIGHT_REC *rec, const char *text,
char *match;
if (rec->regexp) {
-#ifdef HAVE_REGEX_H
- 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;
+ GMatchInfo *match;
+
+ if (rec->regexp_compiled) {
+ g_regex_match (rec->preg, text, 0, &match);
+
+ if (g_match_info_matches(match)) {
+ return g_match_info_fetch_pos(match, 0, match_beg, match_end);
}
- return TRUE;
}
-#endif
} else {
if (rec->case_sensitive) {
match = rec->fullword ?
@@ -509,10 +504,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 HAVE_REGEX_H
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 ae05e1ca..a74c38b0 100644
--- a/src/fe-common/core/hilight-text.h
+++ b/src/fe-common/core/hilight-text.h
@@ -1,10 +1,6 @@
#ifndef __HILIGHT_TEXT_H
#define __HILIGHT_TEXT_H
-#ifdef HAVE_REGEX_H
-# include <regex.h>
-#endif
-
#include "formats.h"
struct _HILIGHT_REC {
@@ -24,10 +20,8 @@ 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 HAVE_REGEX_H
unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */
- regex_t preg;
-#endif
+ GRegex *preg;
char *servertag;
};