Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | 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 GlobPattern &copy)
 
 GlobPattern (const std::string &pattern=std::string())
 
bool get_case_sensitive () const
 
std::string get_const_prefix () const
 Returns the initial part of the pattern before the first glob character.
 
const std::string & get_nomatch_chars () const
 
const std::string & get_pattern () const
 
bool has_glob_characters () const
 Returns true if the pattern includes any special globbing characters, or false if it is just a literal string.
 
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.
 
bool matches (const std::string &candidate) const
 Returns true if the candidate string matches the pattern, false otherwise.
 
bool matches_file (Filename candidate) const
 Treats the GlobPattern as a filename pattern, and returns true if the given filename matches the pattern.
 
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 (std::ostream &out) const
 
void set_case_sensitive (bool case_sensitive)
 
void set_nomatch_chars (const std::string &nomatch_chars)
 
void set_pattern (const std::string &pattern)
 

Public Attributes

 get_case_sensitive
 Returns whether the match is case sensitive (true) or case insensitive (false).
 
 get_nomatch_chars
 Returns the set of characters that are not matched by * or ?.
 
 get_pattern
 Returns the pattern string that the GlobPattern object matches.
 
 set_case_sensitive
 Sets whether the match is case sensitive (true) or case insensitive (false).
 
 set_nomatch_chars
 Specifies a set of characters that are not matched by * or ?.
 
 set_pattern
 Changes the pattern string that the GlobPattern object matches.
 

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 32 of file globPattern.h.

Constructor & Destructor Documentation

◆ GlobPattern() [1/2]

GlobPattern::GlobPattern ( const std::string & pattern = std::string())
inline

Definition at line 17 of file globPattern.I.

◆ GlobPattern() [2/2]

GlobPattern::GlobPattern ( const GlobPattern & copy)
inline

Definition at line 25 of file globPattern.I.

Member Function Documentation

◆ 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 52 of file globPattern.cxx.

Referenced by AsyncTaskManager::find_tasks_matching().

◆ 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 24 of file globPattern.cxx.

Referenced by FindApproxPath::add_match_name_glob().

◆ 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 89 of file globPattern.cxx.

References set_case_sensitive.

◆ matches()

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

◆ matches_file()

bool GlobPattern::matches_file ( Filename candidate) const

Treats the GlobPattern as a filename pattern, and returns true if the given filename matches the pattern.

Unlike matches(), this will not match slash characters for single asterisk characters, and it will ignore path components that only contain a dot.

Definition at line 235 of file globPattern.cxx.

References Filename::is_local().

◆ operator!=()

bool GlobPattern::operator!= ( const GlobPattern & other) const
inline

Definition at line 52 of file globPattern.I.

◆ operator<()

bool GlobPattern::operator< ( const GlobPattern & other) const
inline

Definition at line 60 of file globPattern.I.

◆ operator=()

void GlobPattern::operator= ( const GlobPattern & copy)
inline

Definition at line 35 of file globPattern.I.

◆ operator==()

bool GlobPattern::operator== ( const GlobPattern & other) const
inline

Definition at line 44 of file globPattern.I.

◆ output()

void GlobPattern::output ( std::ostream & out) const
inline

Definition at line 130 of file globPattern.I.

Member Data Documentation

◆ get_case_sensitive

bool GlobPattern::get_case_sensitive
inline

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

The default is case sensitive.

Definition at line 48 of file globPattern.h.

◆ get_nomatch_chars

const std::string & GlobPattern::get_nomatch_chars
inline

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

Definition at line 52 of file globPattern.h.

◆ get_pattern

const std::string & GlobPattern::get_pattern
inline

Returns the pattern string that the GlobPattern object matches.

Definition at line 44 of file globPattern.h.

◆ set_case_sensitive

void GlobPattern::set_case_sensitive
inline

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

The default is case sensitive.

Definition at line 48 of file globPattern.h.

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

◆ set_nomatch_chars

void GlobPattern::set_nomatch_chars
inline

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

Definition at line 52 of file globPattern.h.

◆ set_pattern

void GlobPattern::set_pattern
inline

Changes the pattern string that the GlobPattern object matches.

Definition at line 44 of file globPattern.h.

Referenced by FindApproxPath::add_match_name_glob(), and FindApproxPath::add_match_tag_value().


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