mirror of
https://github.com/SabreTools/SabreTools.Matching.git
synced 2026-02-13 05:35:35 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e596c7c2c1 | ||
|
|
910e963d13 | ||
|
|
751519fadb | ||
|
|
f86f565136 | ||
|
|
1ad45c6d59 | ||
|
|
38796776ee |
6
.github/workflows/build_nupkg.yml
vendored
6
.github/workflows/build_nupkg.yml
vendored
@@ -20,6 +20,12 @@ jobs:
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build library
|
||||
run: dotnet build
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
- name: Pack
|
||||
run: dotnet pack
|
||||
|
||||
5
.github/workflows/check_pr.yml
vendored
5
.github/workflows/check_pr.yml
vendored
@@ -14,4 +14,7 @@ jobs:
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
run: dotnet build
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
9
SabreTools.Matching/ExtensionAttribute.cs
Normal file
9
SabreTools.Matching/ExtensionAttribute.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
#if NET20
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
|
||||
internal sealed class ExtensionAttribute : Attribute {}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,11 +9,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// Indicates whether the specified array is null or has a length of zero
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool IsNullOrEmpty(Array? array)
|
||||
#else
|
||||
public static bool IsNullOrEmpty(this Array? array)
|
||||
#endif
|
||||
{
|
||||
return array == null || array.Length == 0;
|
||||
}
|
||||
@@ -21,11 +17,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// Find all positions of one array in another, if possible, if possible
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static List<int> FindAllPositions(byte[] stack, byte?[]? needle, int start = 0, int end = -1)
|
||||
#else
|
||||
public static List<int> FindAllPositions(this byte[] stack, byte?[]? needle, int start = 0, int end = -1)
|
||||
#endif
|
||||
{
|
||||
// Get the outgoing list
|
||||
List<int> positions = [];
|
||||
@@ -51,11 +43,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// Find the first position of one array in another, if possible
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool FirstPosition(byte[] stack, byte[]? needle, out int position, int start = 0, int end = -1)
|
||||
#else
|
||||
public static bool FirstPosition(this byte[] stack, byte[]? needle, out int position, int start = 0, int end = -1)
|
||||
#endif
|
||||
{
|
||||
// Convert the needle to a nullable byte array
|
||||
byte?[]? nullableNeedle = null;
|
||||
@@ -68,11 +56,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// Find the first position of one array in another, if possible
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool FirstPosition(byte[] stack, byte?[]? needle, out int position, int start = 0, int end = -1)
|
||||
#else
|
||||
public static bool FirstPosition(this byte[] stack, byte?[]? needle, out int position, int start = 0, int end = -1)
|
||||
#endif
|
||||
{
|
||||
var matcher = new ContentMatch(needle, start, end);
|
||||
position = matcher.Match(stack, false);
|
||||
@@ -82,11 +66,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// Find the last position of one array in another, if possible
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool LastPosition(byte[] stack, byte[]? needle, out int position, int start = 0, int end = -1)
|
||||
#else
|
||||
public static bool LastPosition(this byte[] stack, byte[]? needle, out int position, int start = 0, int end = -1)
|
||||
#endif
|
||||
{
|
||||
// Convert the needle to a nullable byte array
|
||||
byte?[]? nullableNeedle = null;
|
||||
@@ -99,11 +79,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// Find the last position of one array in another, if possible
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool LastPosition(byte[] stack, byte?[]? needle, out int position, int start = 0, int end = -1)
|
||||
#else
|
||||
public static bool LastPosition(this byte[] stack, byte?[]? needle, out int position, int start = 0, int end = -1)
|
||||
#endif
|
||||
{
|
||||
var matcher = new ContentMatch(needle, start, end);
|
||||
position = matcher.Match(stack, true);
|
||||
@@ -113,11 +89,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// See if a byte array starts with another
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool StartsWith(byte[] stack, byte[]? needle, bool exact = false)
|
||||
#else
|
||||
public static bool StartsWith(this byte[] stack, byte[]? needle, bool exact = false)
|
||||
#endif
|
||||
{
|
||||
// If we have any invalid inputs, we return false
|
||||
if (needle == null
|
||||
@@ -134,11 +106,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// See if a byte array starts with another
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool StartsWith(byte[] stack, byte?[]? needle, bool exact = false)
|
||||
#else
|
||||
public static bool StartsWith(this byte[] stack, byte?[]? needle, bool exact = false)
|
||||
#endif
|
||||
{
|
||||
// If we have any invalid inputs, we return false
|
||||
if (needle == null
|
||||
@@ -155,11 +123,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// See if a byte array ends with another
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool EndsWith(byte[] stack, byte[]? needle, bool exact = false)
|
||||
#else
|
||||
public static bool EndsWith(this byte[] stack, byte[]? needle, bool exact = false)
|
||||
#endif
|
||||
{
|
||||
// If we have any invalid inputs, we return false
|
||||
if (needle == null
|
||||
@@ -176,11 +140,7 @@ namespace SabreTools.Matching
|
||||
/// <summary>
|
||||
/// See if a byte array ends with another
|
||||
/// </summary>
|
||||
#if NET20
|
||||
public static bool EndsWith(byte[] stack, byte?[]? needle, bool exact = false)
|
||||
#else
|
||||
public static bool EndsWith(this byte[] stack, byte?[]? needle, bool exact = false)
|
||||
#endif
|
||||
{
|
||||
// If we have any invalid inputs, we return false
|
||||
if (needle == null
|
||||
|
||||
@@ -67,16 +67,7 @@ namespace SabreTools.Matching
|
||||
continue;
|
||||
|
||||
// Format the list of all positions found
|
||||
#if NET20 || NET35
|
||||
var positionStrs = new List<string>();
|
||||
foreach (int pos in positions)
|
||||
{
|
||||
positionStrs.Add(pos.ToString());
|
||||
}
|
||||
string positionsString = string.Join(", ", [.. positionStrs]);
|
||||
#else
|
||||
string positionsString = string.Join(", ", positions);
|
||||
#endif
|
||||
string positionsString = string.Join(", ", [.. positions.ConvertAll(p => p.ToString())]);
|
||||
|
||||
// If we there is no version method, just return the match name
|
||||
if (matcher.GetArrayVersion == null)
|
||||
@@ -162,16 +153,7 @@ namespace SabreTools.Matching
|
||||
continue;
|
||||
|
||||
// Format the list of all positions found
|
||||
#if NET20 || NET35
|
||||
var positionStrs = new List<string>();
|
||||
foreach (int pos in positions)
|
||||
{
|
||||
positionStrs.Add(pos.ToString());
|
||||
}
|
||||
string positionsString = string.Join(", ", [.. positionStrs]);
|
||||
#else
|
||||
string positionsString = string.Join(", ", positions);
|
||||
#endif
|
||||
string positionsString = string.Join(", ", [.. positions.ConvertAll(p => p.ToString())]);
|
||||
|
||||
// If we there is no version method, just return the match name
|
||||
if (matcher.GetStreamVersion == null)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
@@ -21,20 +21,6 @@
|
||||
<WarningsNotAsErrors>NU1903</WarningsNotAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR $(TargetFramework.StartsWith(`net4`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../README.md" Pack="true" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#! /bin/bash
|
||||
|
||||
# This batch file assumes the following:
|
||||
# - .NET 8.0 (or newer) SDK is installed and in PATH
|
||||
# - .NET 9.0 (or newer) SDK is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# This batch file assumes the following:
|
||||
# - .NET 8.0 (or newer) SDK is installed and in PATH
|
||||
# - .NET 9.0 (or newer) SDK is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
Reference in New Issue
Block a user