From f4e61993ad7320393ff4888ba85f77728b89a578 Mon Sep 17 00:00:00 2001 From: dragon <66683631+dragon7307@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:45:02 +0100 Subject: [PATCH 01/10] Update publish.yml --- .github/workflows/publish.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 392f778..ee62bc3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,10 @@ name: .NET on: push: branches: [ "main" ] + paths: + - '**.cs' + - '**.csproj' + - '**.sln' permissions: contents: write From 3868b3c98d681a9d8d6ad5233ddb086b60a2fb2e Mon Sep 17 00:00:00 2001 From: dragon <66683631+dragon7307@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:46:32 +0100 Subject: [PATCH 02/10] Update format.yml --- .github/workflows/format.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 5e2565b..931817e 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -4,6 +4,8 @@ name: Format on: push: branches: [ "dev" ] + paths: + - '**.cs' permissions: contents: write From 0d1509f3c652e9c9da531dbf94914d8f05543715 Mon Sep 17 00:00:00 2001 From: dragon <66683631+dragon7307@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:49:17 +0100 Subject: [PATCH 03/10] Update test.yml --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5a1fbf..224a98b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,7 @@ on: paths: - '**.cs' - '**.csproj' + - '**.sln' jobs: test: From 7f17c1535a91a9655cfd8b08bf37bda7f209108b Mon Sep 17 00:00:00 2001 From: dragon <66683631+dragon7307@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:49:42 +0100 Subject: [PATCH 04/10] Update test.yml From 6d0ab7917067e86881c6bb4af80a2694c92d04d5 Mon Sep 17 00:00:00 2001 From: dragon7307 Date: Tue, 29 Oct 2024 10:42:32 +0100 Subject: [PATCH 05/10] blocked compilation on .Net 9. --- src/SpanExtensions.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SpanExtensions.csproj b/src/SpanExtensions.csproj index 323fd81..112e619 100644 --- a/src/SpanExtensions.csproj +++ b/src/SpanExtensions.csproj @@ -27,6 +27,10 @@ README.md icon.png + + + + portable From 3933e24a9bc317e56655ad33c492683294dde255 Mon Sep 17 00:00:00 2001 From: dragon7307 Date: Tue, 29 Oct 2024 11:32:01 +0100 Subject: [PATCH 06/10] added Count overloads for pre net8.0 versions. --- src/Extensions/ReadOnlySpan/Linq/Count.cs | 43 +++++++++++++++++++++++ src/Extensions/Span/Linq/Count.cs | 24 +++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/Extensions/ReadOnlySpan/Linq/Count.cs b/src/Extensions/ReadOnlySpan/Linq/Count.cs index 175110a..534d95d 100644 --- a/src/Extensions/ReadOnlySpan/Linq/Count.cs +++ b/src/Extensions/ReadOnlySpan/Linq/Count.cs @@ -47,5 +47,48 @@ public static int Count(this ReadOnlySpan source, Predicate predicate) return count; } + +#if !NET8_0_OR_GREATER + /// Counts the number of times the specified occurs in the . + /// The element type of the span. + /// A whose elements are to be counted. + /// The value for which to search. + /// The number of elements eqaul to in . + /// The number of elements in is larger than . + public static int Count(this ReadOnlySpan source, T value) where T : IEquatable + { + int count = 0; + + foreach(var item in source) + { + if(item.Equals(value)) + { + count++; + } + } + + return count; + } + + /// Counts the number of times the specified occurs in the . + /// The element type of the span. + /// A whose elements are to be counted. + /// The value for which to search. + /// The number of elements eqaul to in . + /// The number of elements in is larger than . + public static int Count(this ReadOnlySpan source, ReadOnlySpan value) where T : IEquatable + { + int count = 0; + int current = 0; + + while((current = source.IndexOf(value)) != -1) + { + source = source.Slice(current + value.Length); + count++; + } + + return count; + } +#endif } } \ No newline at end of file diff --git a/src/Extensions/Span/Linq/Count.cs b/src/Extensions/Span/Linq/Count.cs index 34cf62d..8909854 100644 --- a/src/Extensions/Span/Linq/Count.cs +++ b/src/Extensions/Span/Linq/Count.cs @@ -29,5 +29,29 @@ public static int Count(this Span source, Predicate predicate) { return ReadOnlySpanExtensions.Count(source, predicate); } + +#if !NET8_0_OR_GREATER + /// Counts the number of times the specified occurs in the . + /// The element type of the span. + /// A whose elements are to be counted. + /// The value for which to search. + /// The number of elements eqaul to in . + /// The number of elements in is larger than . + public static int Count(this Span source, T value) where T : IEquatable + { + return ReadOnlySpanExtensions.Count(source, value); + } + + /// Counts the number of times the specified occurs in the . + /// The element type of the span. + /// A whose elements are to be counted. + /// The value for which to search. + /// The number of elements eqaul to in . + /// The number of elements in is larger than . + public static int Count(this Span source, ReadOnlySpan value) where T : IEquatable + { + return ReadOnlySpanExtensions.Count(source, value); + } +#endif } } \ No newline at end of file From b37d2cbb336053c9a1ed70fae5f032e05c4e22b2 Mon Sep 17 00:00:00 2001 From: dragon7307 Date: Tue, 29 Oct 2024 11:36:45 +0100 Subject: [PATCH 07/10] bumped version --- src/SpanExtensions.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SpanExtensions.csproj b/src/SpanExtensions.csproj index 112e619..370531d 100644 --- a/src/SpanExtensions.csproj +++ b/src/SpanExtensions.csproj @@ -22,7 +22,7 @@ Span;Performance;Extension;String https://github.com/draconware-dev/SpanExtensions.Net/blob/main/Changelog.md LICENSE - 1.4.1 + 1.4.2 SpanExtensions.Net README.md icon.png From ed98dfa5042e17d8e65c40efd31fb9b23a3dd3ed Mon Sep 17 00:00:00 2001 From: dragon <66683631+dragon7307@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:46:01 +0100 Subject: [PATCH 08/10] Update Changelog.md --- Changelog.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Changelog.md b/Changelog.md index 5d36bad..afccc62 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres not (yet) to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.4.2] - 2024-10-29 + +### Added + +- `(Readonly-)Span.Count(...)` overloads to all versions before .Net 8 matching these introduced in .Net 8. + +### Changed + +- blocked compilation on .Net 9 due to known incompatibilities, which are to be resolved in version 1.5. + ## [1.4.1] - 2024-9-9 ### Fixed From a3d066664fbf844ca73efbec9b0f05aa8acf0700 Mon Sep 17 00:00:00 2001 From: dragon <66683631+dragon7307@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:58:28 +0100 Subject: [PATCH 09/10] added badges --- .github/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/README.md b/.github/README.md index d3811e8..ef0d31e 100644 --- a/.github/README.md +++ b/.github/README.md @@ -1,6 +1,8 @@ # SpanExtensions -[![NuGet Badge](https://buildstats.info/nuget/SpanExtensions.Net)](https://www.nuget.org/packages/SpanExtensions.Net) +![NuGet Version](https://img.shields.io/nuget/v/SpanExtensions.Net) +![NuGet Downloads](https://img.shields.io/nuget/dt/SpanExtensions.Net) +![GitHub License](https://img.shields.io/github/license/draconware-dev/SpanExtensions.Net) ## About **`ReadonlySpan`** and **`Span`** are great Types in _C#_, but unfortunately working with them can sometimes be sort of a hassle and some use cases seem straight up impossible, even though they are not. From 1c114437e4d3e716fe87bc56912b72ab88f69e95 Mon Sep 17 00:00:00 2001 From: dragon <66683631+dragon7307@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:03:07 +0100 Subject: [PATCH 10/10] linked badges properly --- .github/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/README.md b/.github/README.md index ef0d31e..014f0cb 100644 --- a/.github/README.md +++ b/.github/README.md @@ -1,8 +1,8 @@ # SpanExtensions -![NuGet Version](https://img.shields.io/nuget/v/SpanExtensions.Net) -![NuGet Downloads](https://img.shields.io/nuget/dt/SpanExtensions.Net) -![GitHub License](https://img.shields.io/github/license/draconware-dev/SpanExtensions.Net) +[![NuGet Version](https://img.shields.io/nuget/v/SpanExtensions.Net)](https://www.nuget.org/packages/SpanExtensions.Net) +[![NuGet Downloads](https://img.shields.io/nuget/dt/SpanExtensions.Net)](https://www.nuget.org/packages/SpanExtensions.Net) +[![GitHub License](https://img.shields.io/github/license/draconware-dev/SpanExtensions.Net)](https://github.com/draconware-dev/SpanExtensions.Net/blob/main/LICENSE) ## About **`ReadonlySpan`** and **`Span`** are great Types in _C#_, but unfortunately working with them can sometimes be sort of a hassle and some use cases seem straight up impossible, even though they are not.