Panda3D
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...

Public Member Functions

 __init__ (const GlobPattern copy)
 
 __init__ (str pattern)
 
bool getCaseSensitive ()
 Returns whether the match is case sensitive (true) or case insensitive (false). More...
 
str getConstPrefix ()
 Returns the initial part of the pattern before the first glob character. More...
 
str getNomatchChars ()
 Returns the set of characters that are not matched by * or ?. More...
 
str getPattern ()
 Returns the pattern string that the GlobPattern object matches. More...
 
bool hasGlobCharacters ()
 Returns true if the pattern includes any special globbing characters, or false if it is just a literal string. More...
 
bool matches (str candidate)
 Returns true if the candidate string matches the pattern, false otherwise. More...
 
bool matchesFile (Filename candidate)
 Treats the GlobPattern as a filename pattern, and returns true if the given filename matches the pattern. More...
 
object matchFiles (const Filename cwd)
 
int matchFiles (VectorString results, const Filename cwd)
 Treats the GlobPattern as a filename pattern, and returns a list of any actual files that match the pattern. More...
 
bool operator != (const GlobPattern other)
 
bool operator< (const GlobPattern other)
 
GlobPattern operator= (const GlobPattern copy)
 
bool operator== (const GlobPattern other)
 
 output (Ostream out)
 
 setCaseSensitive (bool case_sensitive)
 Sets whether the match is case sensitive (true) or case insensitive (false). More...
 
 setNomatchChars (str nomatch_chars)
 Specifies a set of characters that are not matched by * or ?. More...
 
 setPattern (str pattern)
 Changes the pattern string that the GlobPattern object matches. More...
 

Public Attributes

bool case_sensitive
 Returns whether the match is case sensitive (true) or case insensitive (false). More...
 
const String nomatch_chars
 Returns the set of characters that are not matched by * or ?. More...
 
const String pattern
 Returns 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.

Member Function Documentation

◆ __init__() [1/2]

__init__ ( const GlobPattern  copy)

◆ __init__() [2/2]

__init__ ( str  pattern)

◆ getCaseSensitive()

bool getCaseSensitive ( )

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

The default is case sensitive.

◆ getConstPrefix()

str getConstPrefix ( )

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.

◆ getNomatchChars()

str getNomatchChars ( )

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

◆ getPattern()

str getPattern ( )

Returns the pattern string that the GlobPattern object matches.

◆ hasGlobCharacters()

bool hasGlobCharacters ( )

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

◆ matches()

bool matches ( str  candidate)

Returns true if the candidate string matches the pattern, false otherwise.

◆ matchesFile()

bool matchesFile ( Filename  candidate)

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.

◆ matchFiles() [1/2]

object matchFiles ( const Filename  cwd)

◆ matchFiles() [2/2]

int matchFiles ( VectorString  results,
const Filename  cwd 
)

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.

◆ operator !=()

bool operator != ( const GlobPattern  other)

◆ operator<()

bool operator< ( const GlobPattern  other)

◆ operator=()

GlobPattern operator= ( const GlobPattern  copy)

◆ operator==()

bool operator== ( const GlobPattern  other)

◆ output()

output ( Ostream  out)

◆ setCaseSensitive()

setCaseSensitive ( bool  case_sensitive)

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

The default is case sensitive.

◆ setNomatchChars()

setNomatchChars ( str  nomatch_chars)

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

◆ setPattern()

setPattern ( str  pattern)

Changes the pattern string that the GlobPattern object matches.

Member Data Documentation

◆ case_sensitive

bool case_sensitive

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

The default is case sensitive.

◆ nomatch_chars

const String nomatch_chars

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

◆ pattern

const String pattern

Returns the pattern string that the GlobPattern object matches.