The OpenD Programming Language

globMatch

Matches a pattern against a path.

Some characters of pattern have a special meaning (they are meta-characters) and can't be escaped. These are:

*Matches 0 or more instances of any character.
?Matches exactly one instance of any character.
[chars]Matches one instance of any character that appears between the brackets.
[!chars]Matches one instance of any character that does not appear between the brackets after the exclamation mark.
{string1,string2,…}Matches either of the specified strings.

Individual characters are compared using filenameCharCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCharCmp documentation for details.

Note that directory separators and dots don't stop a meta-character from matching further portions of the path.

@safe pure nothrow
bool
globMatch
(
Range path
,
const(C)[] pattern
)
if (
is(immutable C == immutable ElementEncodingType!Range)
)

Parameters

cs

Whether the matching should be case-sensitive

path Range

The path to be matched against

pattern const(C)[]

The glob pattern

Return Value

Type: bool

true if pattern matches path, false otherwise.

Examples

assert(globMatch("foo.bar", "*"));
assert(globMatch("foo.bar", "*.*"));
assert(globMatch(`foo/foo\bar`, "f*b*r"));
assert(globMatch("foo.bar", "f???bar"));
assert(globMatch("foo.bar", "[fg]???bar"));
assert(globMatch("foo.bar", "[!gh]*bar"));
assert(globMatch("bar.fooz", "bar.{foo,bif}z"));
assert(globMatch("bar.bifz", "bar.{foo,bif}z"));

version (Windows)
{
    // Same as calling globMatch!(CaseSensitive.no)(path, pattern)
    assert(globMatch("foo", "Foo"));
    assert(globMatch("Goo.bar", "[fg]???bar"));
}
version (linux)
{
    // Same as calling globMatch!(CaseSensitive.yes)(path, pattern)
    assert(!globMatch("foo", "Foo"));
    assert(!globMatch("Goo.bar", "[fg]???bar"));
}

See Also

Meta