diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 6e2ad35d2..d2e985e68 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/glib.symbols b/glib/glib.symbols index 5ffbcb9fe..d5c1fc6a9 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -1405,6 +1405,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 1a1c41b37..7dc7abbd1 100644 --- a/glib/gregex.c +++ b/glib/gregex.c @@ -1455,6 +1455,27 @@ g_regex_get_capture_count (const GRegex *regex) return value; } +/** + * 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 4d6ac18e0..9b6a5fe70 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 7d1933334..ab9405533 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);