summaryrefslogtreecommitdiff
path: root/src/fe-common/core
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2016-06-23 13:25:23 +0200
committerAilin Nemui <ailin@z30a.localdomain>2017-01-02 17:50:14 +0100
commit5dcf291f2144564363f734dba15760d3a82b61c2 (patch)
tree05c0df68c8cea8474336a006d1db1aea978fe7f1 /src/fe-common/core
parent5eaead761f1812fb9d4058b2bc38468521794693 (diff)
downloadirssi-5dcf291f2144564363f734dba15760d3a82b61c2.zip
Use the RAW flag when building the regexps.
Also, plugged a memory leak when retrieving the match position.
Diffstat (limited to 'src/fe-common/core')
-rw-r--r--src/fe-common/core/hilight-text.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c
index e3dcc2d9..7a7f473c 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -121,7 +121,7 @@ static void hilight_init_rec(HILIGHT_REC *rec)
if (rec->preg != NULL)
g_regex_unref(rec->preg);
- rec->preg = g_regex_new(rec->text, G_REGEX_CASELESS, 0, NULL);
+ rec->preg = g_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, NULL);
}
void hilight_create(HILIGHT_REC *rec)
@@ -188,22 +188,25 @@ static HILIGHT_REC *hilight_find(const char *text, char **channels)
return NULL;
}
-static int hilight_match_text(HILIGHT_REC *rec, const char *text,
+static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text,
int *match_beg, int *match_end)
{
- char *match;
+ gboolean ret = FALSE;
if (rec->regexp) {
- GMatchInfo *match;
-
if (rec->preg != NULL) {
+ GMatchInfo *match;
+
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);
- }
+ if (g_match_info_matches(match))
+ ret = g_match_info_fetch_pos(match, 0, match_beg, match_end);
+
+ g_match_info_free(match);
}
} else {
+ char *match;
+
if (rec->case_sensitive) {
match = rec->fullword ?
strstr_full(text, rec->text) :
@@ -218,11 +221,11 @@ static int hilight_match_text(HILIGHT_REC *rec, const char *text,
*match_beg = (int) (match-text);
*match_end = *match_beg + strlen(rec->text);
}
- return TRUE;
+ ret = TRUE;
}
}
- return FALSE;
+ return ret;
}
#define hilight_match_level(rec, level) \