Skip to content

Commit 02bac8e

Browse files
committed
Merge branch 'release/2.0.0'
2 parents 8f8da1b + cea0b12 commit 02bac8e

33 files changed

+583
-295
lines changed

README.md

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,6 @@ The benchmarks use [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet)
2121
2222
```
2323

24-
## Parsing options.
25-
By default, when your glob pattern is parsed, `DotNet.Glob` will only parse literal characters which are valid for path / directory names.
26-
These are:
27-
28-
1. Any Letter or Digit
29-
2. '.', ' ', '!', '#', '-', ';', '=', '@', '~', '_', ':' };
30-
31-
This is optimised for matching against paths / directory strings.
32-
However starting in `1.6.4` you can override this behaviour so that you can match on arbitrary string containing other characters:
33-
34-
```
35-
// Overide the default options globally for all matche:
36-
GlobParseOptions.Default.AllowInvalidPathCharacters = true;
37-
DotNet.Globbing.Glob.Parse("\"Stuff*").IsMatch("\"Stuff"); // true;
38-
```
39-
40-
You can also just set this behaviour on a per match basis:
41-
42-
```
43-
var globParseOptions = new GlobParseOptions() { AllowInvalidPathCharacters = true };
44-
DotNet.Globbing.Glob.Parse("\"Stuff*", globParseOptions).IsMatch("\"Stuff"); // true;
45-
46-
```
47-
48-
4924
# Build a glob fluently
5025

5126
You can also use the `GlobBuilder` class if you wish to build up a glob using a fluent syntax.
@@ -91,9 +66,50 @@ In addition, DotNet Glob also supports:
9166
| `**` | matches any number of path / directory segments. When used must be the only contents of a segment. | /\*\*/some.\* | /foo/bar/bah/some.txt, /some.txt, or /foo/some.txt |
9267

9368

69+
# Advanced Usages
70+
71+
## Parsing options.
72+
By default, when your glob pattern is parsed, `DotNet.Glob` will only allow literals which are valid for path / directory names.
73+
These are:
74+
75+
1. Any Letter (A-Z, a-z) or Digit
76+
2. `.`, ` `, `!`, `#`, `-`, `;`, `=`, `@`, `~`, `_`, `:`
9477

78+
This is optimised for matching against paths / directory strings.
79+
However, introduced in version `1.6.4`, you can override this behaviour so that you can include arbitrary characters in your literals. For example, here is a pattern that matches the literal `"Stuff`:
80+
81+
```csharp
82+
// Overide the default options globally for all matche:
83+
GlobParseOptions.Default.Parsing.AllowInvalidPathCharacters = true;
84+
DotNet.Globbing.Glob.Parse("\"Stuff*").IsMatch("\"Stuff"); // true;
85+
```
86+
87+
You can also just set these options on a per glob pattern basis:
88+
89+
```csharp
90+
GlobOptions options = new GlobOptions();
91+
options.Parsing.AllowInvalidPathCharacters = allowInvalidPathCharcters;
92+
DotNet.Globbing.Glob.Parse("\"Stuff*", globParseOptions).IsMatch("\"Stuff"); // true;
93+
94+
```
95+
96+
## Case Sensitivity (Available as of version >= 2.0.0)
97+
98+
By default, evaluation is case-sensitive unless you specify otherwise.
99+
100+
```csharp
101+
GlobOptions options = new GlobOptions();
102+
options.Evaluation.CaseInsensitive = true;
103+
DotNet.Globbing.Glob.Parse("foo*", globParseOptions).IsMatch("FOo"); // true;
104+
105+
```
106+
107+
Setting CaseInsensitive has an impact on:
108+
109+
- Letter Ranges. Any letter range (i.e '[A-Z]') will now match both lower or upper case characters.
110+
- Character Lists. Any character list (i.e '[ABC]') will now match both lower or upper case characters.
111+
- Literals. Any literal (i.e 'foo') will now match both lower or upper case characters i.e `FoO` will match `foO` etc.
95112

