MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //usr/share/gtk-doc/html/glib/glib-Glob-style-pattern-matching.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Glob-style pattern matching</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
<link rel="prev" href="glib-Commandline-option-parser.html" title="Commandline option parser">
<link rel="next" href="glib-Simple-XML-Subset-Parser.html" title="Simple XML Subset Parser">
<meta name="generator" content="GTK-Doc V1.6 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="glib.html" title="GLib Overview">
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
<link rel="chapter" href="tools.html" title="GLib Tools">
<link rel="index" href="ix01.html" title="Index">
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Commandline-option-parser.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GLib Reference Manual</th>
<td><a accesskey="n" href="glib-Simple-XML-Subset-Parser.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3141896" class="shortcut">Top</a>
                  &#160;|&#160;
                  <a href="#id3142100" class="shortcut">Description</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="glib-Glob-style-pattern-matching"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id3141896"></a><span class="refentrytitle">Glob-style pattern matching</span>
</h2>
<p>Glob-style pattern matching &#8212; matches strings against patterns containing '*' (wildcard) and '?' (joker).</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">

#include &lt;glib.h&gt;


            <a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a>;
<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a>* <a href="glib-Glob-style-pattern-matching.html#g-pattern-spec-new">g_pattern_spec_new</a>            (const <a href="glib-Basic-Types.html#gchar">gchar</a> *pattern);
void        <a href="glib-Glob-style-pattern-matching.html#g-pattern-spec-free">g_pattern_spec_free</a>             (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-Glob-style-pattern-matching.html#g-pattern-spec-equal">g_pattern_spec_equal</a>            (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec1,
                                             <a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec2);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-Glob-style-pattern-matching.html#g-pattern-match">g_pattern_match</a>                 (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec,
                                             <a href="glib-Basic-Types.html#guint">guint</a> string_length,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string_reversed);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-Glob-style-pattern-matching.html#g-pattern-match-string">g_pattern_match_string</a>          (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-Glob-style-pattern-matching.html#g-pattern-match-simple">g_pattern_match_simple</a>          (const <a href="glib-Basic-Types.html#gchar">gchar</a> *pattern,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);
</pre>
</div>
<div class="refsect1" lang="en">
<a name="id3142100"></a><h2>Description</h2>
<p>
The <code class="function">g_pattern_match*</code> functions match a string 
against a pattern containing '*' and '?' wildcards with similar semantics 
as the standard <code class="function">glob()</code> function: '*' matches an arbitrary, possibly empty, 
string, '?' matches an arbitrary character.
</p>
<p>
Note that in contrast to <code class="function">glob()</code>, the '/' character
<span class="emphasis"><em>can</em></span> be matched by the wildcards, there are no
'[...]' character ranges and '*' and '?' can <span class="emphasis"><em>not</em></span>
be escaped to include them literally in a pattern. 
</p>
<p>
When multiple strings must be matched against the same pattern, it
is better to compile the pattern to a <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a> using 
<a href="glib-Glob-style-pattern-matching.html#g-pattern-spec-new"><code class="function">g_pattern_spec_new()</code></a> and use <a href="glib-Glob-style-pattern-matching.html#g-pattern-match-string"><code class="function">g_pattern_match_string()</code></a> instead of 
<a href="glib-Glob-style-pattern-matching.html#g-pattern-match-simple"><code class="function">g_pattern_match_simple()</code></a>.  This avoids the overhead of repeated 
pattern compilation.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id3142207"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id3142217"></a><h3>
<a name="GPatternSpec"></a>GPatternSpec</h3>
<a class="indexterm" name="id3142230"></a><pre class="programlisting">typedef struct _GPatternSpec GPatternSpec;</pre>
<p>
A <span class="structname">GPatternSpec</span> is the 'compiled' form of a pattern.
This structure is opaque and its fields cannot be accessed directly.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3142250"></a><h3>
<a name="g-pattern-spec-new"></a>g_pattern_spec_new ()</h3>
<a class="indexterm" name="id3142263"></a><pre class="programlisting"><a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a>* g_pattern_spec_new            (const <a href="glib-Basic-Types.html#gchar">gchar</a> *pattern);</pre>
<p>
Compiles a pattern to a <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>pattern</code></em>&#160;:</span></td>
<td>a zero-terminated UTF-8 encoded string.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td>a newly-allocated <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3142338"></a><h3>
<a name="g-pattern-spec-free"></a>g_pattern_spec_free ()</h3>
<a class="indexterm" name="id3142351"></a><pre class="programlisting">void        g_pattern_spec_free             (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec);</pre>
<p>
Frees the memory allocated for the <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td>
<span class="term"><em class="parameter"><code>pspec</code></em>&#160;:</span></td>
<td>a <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.


