From: Yevgen Muntyan Date: Sun, 3 Jun 2007 06:05:23 +0000 (+0000) Subject: fixed g_regex_fetch_named* for cases when (?J) is used inside a pattern X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=1db61c07d212270a50d257bb08d94111a8f33945;p=dana%2Fcg-glib.git fixed g_regex_fetch_named* for cases when (?J) is used inside a pattern 2007-06-03 Yevgen Muntyan * glib/gregex.c: fixed g_regex_fetch_named* for cases when (?J) is used inside a pattern (#442265, comment #12). * tests/regex-test.c: Test it. svn path=/trunk/; revision=5526 --- diff --git a/ChangeLog b/ChangeLog index 3b758b96..78c356d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,19 @@ +2007-06-03 Yevgen Muntyan + + * glib/gregex.c: fixed g_regex_fetch_named* for cases when (?J) + is used inside a pattern (#442265, comment #12). + * tests/regex-test.c: Test it. + 2007-06-03 Matthias Clasen * NEWS: Updates 2007-06-03 Yevgen Muntyan + Some API additions and changes (#442265). + * glib/gregex.c: - * glib/gregex.h: New functions: g_regex_ref(), g_regex_unref() which + * glib/gregex.h: new functions: g_regex_ref(), g_regex_unref() which replaces g_regex_free(); g_match_info_get_regex(), g_match_info_get_string(); g_regex_check_replacement(). Made g_match_info_expand_references() accept NULL; changed GRegexEvalCallback diff --git a/glib/gregex.c b/glib/gregex.c index 953cd269..52ea980c 100644 --- a/glib/gregex.c +++ b/glib/gregex.c @@ -222,7 +222,7 @@ match_info_new (const GRegex *regex, * g_match_info_get_regex: * @match_info: a #GMatchInfo * - * Returns #GRegex object used in @match_info. It belongs to glib + * Returns #GRegex object used in @match_info. It belongs to Glib * and must not be freed. Use g_regex_ref() if you need to keep it * after you free @match_info object. * @@ -617,8 +617,20 @@ get_matched_substring_number (const GMatchInfo *match_info, gchar *first, *last; guchar *entry; + /* + * FIXME: (?J) may be used inside the pattern as the equivalent of + * DUPNAMES compile option. In this case we can't know about it, + * and pcre doesn't tell us about it either, it uses private flag + * PCRE_JCHANGED for this. So we have to always search string + * table, unlike pcre which uses pcre_get_stringnumber() shortcut + * when possible. It shouldn't be actually bad since + * pcre_get_stringtable_entries() uses binary search; still would + * be better to fix it, to be not worse than pcre. + */ +#if 0 if ((match_info->regex->compile_opts & G_REGEX_DUPNAMES) == 0) return pcre_get_stringnumber (match_info->regex->pcre_re, name); +#endif /* This code is copied from pcre_get.c: get_first_set() */ entrysize = pcre_get_stringtable_entries (match_info->regex->pcre_re, diff --git a/tests/regex-test.c b/tests/regex-test.c index 111ca58c..26d96776 100644 --- a/tests/regex-test.c +++ b/tests/regex-test.c @@ -1829,6 +1829,13 @@ main (int argc, char *argv[]) TEST_NAMED_SUB_PATTERN_DUPNAMES("(?Px)|(?Pa)", "a", 0, "N", "a", 0, 1); TEST_NAMED_SUB_PATTERN_DUPNAMES("(?Px)y|(?Pa)b", "ab", 0, "N", "a", 0, 1); + /* DUPNAMES option inside the pattern */ + TEST_NAMED_SUB_PATTERN("(?J)(?Pa)|(?Pb)", "ab", 0, "N", "a", 0, 1); + TEST_NAMED_SUB_PATTERN("(?J)(?Paa)|(?Pa)", "aa", 0, "N", "aa", 0, 2); + TEST_NAMED_SUB_PATTERN("(?J)(?Paa)(?Pa)", "aaa", 0, "N", "aa", 0, 2); + TEST_NAMED_SUB_PATTERN("(?J)(?Px)|(?Pa)", "a", 0, "N", "a", 0, 1); + TEST_NAMED_SUB_PATTERN("(?J)(?Px)y|(?Pa)b", "ab", 0, "N", "a", 0, 1); + /* TEST_FETCH_ALL#(pattern, string, ...) */ TEST_FETCH_ALL0("a", ""); TEST_FETCH_ALL0("a", "b");