[glib/wip/pcre-update: 5/17] regex: Add accessor for PCRE_INFO_HASCRORLF



commit 591d41ef1f2cecf746b50b35597d8f6af23e35ff
Author: Christian Persch <chpe gnome org>
Date:   Thu Jun 7 15:57:15 2012 +0200

    regex: Add accessor for PCRE_INFO_HASCRORLF
    
    This flag is new in PCRE 7.3, and checks whether there is an explicit
    CR or LF reference in the pattern.

 docs/reference/glib/glib-sections.txt |    1 +
 glib/gregex.c                         |   21 +++++++++++++++++++++
 glib/gregex.h                         |    1 +
 glib/tests/regex.c                    |   11 +++++++++++
 4 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 6e2ad35..d2e985e 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1005,6 +1005,7 @@ g_regex_unref
 g_regex_get_pattern
 g_regex_get_max_backref
 g_regex_get_capture_count
+g_regex_get_has_cr_or_lf
 g_regex_get_string_number
 g_regex_get_compile_flags
 g_regex_get_match_flags
diff --git a/glib/gregex.c b/glib/gregex.c
index 1a1c41b..7dc7abb 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -1456,6 +1456,27 @@ g_regex_get_capture_count (const GRegex *regex)
 }
 
 /**
+ * g_regex_get_has_cr_or_lf:
+ * @regex: a #GRegex structure
+ *
+ * Checks whether the pattern contains explicit CR or LF references.
+ *
+ * Returns: %TRUE if the pattern contains explicit CR or LF references
+ *
+ * Since: 2.34
+ */
+gboolean
+g_regex_get_has_cr_or_lf (const GRegex *regex)
+{
+  gint value;
+
+  pcre_fullinfo (regex->pcre_re, regex->extra,
+                 PCRE_INFO_HASCRORLF, &value);
+
+  return !!value;
+}
+
+/**
  * g_regex_get_compile_flags:
  * @regex: a #GRegex
  *
diff --git a/glib/gregex.h b/glib/gregex.h
index 4d6ac18..9b6a5fe 100644
--- a/glib/gregex.h
+++ b/glib/gregex.h
@@ -406,6 +406,7 @@ void		  g_regex_unref			(GRegex              *regex);
 const gchar	 *g_regex_get_pattern		(const GRegex        *regex);
 gint		  g_regex_get_max_backref	(const GRegex        *regex);
 gint		  g_regex_get_capture_count	(const GRegex        *regex);
+gboolean          g_regex_get_has_cr_or_lf      (const GRegex        *regex);
 gint		  g_regex_get_string_number	(const GRegex        *regex, 
 						 const gchar         *name);
 gchar		 *g_regex_escape_string		(const gchar         *string,
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index 7d19333..ab94055 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2023,6 +2023,16 @@ test_multiline (void)
   g_assert_cmpint (count, ==, 2);
 }
 
+static void
+test_explicit_crlf (void)
+{
+  GRegex *regex;
+
+  regex = g_regex_new ("[\r\n]a", 0, 0, NULL);
+  g_assert_cmpint (g_regex_get_has_cr_or_lf (regex), ==, TRUE);
+  g_regex_unref (regex);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -2041,6 +2051,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/regex/condition", test_condition);
   g_test_add_func ("/regex/recursion", test_recursion);
   g_test_add_func ("/regex/multiline", test_multiline);
+  g_test_add_func ("/regex/explicit-crlf", test_explicit_crlf);
 
   /* TEST_NEW(pattern, compile_opts, match_opts) */
   TEST_NEW("", 0, 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]