fixed g_regex_fetch_named* for cases when (?J) is used inside a pattern

2007-06-03  Yevgen Muntyan  <muntyan@tamu.edu>

	* 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
This commit is contained in:
Yevgen Muntyan 2007-06-03 06:05:23 +00:00 committed by Yevgen Muntyan
parent 318b4ce486
commit 1db61c07d2
3 changed files with 29 additions and 2 deletions

View File

@ -1,11 +1,19 @@
2007-06-03 Yevgen Muntyan <muntyan@tamu.edu>
* 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 <mclasen@redhat.com>
* NEWS: Updates
2007-06-03 Yevgen Muntyan <muntyan@tamu.edu>
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

View File

@ -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,

View File

@ -1829,6 +1829,13 @@ main (int argc, char *argv[])
TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)|(?P<N>a)", "a", 0, "N", "a", 0, 1);
TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)y|(?P<N>a)b", "ab", 0, "N", "a", 0, 1);
/* DUPNAMES option inside the pattern */
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>a)|(?P<N>b)", "ab", 0, "N", "a", 0, 1);
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>aa)|(?P<N>a)", "aa", 0, "N", "aa", 0, 2);
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>aa)(?P<N>a)", "aaa", 0, "N", "aa", 0, 2);
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>x)|(?P<N>a)", "a", 0, "N", "a", 0, 1);
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>x)y|(?P<N>a)b", "ab", 0, "N", "a", 0, 1);
/* TEST_FETCH_ALL#(pattern, string, ...) */
TEST_FETCH_ALL0("a", "");
TEST_FETCH_ALL0("a", "b");