Panda3D
Public Member Functions | List of all members
GlobPattern Class Reference

This class can be used to test for string matches against standard Unix-shell filename globbing conventions. More...

#include "globPattern.h"

Public Member Functions

 GlobPattern (const string &pattern=string())
 
 GlobPattern (const GlobPattern &copy)
 
bool get_case_sensitive () const
 Returns whether the match is case sensitive (true) or case insensitive (false). More...
 
string get_const_prefix () const
 Returns the initial part of the pattern before the first glob character. More...
 
const string & get_nomatch_chars () const
 Returns the set of characters that are not matched by or ?. More...
 
const string & get_pattern () const
 Returns the pattern string that the GlobPattern object matches. More...
 
bool has_glob_characters () const
 Returns true if the pattern includes any special globbing characters, or false if it is just a literal string. More...
 
int match_files (vector_string &results, const Filename &cwd=Filename()) const
 Treats the GlobPattern as a filename pattern, and returns a list of any actual files that match the pattern. More...
 
bool matches (const string &candidate) const
 Returns true if the candidate string matches the pattern, false otherwise. More...
 
bool operator!= (const GlobPattern &other) const
 
bool operator< (const GlobPattern &other) const
 
void operator= (const GlobPattern &copy)
 
bool operator== (const GlobPattern &other) const
 
void output (ostream &out) const
 
void set_case_sensitive (bool case_sensitive)
 Sets whether the match is case sensitive (true) or case insensitive (false). More...
 
void set_nomatch_chars (const string &nomatch_chars)
 Specifies a set of characters that are not matched by or ?. More...
 
void set_pattern (const string &pattern)
 Changes the pattern string that the GlobPattern object matches. More...
 

Detailed Description

This class can be used to test for string matches against standard Unix-shell filename globbing conventions.

It serves as a portable standin for the Posix fnmatch() call.

A GlobPattern is given a pattern string, which can contain operators like *, ?, and []. Then it can be tested against any number of candidate strings; for each candidate, it will indicate whether the string matches the pattern or not. It can be used, for example, to scan a directory for all files matching a particular pattern.

Definition at line 37 of file globPattern.h.

Member Function Documentation

◆ get_case_sensitive()

bool GlobPattern::get_case_sensitive ( ) const
inline

Returns whether the match is case sensitive (true) or case insensitive (false).

The default is case sensitive.

Definition at line 124 of file globPattern.I.

References set_nomatch_chars().

Referenced by set_case_sensitive().

◆ get_const_prefix()

string GlobPattern::get_const_prefix ( ) const

Returns the initial part of the pattern before the first glob character.

Since many glob patterns begin with a sequence of static characters and end with one or more glob characters, this can be used to optimized searches through sorted indices.

Definition at line 57 of file globPattern.cxx.

References match_files().

Referenced by AsyncTaskManager::find_tasks_matching(), and has_glob_characters().

◆ get_nomatch_chars()

const string & GlobPattern::get_nomatch_chars ( ) const
inline

Returns the set of characters that are not matched by or ?.

Definition at line 146 of file globPattern.I.

References matches().

Referenced by set_nomatch_chars().

◆ get_pattern()

const string & GlobPattern::get_pattern ( ) const
inline

Returns the pattern string that the GlobPattern object matches.

Definition at line 100 of file globPattern.I.

References set_case_sensitive().

Referenced by set_pattern().

◆ has_glob_characters()

bool GlobPattern::has_glob_characters ( ) const

Returns true if the pattern includes any special globbing characters, or false if it is just a literal string.

Definition at line 26 of file globPattern.cxx.

References get_const_prefix().

Referenced by match_files().

◆ match_files()

int GlobPattern::match_files ( vector_string &  results,
const Filename cwd = Filename() 
) const

Treats the GlobPattern as a filename pattern, and returns a list of any actual files that match the pattern.

This is the behavior of the standard Posix glob() function. Any part of the filename may contain glob characters, including intermediate directory names.

If cwd is specified, it is the directory that relative filenames are taken to be relative to; otherwise, the actual current working directory is assumed.

The return value is the number of files matched, which are added to the results vector.

Definition at line 99 of file globPattern.cxx.

References Filename::exists(), has_glob_characters(), Filename::is_local(), matches(), Filename::scan_directory(), and set_case_sensitive().

Referenced by get_const_prefix().

◆ matches()

bool GlobPattern::matches ( const string &  candidate) const
inline

◆ set_case_sensitive()

void GlobPattern::set_case_sensitive ( bool  case_sensitive)
inline

Sets whether the match is case sensitive (true) or case insensitive (false).

The default is case sensitive.

Definition at line 112 of file globPattern.I.

References get_case_sensitive().

Referenced by get_pattern(), match_files(), TxaLine::parse(), and ConfigPageManager::reload_implicit_pages().

◆ set_nomatch_chars()

void GlobPattern::set_nomatch_chars ( const string &  nomatch_chars)
inline

Specifies a set of characters that are not matched by or ?.

Definition at line 135 of file globPattern.I.

References get_nomatch_chars().

Referenced by get_case_sensitive().

◆ set_pattern()

void GlobPattern::set_pattern ( const string &  pattern)
inline

Changes the pattern string that the GlobPattern object matches.

Definition at line 89 of file globPattern.I.

References get_pattern().


The documentation for this class was generated from the following files: