Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::G::PatternSpec Class Reference

A GPatternSpec C++ wrapper interface. More...

#include <xfc/glib/pattern.hh>

Inheritance diagram for Xfc::G::PatternSpec:

Xfc::Object Xfc::Trackable List of all members.

Public Member Functions

Constructors
Accessors
Methods

Static Public Member Functions

Methods

Detailed Description

A GPatternSpec C++ wrapper interface.

A PatternSpec is the 'compiled' form of a pattern. Its match() and match_simple() methods match a string against a pattern containing '*' and '?' wildcards with similar semantics as the standard glob() function: '*' matches an arbitrary, possibly empty, string, '?' matches an arbitrary character.

Note that in contrast to glob(), the '/' character can be matched by the wildcards, there are no '[...]' character ranges and '*' and '?' can not be escaped to include them literally in a pattern.

When multiple strings must be matched against the same pattern, it is better to compile the pattern to a G::PatternSpec and use match() instead of match_simple(). This avoids the overhead of repeated pattern compilation.


Constructor & Destructor Documentation

Xfc::G::PatternSpec::PatternSpec const char *  pattern  ) 
 

Constructs a PatternSpec, the compiled form of a pattern.

Parameters:
pattern A zero-terminated UTF-8 encoded string.

Xfc::G::PatternSpec::PatternSpec const String pattern  ) 
 

Constructs a PatternSpec, the compiled form of a pattern.

Parameters:
pattern A UTF-8 encoded string.


Member Function Documentation

bool Xfc::G::PatternSpec::equal const PatternSpec other  )  const
 

Compares this compiled pattern spec with other and returns whether they will match the same set of strings.

Parameters:
other Another PatternSpec.
Returns:
Whether the compiled patterns are equal.

bool Xfc::G::PatternSpec::match const String string,
const String string_reversed
 

Matches a string against a compiled pattern.

Parameters:
string The UTF-8 encoded string to match.
string_reversed The reverse of string or null.
Returns:
true if string matches this pattern.
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 match().

Note also that the reverse of a UTF-8 encoded string can in general not be obtained by g_strreverse(). This works only if the string doesn't contain any multibyte characters. Glib doesn't currently offer a function to reverse UTF-8 encoded strings.

bool Xfc::G::PatternSpec::match const String string  ) 
 

Matches a string against a compiled pattern.

Parameters:
string The UTF-8 encoded string to match.
Returns:
true if string matches this pattern.
If the string is to be matched against more than one pattern, consider using this match() method instead while supplying the reversed string. See match(const String&, const String&) for details.

bool Xfc::G::PatternSpec::match_simple const String pattern,
const String string
[static]
 

Matches a string against a pattern given as a string.

Parameters:
pattern The UTF-8 encoded pattern.
string The UTF-8 encoded string to match.
Returns:
true if string matches pspec.
If this function is to be called in a loop, it's more efficient to construct the pattern once as a PatternSpec and call match() repetitively.

bool Xfc::G::PatternSpec::operator!= const PatternSpec other  )  const
 

Inequality operator; compares this compiled pattern spec with other and returns true if they will not match the same set of strings.

Parameters:
other Another PatternSpec.
Returns:
Whether the compiled patterns are not equal.

bool Xfc::G::PatternSpec::operator== const PatternSpec other  )  const
 

Equality operator; compares this compiled pattern spec with other and returns true if they will match the same set of strings.

Parameters:
other Another PatternSpec.
Returns:
Whether the compiled patterns are equal.


The documentation for this class was generated from the following file: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3