12 Commits
1.5.2 ... main

Author SHA1 Message Date
Matt Nadareski
77280e8da1 Update notice 2025-09-24 08:12:19 -04:00
Matt Nadareski
3d05135a81 Add notice 2025-09-23 11:00:46 -04:00
Matt Nadareski
b2dfffbc92 There 2025-09-10 21:52:47 -04:00
Matt Nadareski
036ee4246b Bump version 2025-07-23 10:13:30 -04:00
Matt Nadareski
8e3bcb9015 Update nuget packages 2025-07-23 10:11:08 -04:00
Matt Nadareski
8b1ac53ccf Remove now-unnecessary prefixes 2025-07-23 10:08:53 -04:00
Matt Nadareski
0c9e255d48 Split tests to match classes 2025-07-23 10:08:30 -04:00
Matt Nadareski
1227488572 Be consistent about end-of-file newlines 2025-07-23 10:07:10 -04:00
Matt Nadareski
bd878cf1a1 Fix nullability issue in MatchUtil 2025-07-23 10:04:43 -04:00
Matt Nadareski
b436b64c3a Be consistent about end-of-file newlines 2025-07-23 10:00:50 -04:00
Matt Nadareski
6f6d071a79 Add summaries to IMatch 2025-07-23 09:58:46 -04:00
Matt Nadareski
69130a6e9f Add .NET Standard 2.0 and 2.1 2025-07-23 09:52:35 -04:00
25 changed files with 98 additions and 65 deletions

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
Copyright (c) 2018-2025 Matt Nadareski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -2,6 +2,8 @@
[![Build and Test](https://github.com/SabreTools/SabreTools.Matching/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/SabreTools/SabreTools.Matching/actions/workflows/build_and_test.yml)
**NOTICE:** This library has been deprecated. All functionality formerly in this library is in [SabreTools.IO](https://github.com/SabreTools/SabreTools.IO) as of version 1.7.5.
This library comprises of code to perform search operations on both byte arrays and streams. There is also an implementation that allows searching for strings in a set of strings, usually used in the context of directory contents.
Find the link to the Nuget package [here](https://www.nuget.org/packages/SabreTools.Matching).

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Matching.Test.Compare
public class NaturalComparerTests
{
[Fact]
public void NaturalComparer_ListSort_Numeric()
public void ListSort_Numeric()
{
// Setup arrays
string[] sortable = ["0", "100", "5", "2", "1000"];
@@ -22,7 +22,7 @@ namespace SabreTools.Matching.Test.Compare
}
[Fact]
public void NaturalComparer_ListSort_Mixed()
public void ListSort_Mixed()
{
// Setup arrays
string[] sortable = ["b3b", "c", "b", "a", "a1"];
@@ -34,33 +34,5 @@ namespace SabreTools.Matching.Test.Compare
// Check the output
Assert.True(sortable.SequenceEqual(expected));
}
[Fact]
public void NaturalReversedComparer_ListSort_Numeric()
{
// Setup arrays
string[] sortable = ["0", "100", "5", "2", "1000"];
string[] expected = ["1000", "100", "5", "2", "0"];
// Run sorting on array
Array.Sort(sortable, new NaturalReversedComparer());
// Check the output
Assert.True(sortable.SequenceEqual(expected));
}
[Fact]
public void NaturalReversedComparer_ListSort_Mixed()
{
// Setup arrays
string[] sortable = ["b3b", "c", "b", "a", "a1"];
string[] expected = ["c", "b3b", "b", "a1", "a"];
// Run sorting on array
Array.Sort(sortable, new NaturalReversedComparer());
// Check the output
Assert.True(sortable.SequenceEqual(expected));
}
}
}
}

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Matching.Test.Compare
int actual = NaturalComparerUtil.ComparePaths(null, null);
Assert.Equal(0, actual);
}
[Fact]
public void CompareNumeric_SingleNull_Ordered()
{
@@ -63,4 +63,4 @@ namespace SabreTools.Matching.Test.Compare
Assert.Equal(-1, actual);
}
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Linq;
using SabreTools.Matching.Compare;
using Xunit;
namespace SabreTools.Matching.Test.Compare
{
public class NaturalReversedComparerTests
{
[Fact]
public void ListSort_Numeric()
{
// Setup arrays
string[] sortable = ["0", "100", "5", "2", "1000"];
string[] expected = ["1000", "100", "5", "2", "0"];
// Run sorting on array
Array.Sort(sortable, new NaturalReversedComparer());
// Check the output
Assert.True(sortable.SequenceEqual(expected));
}
[Fact]
public void ListSort_Mixed()
{
// Setup arrays
string[] sortable = ["b3b", "c", "b", "a", "a1"];
string[] expected = ["c", "b3b", "b", "a1", "a"];
// Run sorting on array
Array.Sort(sortable, new NaturalReversedComparer());
// Check the output
Assert.True(sortable.SequenceEqual(expected));
}
}
}

View File

@@ -199,4 +199,4 @@ namespace SabreTools.Matching.Test.Content
#endregion
}
}
}

