提交 b96e0dbb 编写于 作者: J Ján Tomko

util: use GRegex in virStringMatch

Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
上级 9c76dd3a
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include <config.h> #include <config.h>
#include <glib/gprintf.h> #include <glib/gprintf.h>
#include <regex.h>
#include <locale.h> #include <locale.h>
#include "c-ctype.h" #include "c-ctype.h"
...@@ -1089,24 +1088,18 @@ bool ...@@ -1089,24 +1088,18 @@ bool
virStringMatch(const char *str, virStringMatch(const char *str,
const char *regexp) const char *regexp)
{ {
regex_t re; g_autoptr(GRegex) regex = NULL;
int rv; g_autoptr(GError) err = NULL;
VIR_DEBUG("match '%s' for '%s'", str, regexp); VIR_DEBUG("match '%s' for '%s'", str, regexp);
if ((rv = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB)) != 0) { regex = g_regex_new(regexp, 0, 0, &err);
char error[100]; if (!regex) {
regerror(rv, &re, error, sizeof(error)); VIR_WARN("Failed to compile regex %s", err->message);
VIR_WARN("error while compiling regular expression '%s': %s",
regexp, error);
return false; return false;
} }
rv = regexec(&re, str, 0, NULL, 0); return g_regex_match(regex, str, 0, NULL);
regfree(&re);
return rv == 0;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册