LLVM 20.0.0git
|
This class implements a glob pattern matcher similar to the one found in bash, but with some key differences. More...
#include "llvm/Support/GlobPattern.h"
Public Member Functions | |
bool | match (StringRef S) const |
bool | isTrivialMatchAll () const |
Static Public Member Functions | |
static Expected< GlobPattern > | create (StringRef Pat, std::optional< size_t > MaxSubPatterns={}) |
This class implements a glob pattern matcher similar to the one found in bash, but with some key differences.
Namely, that "*"
matches all characters and does not exclude path separators.
"?"
matches a single character."*"
matches zero or more characters."[<chars>]"
matches one character in the bracket. Character ranges, e.g., "[a-z]"
, and negative sets via "[^ab]"
or "[!ab]"
are also supported."{<glob>,...}"
matches one of the globs in the list. Nested brace expansions are not supported. If MaxSubPatterns
is empty then brace expansions are not supported and characters "{,}"
are treated as literals."\" escapes the next character so it is treated as a literal.
Some known edge cases are:
* \p "
]" is allowed as the first character in a character class, i.e.,
\p "[]]" is valid and matches the literal \p "]".
* The empty character class, i.e., \p "[]", is invalid.
* Empty or singleton brace expansions, e.g., \p "{}", \p "{a}", are invalid.
* \p "}" and \p "," that are not inside a brace expansion are taken as
literals, e.g., \p ",}" is valid but \p "{" is not.
For example, \p "*[/\]foo.{c,cpp}" will match (unix or windows) paths to
all files named \p "foo.c" or \p "foo.cpp". Definition at line 51 of file GlobPattern.h.
|
static |
Pat | the pattern to match against |
MaxSubPatterns | if provided limit the number of allowed subpatterns created from expanding braces otherwise disable brace expansion |
Definition at line 136 of file GlobPattern.cpp.
References llvm::StringRef::find_first_of(), parseBraceExpansions(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::StringRef::substr().
Referenced by llvm::objcopy::NameOrPattern::create(), llvm::ifs::filterIFSSyms(), and llvm::SpecialCaseList::Matcher::insert().
|
inline |
Definition at line 64 of file GlobPattern.h.
References llvm::StringRef::empty(), and llvm::SmallVectorBase< Size_T >::size().
true
if S
matches this glob pattern Definition at line 193 of file GlobPattern.cpp.
References llvm::StringRef::consume_front(), llvm::SmallVectorBase< Size_T >::empty(), and llvm::StringRef::empty().