View File

@@ -268,4 +268,4 @@ namespace SabreTools.Matching.Test.Content
#endregion
}
}
}

View File

@@ -393,4 +393,4 @@ namespace SabreTools.Matching.Test
#endregion
}
}
}

View File

@@ -321,4 +321,4 @@ namespace SabreTools.Matching.Test
#endregion
}
}
}

View File

@@ -19,4 +19,4 @@ namespace SabreTools.Matching.Test.Paths
Assert.Equal(expected, fpm.Needle);
}
}
}
}

View File

@@ -183,4 +183,4 @@ namespace SabreTools.Matching.Test.Paths
#endregion
}
}
}

View File

@@ -290,4 +290,4 @@ namespace SabreTools.Matching.Test.Paths
#endregion
}
}
}

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
<NoWarn>NU1903</NoWarn>
@@ -10,13 +10,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View File

@@ -329,4 +329,4 @@ namespace SabreTools.Matching.Content
#endregion
}
}
}

View File

@@ -235,4 +235,4 @@ namespace SabreTools.Matching.Content
#endregion
}
}
}

View File

@@ -28,4 +28,4 @@ namespace SabreTools.Matching
/// <param name="positions">List of positions in the Stream that were matched</param>
/// <returns>Version string on success, null on failure</returns>
public delegate string? GetStreamVersion(string path, Stream? content, List<int> positions);
}
}

View File

@@ -6,4 +6,4 @@ namespace System.Runtime.CompilerServices
internal sealed class ExtensionAttribute : Attribute {}
}
#endif
#endif

View File

@@ -223,4 +223,4 @@ namespace SabreTools.Matching
return FirstPosition(stack, needle, start: stack.Length - needle.Length) > -1;
}
}
}
}

View File

@@ -1,7 +1,13 @@
namespace SabreTools.Matching
{
/// <summary>
/// Represents a matcher for a particular type
/// </summary>
public interface IMatch<T>
{
/// <summary>
/// Nullable typed data to be matched
/// </summary>
T? Needle { get; }
}
}

View File

@@ -17,4 +17,4 @@ namespace SabreTools.Matching
/// </summary>
public string SetName { get; }
}
}
}

View File

@@ -98,7 +98,7 @@ namespace SabreTools.Matching
var version = matcher.GetArrayVersion(file, stack, positions);
if (version == null)
continue;
// Trim and add the version
version = version.Trim();
if (version.Length > 0)
@@ -212,7 +212,7 @@ namespace SabreTools.Matching
var version = matcher.GetStreamVersion(file, stack, positions);
if (version == null)
continue;
// Trim and add the version
version = version.Trim();
if (version.Length > 0)
@@ -314,12 +314,20 @@ namespace SabreTools.Matching
foreach (var matcher in matchSets)
{
// Determine if the matcher passes
List<string> matches = any
? [matcher.MatchesAny(stack)]
: matcher.MatchesAll(stack);
List<string> matches = [];
if (any)
{
string? anyMatch = matcher.MatchesAny(stack);
if (anyMatch != null)
matches = [anyMatch];
}
else
{
matches = matcher.MatchesAll(stack);
}
// If we don't have a pass, just continue
if (matches.Count == 0 || matches[0] == null)
if (matches.Count == 0)
continue;
// Build the output string
@@ -333,7 +341,7 @@ namespace SabreTools.Matching
var version = matcher.GetVersion(matches[0], stack);
if (version == null)
continue;
// Trim and add the version
version = version.Trim();
if (version.Length > 0)
@@ -353,4 +361,4 @@ namespace SabreTools.Matching
#endregion
}
}
}

View File

@@ -15,4 +15,4 @@ namespace SabreTools.Matching.Paths
public FilePathMatch(string needle, bool matchCase = false)
: base($"{Path.DirectorySeparatorChar}{needle}", matchCase, true) { }
}
}
}

View File

@@ -89,4 +89,4 @@ namespace SabreTools.Matching.Paths
#endregion
}
}
}

View File

@@ -152,4 +152,4 @@ namespace SabreTools.Matching.Paths
#endregion
}
}
}

View File

@@ -2,14 +2,14 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<IncludeSymbols>true</IncludeSymbols>
<LangVersion>latest</LangVersion>
<NoWarn>NU1903</NoWarn>
<Nullable>enable</Nullable>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.5.2</Version>
<Version>1.6.0</Version>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>