make_re() now doesn't free the argument.

This is good practice and also helped simplifying re_*() functions.
This commit is contained in:
Diogo Sousa 2013-10-21 04:22:25 +01:00 committed by TingPing
parent a72d40284d
commit a25363f5c3
1 changed files with 14 additions and 45 deletions

View File

@ -425,14 +425,14 @@ regex_match (const GRegex *re, const char *word, int *start, int *end)
#define PORT "(:[1-9][0-9]{0,4})" #define PORT "(:[1-9][0-9]{0,4})"
#define OPT_PORT "(" PORT ")?" #define OPT_PORT "(" PORT ")?"
GRegex * static GRegex *
make_re (char *grist) make_re (char *grist)
{ {
GRegex *ret; GRegex *ret;
GError *err = NULL; GError *err = NULL;
ret = g_regex_new (grist, G_REGEX_CASELESS | G_REGEX_OPTIMIZE, 0, &err); ret = g_regex_new (grist, G_REGEX_CASELESS | G_REGEX_OPTIMIZE, 0, &err);
g_free (grist);
return ret; return ret;
} }
@ -442,16 +442,11 @@ static const GRegex *
re_host (void) re_host (void)
{ {
static GRegex *host_ret; static GRegex *host_ret;
char *grist;
if (host_ret) return host_ret; if (host_ret) return host_ret;
grist = g_strdup ( host_ret = make_re ("(" "(" HOST_URL PORT ")|(" HOST ")" ")");
"("
"(" HOST_URL PORT ")|(" HOST ")"
")"
);
host_ret = make_re (grist);
return host_ret; return host_ret;
} }
@ -459,17 +454,10 @@ static const GRegex *
re_host6 (void) re_host6 (void)
{ {
static GRegex *host6_ret; static GRegex *host6_ret;
char *grist;
if (host6_ret) return host6_ret; if (host6_ret) return host6_ret;
grist = g_strdup ( host6_ret = make_re ("(" "(" IPV6ADDR ")|(" "\\[" IPV6ADDR "\\]" PORT ")" ")");
"("
"(" IPV6ADDR ")|(" "\\[" IPV6ADDR "\\]" PORT ")"
")"
);
host6_ret = make_re (grist);
return host6_ret; return host6_ret;
} }
@ -601,6 +589,7 @@ re_url (void)
grist = g_string_free (grist_gstr, FALSE); grist = g_string_free (grist_gstr, FALSE);
url_ret = make_re (grist); url_ret = make_re (grist);
g_free (grist);
return url_ret; return url_ret;
} }
@ -612,16 +601,11 @@ static const GRegex *
re_email (void) re_email (void)
{ {
static GRegex *email_ret; static GRegex *email_ret;
char *grist;
if (email_ret) return email_ret; if (email_ret) return email_ret;
grist = g_strdup ( email_ret = make_re ("(" EMAIL ")");
"("
EMAIL
")"
);
email_ret = make_re (grist);
return email_ret; return email_ret;
} }
@ -648,16 +632,11 @@ static const GRegex *
re_nick (void) re_nick (void)
{ {
static GRegex *nick_ret; static GRegex *nick_ret;
char *grist;
if (nick_ret) return nick_ret; if (nick_ret) return nick_ret;
grist = g_strdup ( nick_ret = make_re ("(" NICK ")");
"("
NICK
")"
);
nick_ret = make_re (grist);
return nick_ret; return nick_ret;
} }
@ -668,16 +647,11 @@ static const GRegex *
re_channel (void) re_channel (void)
{ {
static GRegex *channel_ret; static GRegex *channel_ret;
char *grist;
if (channel_ret) return channel_ret; if (channel_ret) return channel_ret;
grist = g_strdup ( channel_ret = make_re ("(" CHANNEL ")");
"("
CHANNEL
")"
);
channel_ret = make_re (grist);
return channel_ret; return channel_ret;
} }
@ -694,15 +668,10 @@ static const GRegex *
re_path (void) re_path (void)
{ {
static GRegex *path_ret; static GRegex *path_ret;
char *grist;
if (path_ret) return path_ret; if (path_ret) return path_ret;
grist = g_strdup ( path_ret = make_re ("(" FS_PATH ")");
"("
FS_PATH
")"
);
path_ret = make_re (grist);
return path_ret; return path_ret;
} }