</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3142414"></a><h3>
<a name="g-pattern-spec-equal"></a>g_pattern_spec_equal ()</h3>
<a class="indexterm" name="id3142427"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_pattern_spec_equal            (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec1,
                                             <a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec2);</pre>
<p>
Compares two compiled pattern specs and returns whether they
will match the same set of strings.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>pspec1</code></em>&#160;:</span></td>
<td>a <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>pspec2</code></em>&#160;:</span></td>
<td>another <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td>Whether the compiled patterns are equal.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3142524"></a><h3>
<a name="g-pattern-match"></a>g_pattern_match ()</h3>
<a class="indexterm" name="id3142537"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_pattern_match                 (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec,
                                             <a href="glib-Basic-Types.html#guint">guint</a> string_length,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string_reversed);</pre>
<p>
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 <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>,
this is more efficient if the reversed version of the string to be matched is
not at hand, as <a href="glib-Glob-style-pattern-matching.html#g-pattern-match"><code class="function">g_pattern_match()</code></a> will only construct it if the compiled pattern
requires reverse matches.
</p>
<p>
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
<a href="glib-Glob-style-pattern-matching.html#g-pattern-match"><code class="function">g_pattern_match()</code></a>.
</p>
<p>
Note also that the reverse of a UTF-8 encoded string can in general 
<span class="emphasis"><em>not</em></span> be obtained by <a href="glib-String-Utility-Functions.html#g-strreverse"><code class="function">g_strreverse()</code></a>.
This works only if the string doesn't contain any multibyte characters.
Glib offers the <code class="function">g_utf_strreverse()</code> function to reverse UTF-8 encoded strings.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>pspec</code></em>&#160;:</span></td>
<td>a <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>string_length</code></em>&#160;:</span></td>
<td>the length of <em class="parameter"><code>string</code></em>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>string</code></em>&#160;:</span></td>
<td>the UTF-8 encoded string to match.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>string_reversed</code></em>&#160;:</span></td>
<td>the reverse of <em class="parameter"><code>string</code></em> or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td>
<a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>string</code></em> matches <em class="parameter"><code>pspec</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3142787"></a><h3>
<a name="g-pattern-match-string"></a>g_pattern_match_string ()</h3>
<a class="indexterm" name="id3142800"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_pattern_match_string          (<a href="glib-Glob-style-pattern-matching.html#GPatternSpec">GPatternSpec</a> *pspec,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre>
<p>
Matches a string against a compiled pattern. If the string is to
be matched against more than one pattern, consider using
<a href="glib-Glob-style-pattern-matching.html#g-pattern-match"><code class="function">g_pattern_match()</code></a> instead while supplying the reversed string.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>pspec</code></em>&#160;:</span></td>
<td>a <a href="glib-Glob-style-pattern-matching.html#GPatternSpec"><span class="type">GPatternSpec</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>string</code></em>&#160;:</span></td>
<td>the UTF-8 encoded string to match.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td>
<a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>string</code></em> matches <em class="parameter"><code>pspec</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3142921"></a><h3>
<a name="g-pattern-match-simple"></a>g_pattern_match_simple ()</h3>
<a class="indexterm" name="id3142934"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_pattern_match_simple          (const <a href="glib-Basic-Types.html#gchar">gchar</a> *pattern,
                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre>
<p>
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 <a href="glib-Glob-style-pattern-matching.html#g-pattern-spec-new"><code class="function">g_pattern_spec_new()</code></a> and call <a href="glib-Glob-style-pattern-matching.html#g-pattern-match-string"><code class="function">g_pattern_match_string()</code></a>
repetively.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>pattern</code></em>&#160;:</span></td>
<td>the UTF-8 encoded pattern.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>string</code></em>&#160;:</span></td>
<td>the UTF-8 encoded string to match.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td>
<a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>string</code></em> matches <em class="parameter"><code>pspec</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
</body>
</html>