make struct _GPatternSpec and GMatchType private. (g_pattern_equal): new

Fri Oct 12 18:24:02 2001  Tim Janik  <timj@gtk.org>

        * glib/gpattern.[hc]: make struct _GPatternSpec and GMatchType
        private.
        (g_pattern_equal): new function to return equality of two patterns
        (required because GPatternSpec is private now).
        (g_pattern_spec_new): fix bug wrg wildcard counting which produced
        incorrect pattern specs (discovered by Matthias Clasen).
        optimized code so we just keep one compiled pattern string now.
        correctly canonicalize patterns. reduce string walks, optimize
        decision about MATCH_ALL vs. MATCH_ALL_TAIL.
        (g_pattern_match_string): call just g_pattern_match() with NULL
        reversed string.
        (g_pattern_match): allow NULL reversed strings now, reverse_dup
        strings on demand.

        * tests/patterntest.c (test_compilation): added an extended testcase
        for pattern matching from Matthias Clasen <matthiasc@poet.de>.

Sat Oct 13 06:58:23 2001  Tim Janik  <timj@gtk.org>

        * glib/tmpl/patterns.sgml: amended documentation.
This commit is contained in:
Tim Janik
2001-10-13 05:54:10 +00:00
committed by Tim Janik
parent 96bc4f0c3b
commit 92dfa96114
19 changed files with 607 additions and 168 deletions

View File

@@ -1,3 +1,7 @@
Sat Oct 13 06:58:23 2001 Tim Janik <timj@gtk.org>
* glib/tmpl/patterns.sgml: amended documentation.
2001-10-11 Matthias Clasen <matthiasc@poet.de>
* glib/tmpl/patterns.sgml, glib/tmpl/shell.sgml: Updates.

View File

@@ -748,6 +748,7 @@ GMatchType
GPatternSpec
g_pattern_spec_new
g_pattern_spec_free
g_pattern_spec_equal
g_pattern_match
g_pattern_match_string
g_pattern_match_simple

View File

@@ -78,6 +78,20 @@ Specifies the type of function passed to g_set_error_handler().
@G_IO_FILE_MODE_READ_WRITE_TRUNCATE:
@G_IO_FILE_MODE_READ_WRITE_APPEND:
<!-- ##### ENUM GMatchType ##### -->
<para>
Enumeration representing different kinds of patterns. This is only used
internally for optimizing the match algorithm.
</para>
@G_MATCH_ALL: a general pattern.
@G_MATCH_ALL_TAIL: a general pattern which contains a fixed part matching
the end of the string.
@G_MATCH_HEAD: a pattern matching every string with a certain prefix.
@G_MATCH_TAIL: a pattern matching every string with a certain suffix.
@G_MATCH_EXACT: a pattern matching exactly one string.
@G_MATCH_LAST:
<!-- ##### USER_FUNCTION GWarningFunc ##### -->
<para>
Specifies the type of function passed to g_set_warning_handler().

View File

