Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Inti::G::PatternSpec Class Reference

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

`#include <inti/glib/pattern.h>`

Inheritance diagram for Inti::G::PatternSpec:

List of all members.

## Public Member Functions

Constructors

- PatternSpec (const char *pattern)
    Constructs a PatternSpec, the compiled form of a pattern.
- PatternSpec (const String &pattern)
    Constructs a PatternSpec, the compiled form of a pattern.
- ~PatternSpec ()
    Destructor.

Accessors

- GPatternSpec * g_pattern_spec () const
    Get a pointer to the GPatternSpec object.
- operator GPatternSpec * () const
    Conversion operator; Safely converts a G::PatternSpec object into a GPatternSpec pointer.
- bool equal (const PatternSpec &other) const
    Compares this compiled pattern spec with other and returns whether they will match the same set of strings.
- bool 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.
- bool 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.

Methods

- bool match (const String &string)
    Matches a string against a compiled pattern.
- bool match (const String &string, const String &string_reversed)
    Matches a string against a compiled pattern.

## Static Public Member Functions

- bool match_simple (const String &pattern, const String &string)
    Matches a string against a pattern given as a string.

## 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

Inti::G::PatternSpec::PatternSpec | ( | const char * | pattern | ) |

Constructs a PatternSpec, the compiled form of a pattern.

Parameters:

  pattern | A zero-terminated UTF-8 encoded string.

Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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:

- pattern.h

Main Page - Footer