96-
# Advanced Usages
97113

98114
## Match Generation
99115
Given a glob, you can generate random matches, or non matches, for that glob.
@@ -117,16 +133,3 @@ For example, given the glob pattern `/f?o/bar/**/*.txt` you could generate match
117133
}
118134
119135
```
120-
121-
122-
## Match Analysis
123-
124-
The `IsMatch` method just returns you a boolean. If you require more in-depth information about the match including which tokens were matched, or failed to match, you can do this:
125-
126-
```
127-
MatchInfo match = glob.Match(somestring);
128-
129-
```
130-
131-
You can then inspect the `MatchInfo` which holds all of those useful details.
132-

appveyor.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
version: 1.0.{build}
21
skip_tags: true
2+
image: Visual Studio 2017
3+
install:
4+
- choco install gitversion.portable -pre -y
5+
before_build:
6+
- ps: gitversion /l console /output buildserver
37
build:
4-
verbosity: minimal
8+
verbosity: detailed
59
environment:
610
NuGetOrgApiKey:
711
secure: u8JpW5kkti8pMi+ra2QcXTJPhkHCA8pkKSiiZOJbcS/vFVHNvF3W8qw1Fy2If6a7
812
PUBLIC_NUGET_FEED_NAME: nuget.org
913
PUBLIC_NUGET_FEED_SOURCE: https://www.nuget.org/
1014
BENCHMARKS: on
1115
build_script:
12-
- cmd: ./build.cmd
16+
- cmd: dotnet restore ./src/DotNetGlob.sln --disable-parallel
17+
- cmd: dotnet build ./src/DotNetGlob.sln --disable-parallel
18+
- cmd: dotnet pack ./src/DotNetGlob.sln --output ../../artifacts/
1319
test: off
1420
artifacts:
15-
- path: ./artifacts/*
16-
- path: ./**/*Artifacts/**/*.*
21+
- path: ./artifacts/*

build.cake

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//////////////////////////////////////////////////////////////////////
22
// TOOLS
33
//////////////////////////////////////////////////////////////////////
4-
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0-beta0012"
4+
#tool "nuget:https://ci.appveyor.com/nuget/gitversion-8nigugxjftrw?package=GitVersion.CommandLine&version=4.0.0-pullrequest1269-1542"
55
#tool "nuget:?package=GitReleaseNotes&version=0.7.0"
6-
#addin "nuget:?package=Cake.Git&version=0.15.0"
7-
#addin "nuget:?package=Cake.ExtendedNuGet&version=1.0.0.24"
86
#addin "nuget:?package=NuGet.Core&version=2.14.0"
9-
#addin "nuget:?package=MagicChunks&version=1.2.0.58"
107

118

129
//////////////////////////////////////////////////////////////////////
@@ -20,7 +17,6 @@ var configuration = Argument("configuration", "Release");
2017
///////////////////////////////////////////////////////////////////////////////
2118
var artifactsDir = "./artifacts";
2219
var projectName = "DotNet.Glob";
23-
var globalAssemblyFile = "./src/GlobalAssemblyInfo.cs";
2420
var projectToPackage = $"./src/{projectName}";
2521
var repoBranchName = "master";
2622
var benchMarksEnabled = EnvironmentVariable("BENCHMARKS") == "on";
@@ -54,8 +50,7 @@ Teardown(context =>
5450
Task("__Default")
5551
.IsDependentOn("__SetAppVeyorBuildNumber")
5652
.IsDependentOn("__Clean")
57-
.IsDependentOn("__Restore")
58-
.IsDependentOn("__UpdateAssemblyVersionInformation")
53+
.IsDependentOn("__Restore")
5954
.IsDependentOn("__Build")
6055
.IsDependentOn("__Test")
6156
.IsDependentOn("__Benchmarks")
@@ -90,28 +85,26 @@ Task("__SetAppVeyorBuildNumber")
9085
});
9186

9287
Task("__Restore")
93-
.Does(() => DotNetCoreRestore(solutionPath));
94-
95-
Task("__UpdateAssemblyVersionInformation")
96-
.WithCriteria(isContinuousIntegrationBuild)
97-
.Does(() =>
88+
.Does(() =>
9889
{
99-
GitVersion(new GitVersionSettings {
100-
UpdateAssemblyInfo = true,
101-
UpdateAssemblyInfoFilePath = globalAssemblyFile
102-
});
103-
104-
Information("AssemblyVersion -> {0}", gitVersionInfo.AssemblySemVer);
105-
Information("AssemblyFileVersion -> {0}", $"{gitVersionInfo.MajorMinorPatch}.0");
106-
Information("AssemblyInformationalVersion -> {0}", gitVersionInfo.InformationalVersion);
107-
});
90+
var settings = new DotNetCoreRestoreSettings
91+
{
92+
// ArgumentCustomization = args => args.Append("/p:PackageVersion=" + nugetVersion),
93+
DisableParallel = true
94+
};
95+
96+
DotNetCoreRestore(solutionPath, settings);
97+
98+
});
10899

109100
Task("__Build")
110101
.Does(() =>
111102
{
112103
DotNetCoreBuild(solutionPath, new DotNetCoreBuildSettings
113104
{
114-
Configuration = configuration
105+
Configuration = configuration,
106+
ArgumentCustomization = args => args.Append("--disable-parallel"),
107+
Verbosity = Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity.Detailed
115108
});
116109
});
117110

@@ -165,7 +158,7 @@ Task("__Pack")
165158
var versionarg = "/p:PackageVersion=" + nugetVersion;
166159
var settings = new DotNetCorePackSettings
167160
{
168-
Configuration = "Release",
161+
Configuration = configuration,
169162
OutputDirectory = $"{artifactsDir}",
170163
ArgumentCustomization = args=>args.Append(versionarg)
171164
};
@@ -175,12 +168,7 @@ Task("__Pack")
175168

176169
Task("__GenerateReleaseNotes")
177170
.Does(() =>
178-
{
179-
var settings = new DotNetCorePackSettings
180-
{
181-
Configuration = "Release",
182-
OutputDirectory = $"{artifactsDir}"
183-
};
171+
{
184172

185173
GitReleaseNotes($"{artifactsDir}/ReleaseNotes.md", new GitReleaseNotesSettings {
186174
WorkingDirectory = ".",

src/DotNet.Glob.Benchmarks/DotNetGlobBenchmarks.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,7 @@ public bool IsMatch_False()
6565
result ^= _glob.IsMatch(testString);
6666
}
6767
return result;
68-
}
69-
70-
[Benchmark]
71-
public List<MatchInfo> Match()
72-
{
73-
var results = new List<MatchInfo>(NumberOfMatches);
74-
for (int i = 0; i < NumberOfMatches; i++)
75-
{
76-
var testString = _testMatchingStringsList[i];
77-
results.Add(_glob.Match(testString));
78-
}
79-
return results;
80-
}
68+
}
8169

8270
}
8371
}

src/DotNet.Glob.Benchmarks/Utils/GlobToRegexFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void IGlobTokenVisitor.Visit(CharacterListToken token)
4646
{
4747
_stringBuilder.Append('^');
4848
}
49-
_stringBuilder.Append(Regex.Escape(new string(token.Characters.ToArray())));
49+
_stringBuilder.Append(Regex.Escape(new string(token.Characters)));
5050
_stringBuilder.Append(']');
5151

5252
}

src/DotNet.Glob.Tests/FormatterTests.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ public void Can_Format_Glob_Pattern()
1414
// build the following glob pattern using tokens:
1515
// /foo?\\*[abc][!1-3].txt
1616

17-
var glob = new Globbing.Glob(new PathSeperatorToken('/'),
18-
new LiteralToken("foo"),
19-
new AnyCharacterToken(),
20-
new PathSeperatorToken('\\'),
21-
new WildcardToken(),
22-
new CharacterListToken(new char[] { 'a', 'b', 'c' }, false),
23-
new WildcardDirectoryToken(new PathSeperatorToken('/'), new PathSeperatorToken('/')),
24-
new NumberRangeToken('1', '3', true),
25-
new LiteralToken(".txt"));
17+
var glob = new Globbing.Glob(
18+
new PathSeperatorToken('/'),
19+
new LiteralToken("foo"),
20+
new AnyCharacterToken(),
21+
new PathSeperatorToken('\\'),
22+
new WildcardToken(),
23+
new CharacterListToken(new char[] { 'a', 'b', 'c' }, false),
24+
new WildcardDirectoryToken(new PathSeperatorToken('/'), new PathSeperatorToken('/')),
25+
new NumberRangeToken('1', '3', true),
26+
new LiteralToken(".txt"));
2627

2728
// now format the glob.
2829
var sut = new GlobTokenFormatter();

src/DotNet.Glob.Tests/GlobTests.cs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ public class GlobTests
2121
[InlineData("C:\\name\\**", false, "C:\\name.ext", "C:\\name_longer.ext")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/29
2222
[InlineData("Bumpy/**/AssemblyInfo.cs", false, "Bumpy.Test/Properties/AssemblyInfo.cs")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/33
2323
[InlineData("C:\\sources\\x-y 1\\BIN\\DEBUG\\COMPILE\\**\\MSVC*120.DLL", false, "C:\\sources\\x-y 1\\BIN\\DEBUG\\COMPILE\\ANTLR3.RUNTIME.DLL")] // Attempted repro for https://github.com/dazinator/DotNet.Glob/issues/37
24+
[InlineData("literal1", false, "LITERAL1")] // Regression tests for https://github.com/dazinator/DotNet.Glob/issues/41
25+
[InlineData("*ral*", false, "LITERAL1")] // Regression tests for https://github.com/dazinator/DotNet.Glob/issues/41
26+
[InlineData("[list]s", false, "LS", "iS", "Is")] // Regression tests for https://github.com/dazinator/DotNet.Glob/issues/41
27+
[InlineData("range/[a-b][C-D]", false, "range/ac", "range/Ad", "range/BD")] // Regression tests for https://github.com/dazinator/DotNet.Glob/issues/41
2428
public void Does_Not_Match(string pattern, bool allowInvalidPathCharcters, params string[] testStrings)
2529
{
26-
GlobParseOptions options = new GlobParseOptions() { AllowInvalidPathCharacters = allowInvalidPathCharcters };
30+
GlobOptions options = new GlobOptions();
31+
options.Parsing.AllowInvalidPathCharacters = allowInvalidPathCharcters;
32+
2733
var glob = Globbing.Glob.Parse(pattern, options);
2834
foreach (var testString in testStrings)
2935
{
@@ -59,12 +65,14 @@ public void Does_Not_Match(string pattern, bool allowInvalidPathCharcters, param
5965
[InlineData("Stuff, *", "Stuff, x")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/31
6066
[InlineData("\"Stuff*", "\"Stuff")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/32
6167
[InlineData("path/**/somefile.txt", "path//somefile.txt")]
62-
[InlineData("**/app*.js", "dist/app.js", "dist/app.a72ka8234.js")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/34
68+
[InlineData("**/app*.js", "dist/app.js", "dist/app.a72ka8234.js")] // Regression Test for https://github.com/dazinator/DotNet.Glob/issues/34#
6369
public void IsMatch(string pattern, params string[] testStrings)
6470
{
6571

66-
GlobParseOptions.Default.AllowInvalidPathCharacters = true;
67-
var glob = Globbing.Glob.Parse(pattern);
72+
GlobOptions options = new GlobOptions();
73+
options.Parsing.AllowInvalidPathCharacters = true;
74+
75+
var glob = Globbing.Glob.Parse(pattern, options);
6876
foreach (var testString in testStrings)
6977
{
7078
var match = glob.IsMatch(testString);
@@ -73,6 +81,25 @@ public void IsMatch(string pattern, params string[] testStrings)
7381
}
7482
}
7583

84+
// Regression tests for https://github.com/dazinator/DotNet.Glob/issues/41
85+
[Theory]
86+
[InlineData("literal1", "LITERAL1", "literal1")]
87+
[InlineData("*ral*", "LITERAL1", "literal1")]
88+
[InlineData("[list]s", "LS", "ls", "iS", "Is")]
89+
[InlineData("range/[a-b][C-D]", "range/ac", "range/Ad", "range/bC", "range/BD")]
90+
public void IsMatchCaseInsensitive(string pattern, params string[] testStrings)
91+
{
92+
GlobOptions options = new GlobOptions();
93+
options.Parsing.AllowInvalidPathCharacters = true;
94+
options.Evaluation.CaseInsensitive = true;
95+
96+
var glob = Globbing.Glob.Parse(pattern, options);
97+
foreach (var testString in testStrings)
98+
{
99+
var match = glob.IsMatch(testString);
100+
Assert.True(match);
101+
}
102+
}
76103

77104
[Fact]
78105
public void To_String_Returns_Pattern()
@@ -82,11 +109,5 @@ public void To_String_Returns_Pattern()
82109
var resultPattern = glob.ToString();
83110
Assert.Equal(pattern, resultPattern);
84111
}
85-
86-
87-
88-
89-
90-
91112
}
92113
}

src/DotNet.Glob/DotNet.Glob.csproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
<TargetFrameworks>netstandard1.1;net45;net46;net4</TargetFrameworks>
55
<AssemblyName>DotNet.Glob</AssemblyName>
66
<OutputType>Library</OutputType>
7-
<PackageId>DotNet.Glob</PackageId>
8-
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
9-
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
10-
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
7+
<PackageId>DotNet.Glob</PackageId>
118
<PackageProjectUrl>https://github.com/dazinator/DotNet.Glob</PackageProjectUrl>
129
<Description>A fast globbing library for .NET applications, including .net core. Doesn't use Regex.</Description>
1310
<Authors>Darrell Tunnell &lt;darrell.tunnell@googlemail.com&gt;</Authors>
1411
<PackageLicenseUrl>https://github.com/dazinator/DotNet.Glob/blob/master/LICENSE</PackageLicenseUrl>
1512
<PackageTags>glob;globbing;dotnet;pattern;match</PackageTags>
16-
<PackageReleaseNotes>This is a hotfix release to support tilde characters (~), thanks goes to @ming4883</PackageReleaseNotes>
13+
<PackageReleaseNotes>New features and fixes. See README in Github Repo.</PackageReleaseNotes>
1714
<RootNamespace>DotNet.Glob</RootNamespace>
1815
</PropertyGroup>
16+
17+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net4' ">
18+
<DefineConstants>NET40</DefineConstants>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<PackageReference Include="GitVersionTask" Version="4.0.0-pullrequest1269-1542">
23+
<PrivateAssets>all</PrivateAssets>
24+
</PackageReference>
25+
</ItemGroup>
26+
1927
</Project>

src/DotNet.Glob/Evaluation/AnyCharacterTokenEvaluator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public AnyCharacterTokenEvaluator(AnyCharacterToken token)
1111
{
1212
_token = token;
1313
}
14+
1415
public bool IsMatch(string allChars, int currentPosition, out int newPosition)
1516
{
1617
newPosition = currentPosition + 1;

0 commit comments

Comments
 (0)