[glib/wip/pcre-update: 7/8] regex: Add g_regex_get_match_empty
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/pcre-update: 7/8] regex: Add g_regex_get_match_empty
- Date: Sun, 23 Nov 2014 18:48:22 +0000 (UTC)
commit 5f62610ce36ef7cf34258b8a556e0000f75b39ea
Author: Christian Persch <chpe gnome org>
Date: Sat Nov 22 22:04:05 2014 +0100
regex: Add g_regex_get_match_empty
This checks whether the pattern matches the empty string. Since PCRE 8.34.
docs/reference/glib/glib-sections.txt | 1 +
glib/gregex.c | 21 +++++++++++++++++++++
glib/gregex.h | 2 ++
glib/tests/regex.c | 15 +++++++++++++++
4 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 19bae6f..ca4b65f 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1017,6 +1017,7 @@ g_regex_ref
g_regex_unref
g_regex_get_pattern
g_regex_get_max_backref
+g_regex_get_match_empty
g_regex_get_capture_count
g_regex_get_has_cr_or_lf
g_regex_get_max_lookbehind
diff --git a/glib/gregex.c b/glib/gregex.c
index 1f8ebe8..c2f9a32 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -1579,6 +1579,27 @@ g_regex_get_max_lookbehind (const GRegex *regex)
}
/**
+ * g_regex_get_match_empty:
+ * @regex: a #GRegex structure
+ *
+ * Returns whether the pattern matches the empty string.
+ *
+ * Returns: %TRUE if the pattern matches the emtpy string
+ *
+ * Since: 2.44
+ */
+gboolean
+g_regex_get_match_empty (const GRegex *regex)
+{
+ gint match_empty;
+
+ pcre_fullinfo (regex->pcre_re, regex->extra,
+ PCRE_INFO_MATCH_EMPTY, &match_empty);
+
+ return match_empty != 0;
+}
+
+/**
* g_regex_get_compile_flags:
* @regex: a #GRegex
*
diff --git a/glib/gregex.h b/glib/gregex.h
index 28d4dd9..f7c6da1 100644
--- a/glib/gregex.h
+++ b/glib/gregex.h
@@ -473,6 +473,8 @@ GLIB_AVAILABLE_IN_ALL
gboolean g_regex_get_has_cr_or_lf (const GRegex *regex);
GLIB_AVAILABLE_IN_2_38
gint g_regex_get_max_lookbehind (const GRegex *regex);
+GLIB_AVAILABLE_IN_2_44
+gboolean g_regex_get_match_empty (const GRegex *regex);
GLIB_AVAILABLE_IN_ALL
gint g_regex_get_string_number (const GRegex *regex,
const gchar *name);
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index b9380e7..87e52f1 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2159,6 +2159,20 @@ test_max_lookbehind (void)
g_regex_unref (regex);
}
+static void
+test_match_empty (void)
+{
+ GRegex *regex;
+
+ regex = g_regex_new ("a+", 0, 0, NULL);
+ g_assert_cmpint (g_regex_get_match_empty (regex), ==, FALSE);
+ g_regex_unref (regex);
+
+ regex = g_regex_new ("a*", 0, 0, NULL);
+ g_assert_cmpint (g_regex_get_match_empty (regex), ==, TRUE);
+ g_regex_unref (regex);
+}
+
int
main (int argc, char *argv[])
{
@@ -2178,6 +2192,7 @@ main (int argc, char *argv[])
g_test_add_func ("/regex/multiline", test_multiline);
g_test_add_func ("/regex/explicit-crlf", test_explicit_crlf);
g_test_add_func ("/regex/max-lookbehind", test_max_lookbehind);
+ g_test_add_func ("/regex/match-empty", test_match_empty);
/* TEST_NEW(pattern, compile_opts, match_opts) */
TEST_NEW("[A-Z]+", G_REGEX_CASELESS | G_REGEX_EXTENDED | G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTBOL |
G_REGEX_MATCH_PARTIAL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]