@@ -3,7 +3,7 @@ Glob-style pattern matching
<!-- ##### SECTION Short_Description ##### -->
Matches strings against patterns containing '*' and '?' wildcards.
Matches strings against patterns containing '*' (wildcard) and '?' (joker).
<!-- ##### SECTION Long_Description ##### -->
<para>
@@ -15,7 +15,7 @@ arbitrary, possibly empty, string, '?' matches an arbitrary character.
<para>
Note that in contrast to <function>glob()</function>, the '/' character
<emphasis>can</emphasis> be matched by the wildcards, there are no
'[...]' character ranges and '*', '?' and '[' can <emphasis>not</emphasis>
'[...]' character ranges and '*' and '?' can <emphasis>not</emphasis>
be escaped to include them literally in a pattern.
</para>
<para>
@@ -23,7 +23,7 @@ The pattern matcher is restricted to ASCII and will not work correctly with
multibyte UTF-8 characters in the pattern or in the string to match.
</para>
<para>
When multiple string must be matched against the same pattern, it
When multiple strings must be matched against the same pattern, it
is better to compile the pattern to a #GPatternSpec using
g_pattern_spec_new() and use g_pattern_match_string() instead of
g_pattern_match_simple(). This avoids the overhead of repeated
@@ -32,41 +32,22 @@ pattern compilation.
<!-- ##### SECTION See_Also ##### -->
<para>
g_strreverse()
</para>
<!-- ##### ENUM GMatchType ##### -->
<para>
Enumeration representing different kinds of patterns. This is only used
internally for optimizing the match algorithm.
</para>
@G_MATCH_ALL: a general pattern.
@G_MATCH_ALL_TAIL: a general pattern which contains a fixed part matching
the end of the string.
@G_MATCH_HEAD: a pattern matching every string with a certain prefix.
@G_MATCH_TAIL: a pattern matching every string with a certain suffix.
@G_MATCH_EXACT: a pattern matching exactly one string.
@G_MATCH_LAST:
<!-- ##### STRUCT GPatternSpec ##### -->
<para>
A <structname>GPatternSpec</structname> is the 'compiled' form of a pattern.
There should be no need to access its fields.
This structure is opaque and its fields and cannot be accessed.
</para>
@match_type: the #GMatchType of the pattern.
@pattern_length: the length of the pattern.
@pattern: the pattern. Note that this may be different from the @pattern
used to construct this <structname>GPatternSpec</structname>.
@pattern_reversed: the reverse of @pattern.
<!-- ##### FUNCTION g_pattern_spec_new ##### -->
<para>
Compiles a pattern to a #GPatternSpec.
</para>
@pattern: a string.
@pattern: a zero terminated string.
@Returns: a newly-allocated #GPatternSpec.
@@ -78,21 +59,43 @@ Frees the memory allocated for the #GPatternSpec.
@pspec: a #GPatternSpec.
<!-- ##### FUNCTION g_pattern_spec_equal ##### -->
<para>
Compares two compiled pattern specs and returns whether they
will match the same set of strings.
</para>
@pspec1: a #GPatternSpec.
@pspec2: another #GPatternSpec.
@Returns: Whether the compiled patterns are equal.
<!-- ##### FUNCTION g_pattern_match ##### -->
<para>
Matches a string against a compiled pattern.
Matches a string against a compiled pattern. Passing the correct length of the
string given is mandatory. The reversed string can be omitted by passing %NULL,
this is more efficient if the reversed version of the string to be matched is
not at hand, as g_pattern_match() will only construct it if the compiled pattern
requires reverse matches.
Note that, if the user code will (possibly) match a string against a multitude of
patterns containing wildcards, chances are high that some patterns will require
a reversed string. In this case, it's more efficient to provide the reversed
string to avoid multiple constructions thereof in the various calls to
g_pattern_match().
</para>
@pspec: a #GPatternSpec.
@string_length: the length of @string.
@string: the string to match.
@string_reversed: the reverse of @string.
@string_reversed: the reverse of @string or %NULL.
@Returns: %TRUE if @string matches @pspec.
<!-- ##### FUNCTION g_pattern_match_string ##### -->
<para>
Matches a string against a compiled pattern.
Matches a string against a compiled pattern. If the string is to
be matched against more than one pattern, consider using
g_pattern_match() instead while supplying the reversed string.
</para>
@pspec: a #GPatternSpec.
@@ -102,7 +105,10 @@ Matches a string against a compiled pattern.
<!-- ##### FUNCTION g_pattern_match_simple ##### -->
<para>
Matches a string against a pattern.
Matches a string against a pattern given as a string.
If this function is to be called in a loop, it's more efficient to compile
the pattern once with g_pattern_spec_new() and call g_pattern_match_string()
repetively.
</para>
@pattern: the pattern.

View File

@@ -555,11 +555,11 @@ value if @s1 > @s2.
<!-- ##### FUNCTION g_strreverse ##### -->
<para>
Reverses all of the characters in a string.
For example, g_strreverse ("abcdef") would be "fedcba".
For example, g_strreverse ("abcdef") will result in "fedcba".
</para>
@string: the string to reverse.
@Returns:
@Returns: the same pointer passed in as @string.
<!-- ##### FUNCTION g_strtod ##### -->

View File

@@ -213,6 +213,8 @@ The predefined identifiers of the reserved fundamental types.
@G_TYPE_PARAM_UINT: Identifier for the "#GParamSpecUInt" type.
@G_TYPE_PARAM_LONG: Identifier for the "#GParamSpecLong" type.
@G_TYPE_PARAM_ULONG: Identifier for the "#GParamSpecULong" type.
@G_TYPE_PARAM_INT64:
@G_TYPE_PARAM_UINT64:
@G_TYPE_PARAM_UNICHAR:
@G_TYPE_PARAM_ENUM: Identifier for the "#GParamSpecEnum" type.
@G_TYPE_PARAM_FLAGS: Identifier for the "#GParamSpecFlags" type.
@@ -225,8 +227,6 @@ The predefined identifiers of the reserved fundamental types.
@G_TYPE_PARAM_VALUE_ARRAY: Identifier for the "#GParamSpecValueArray" type.
@G_TYPE_PARAM_CLOSURE: Identifier for the "#GParamClosure" type.
@G_TYPE_PARAM_OBJECT: Identifier for the "#GParamSpecObject" type.
@G_TYPE_PARAM_INT64:
@G_TYPE_PARAM_UINT64:
<!-- ##### STRUCT GTypeInterface ##### -->
<para>