Class GlobPattern
Implements a very simple glob matcher inspired by the GitHub .gitignore
patterns
described here.
Namespace: Neon.Common
Assembly: Neon.Common.dll
Syntax
public class GlobPattern
Remarks
The current implementation is somewhat limited compared to that for .gitignore
:
- Only "*" and "**" wildcard chacacters are allowed. "!" and "[..]" are not recognized.
- "*" matches anything except for "/".
- "**" matches zero or more directories.
note
This class works only for file paths using either Linux style forward slashes (/) or Windows style backslashes by converting any backslashes to forward slashes in IsMatch(string) before performing the match. The Regex handles forward slash matching only.
Properties
Regex
Returns the Regex that can be used to match strings against the glob.
Declaration
public Regex Regex { get; }
Property Value
Type | Description |
---|---|
Regex |
RegexPattern
Returns the glob as a regular expression string.
Declaration
public string RegexPattern { get; }
Property Value
Type | Description |
---|---|
string |
Methods
IsMatch(string)
Matches a string against the glob.
Declaration
public bool IsMatch(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The value to be matched. |
Returns
Type | Description |
---|---|
bool |
|
Parse(string, bool)
Parses a GlobPattern from a pattern string.
Declaration
public static GlobPattern Parse(string pattern, bool caseInsensitive = false)
Parameters
Type | Name | Description |
---|---|---|
string | pattern | The pattern. |
bool | caseInsensitive | Optionally uses case insensitive that matching. |
Returns
Type | Description |
---|---|
GlobPattern | The created GlobPattern. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the pattern is |
FormatException | Thrown if the pattern is invalid. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |
Overrides
TryParse(string, out GlobPattern)
Attempts to parse a case insensitive GlobPattern.
Declaration
public static bool TryParse(string pattern, out GlobPattern globPattern)
Parameters
Type | Name | Description |
---|---|---|
string | pattern | The pattern string. |
GlobPattern | globPattern | Returns as the parsed GlobPattern. |
Returns
Type | Description |
---|---|
bool |
|
TryParse(string, bool, out GlobPattern)
Attempts to parse a GlobPattern where case sensitivity can be controlled.
Declaration
public static bool TryParse(string pattern, bool caseInsenstive, out GlobPattern globPattern)
Parameters
Type | Name | Description |
---|---|---|
string | pattern | The pattern string. |
bool | caseInsenstive | Controls whether the mactching is case insensitive. |
GlobPattern | globPattern | Returns as the parsed GlobPattern. |
Returns
Type | Description |
---|---|
bool |
|