Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File 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>

List of all members.

Public Member Functions

 GlobPattern (const string &pattern=string())
 GlobPattern (const GlobPattern &copy)
void operator= (const GlobPattern &copy)
void set_pattern (const string &pattern)
 Changes the pattern string that the GlobPattern object matches.

const string & get_pattern () const
 Returns the pattern string that the GlobPattern object matches.

bool matches (const string &candidate) const
 Returns true if the candidate string matches the pattern, false otherwise.

void output (ostream &out) 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())
 Treats the GlobPattern as a filename pattern, and returns a list of any actual files that match the pattern.


Private Member Functions

bool matches_substr (string::const_iterator pi, string::const_iterator pend, string::const_iterator ci, string::const_iterator cend) const
 The recursive implementation of matches().

bool matches_set (string::const_iterator &pi, string::const_iterator pend, char ch) const
 Called when an unescaped open square bracked is scanned, this is called with pi positioned after the opening square bracket, scans the set sequence, leaving pi positioned on the closing square bracket, and returns true if the indicated character matches the set of characters indicated, false otherwise.

int r_match_files (const Filename &prefix, const string &suffix, vector_string &results, const Filename &cwd)
 The recursive implementation of match_files().


Private Attributes

string _pattern


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


Constructor & Destructor Documentation

GlobPattern::GlobPattern const string &  pattern = string()  )  [inline]
 

Definition at line 31 of file globPattern.I.

References INLINE.

GlobPattern::GlobPattern const GlobPattern &  copy  )  [inline]
 

Definition at line 42 of file globPattern.I.

References _pattern, and INLINE.


Member Function Documentation

const string & GlobPattern::get_pattern  )  const [inline]
 

Returns the pattern string that the GlobPattern object matches.

Definition at line 83 of file globPattern.I.

References _pattern, and INLINE.

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

Referenced by match_files().

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

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

References _pattern, Filename::empty(), has_glob_characters(), Filename::is_local(), and size_t.

bool GlobPattern::matches const string &  candidate  )  const [inline]
 

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

Definition at line 98 of file globPattern.I.

Referenced by FindApproxPath::Component::matches(), NodePath::set_color(), and NodePath::set_transparency().

bool GlobPattern::matches_set string::const_iterator &  pi,
string::const_iterator  pend,
char  ch
const [private]
 

Called when an unescaped open square bracked is scanned, this is called with pi positioned after the opening square bracket, scans the set sequence, leaving pi positioned on the closing square bracket, and returns true if the indicated character matches the set of characters indicated, false otherwise.

Definition at line 298 of file globPattern.cxx.

Referenced by matches_substr().

bool GlobPattern::matches_substr string::const_iterator  pi,
string::const_iterator  pend,
string::const_iterator  ci,
string::const_iterator  cend
const [private]
 

The recursive implementation of matches().

This returns true if the pattern substring [pi, pend) matches the candidate substring [ci, cend), false otherwise.

Definition at line 211 of file globPattern.cxx.

References matches_set().

void GlobPattern::operator= const GlobPattern &  copy  )  [inline]
 

Definition at line 53 of file globPattern.I.

References _pattern, and INLINE.

void GlobPattern::output ostream &  out  )  const [inline]
 

Definition at line 111 of file globPattern.I.

int GlobPattern::r_match_files const Filename prefix,
const string &  suffix,
vector_string &  results,
const Filename cwd
[private]
 

The recursive implementation of match_files().

Definition at line 124 of file globPattern.cxx.

References _pattern.

void GlobPattern::set_pattern const string &  pattern  )  [inline]
 

Changes the pattern string that the GlobPattern object matches.

Definition at line 68 of file globPattern.I.


Member Data Documentation

string GlobPattern::_pattern [private]
 

Definition at line 87 of file globPattern.h.

Referenced by get_pattern(), GlobPattern(), match_files(), operator=(), and r_match_files().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:51:12 2003 for Panda by doxygen1.3