Skip to content

Commit 99d8486

Browse files
authored
Version 1.5.1 (#26)
updated to version 1.5.1!!!
1 parent 2c50b0e commit 99d8486

File tree

5 files changed

+101
-73
lines changed

5 files changed

+101
-73
lines changed

Changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres not (yet) to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.5.1] - 2024-12-14
9+
10+
### Fixed
11+
12+
- incorrect ranges returned by the range-based Split method for versions prior to .Net 9.
13+
14+
### Changed
15+
16+
- moved MemoryExtensions containing range-based Split method for versions prior to .Net 9 from `System` to `SpanExtensions`.
17+
- grammatical issues in some documentation comments.
18+
819
## [1.5] - 2024-11-12
920

1021
### Added

src/Enumerators/System/SpanSplitEnumerator.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System.Buffers;
1+
using System;
2+
using System.Buffers;
23
using System.Diagnostics;
34
using System.Runtime.CompilerServices;
45

56
#if !NET9_0_OR_GREATER
67

7-
namespace System
8+
namespace SpanExtensions
89
{
910
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1011
public static partial class MemoryExtensions
@@ -23,27 +24,35 @@ public static partial class MemoryExtensions
2324
readonly SearchValues<T> SearchValues = null!;
2425
#endif
2526

27+
int currentStartIndex;
28+
int currentEndIndex;
29+
int nextStartIndex;
2630
/// <summary>
2731
/// Gets the current element of the enumeration.
2832
/// </summary>
29-
/// <returns>Returns a <see cref="Range"/> instance that indicates the bounds of the current element withing the source span.</returns>
30-
public Range Current { get; internal set; }
33+
/// <returns>Returns a <see cref="Range"/> instance that indicates the bounds of the current element within the source span.</returns>
34+
public readonly Range Current => new Range(currentStartIndex, currentEndIndex);
3135

3236
internal SpanSplitEnumerator(ReadOnlySpan<T> source, T delimiter)
3337
{
3438
Span = source;
3539
Delimiter = delimiter;
36-
Current = new Range(0, 0);
3740
DelimiterSpan = default;
3841
mode = SpanSplitEnumeratorMode.Delimiter;
42+
currentStartIndex = 0;
43+
currentEndIndex = 0;
44+
nextStartIndex = 0;
3945
}
46+
4047
internal SpanSplitEnumerator(ReadOnlySpan<T> source, ReadOnlySpan<T> delimiter, SpanSplitEnumeratorMode mode)
4148
{
4249
Span = source;
4350
DelimiterSpan = delimiter;
44-
Current = new Range(0, 0);
4551
Delimiter = default!;
4652
this.mode = mode;
53+
currentStartIndex = 0;
54+
currentEndIndex = 0;
55+
nextStartIndex = 0;
4756
}
4857

4958
#if NET8_0
@@ -52,9 +61,11 @@ internal SpanSplitEnumerator(ReadOnlySpan<T> source, SearchValues<T> searchValue
5261
Span = source;
5362
Delimiter = default!;
5463
SearchValues = searchValues;
55-
Current = new Range(0, 0);
5664
DelimiterSpan = default;
5765
mode = SpanSplitEnumeratorMode.Delimiter;
66+
currentStartIndex = 0;
67+
currentEndIndex = 0;
68+
nextStartIndex = 0;
5869
}
5970
#endif
6071
/// <summary>
@@ -77,17 +88,17 @@ public bool MoveNext()
7788
switch(mode)
7889
{
7990
case SpanSplitEnumeratorMode.Delimiter:
80-
index = Span[Current.Start..].IndexOf(Delimiter);
91+
index = Span[nextStartIndex..].IndexOf(Delimiter);
8192
length = 1;
8293
break;
8394

8495
case SpanSplitEnumeratorMode.Any:
85-
index = Span[Current.Start..].IndexOfAny(DelimiterSpan);
96+
index = Span[nextStartIndex..].IndexOfAny(DelimiterSpan);
8697
length = 1;
8798
break;
8899

89100
case SpanSplitEnumeratorMode.Sequence:
90-
index = Span[Current.Start..].IndexOf(DelimiterSpan);
101+
index = Span[nextStartIndex..].IndexOf(DelimiterSpan);
91102
length = DelimiterSpan.Length;
92103
break;
93104

@@ -98,23 +109,28 @@ public bool MoveNext()
98109

99110
#if NET8_0
100111
case SpanSplitEnumeratorMode.SearchValues:
101-
index = Span[Current.Start..].IndexOfAny(SearchValues);
112+
index = Span[nextStartIndex..].IndexOfAny(SearchValues);
102113
length = 1;
103114
break;
104115
#endif
105116
default:
106117
return false;
107118
}
108119

120+
currentStartIndex = nextStartIndex;
121+
109122
if(index < 0)
110123
{
111-
Current = new Range(Span.Length, Span.Length);
124+
currentEndIndex = Span.Length;
125+
nextStartIndex = Span.Length;
126+
112127
mode = (SpanSplitEnumeratorMode)(-1);
113128
return true;
114129
}
115130

116-
Current = new Range(Current.End.Value + length, Current.Start.Value + index);
117-
131+
currentEndIndex = currentStartIndex + index;
132+
nextStartIndex = currentEndIndex + length;
133+
118134
return true;
119135
}
120136
}
@@ -129,5 +145,4 @@ internal enum SpanSplitEnumeratorMode
129145
}
130146
}
131147
}
132-
133148
#endif

src/Extensions/ReadOnlySpan/Span/Split.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System.Buffers;
1+
using System;
2+
using System.Buffers;
23
using System.Diagnostics;
34
using System.Runtime.CompilerServices;
45

56
#if !NET9_0_OR_GREATER
67

7-
namespace System
8+
namespace SpanExtensions
89
{
910
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1011
public static partial class MemoryExtensions

src/Extensions/Span/Span/Split.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System.Buffers;
1+
using System;
2+
using System.Buffers;
23
using System.Diagnostics;
34
using System.Runtime.CompilerServices;
45

56
#if !NET9_0_OR_GREATER
67

7-
namespace System
8+
namespace SpanExtensions
89
{
910
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1011
public static partial class MemoryExtensions

src/SpanExtensions.csproj

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;net5.0;netstandard2.1</TargetFrameworks>
5-
<ImplicitUsings>disable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
<GenerateDocumentationFile>True</GenerateDocumentationFile>
8-
<Platforms>AnyCPU</Platforms>
9-
<Title>Span Extensions</Title>
10-
<Authors>dragon-cs</Authors>
11-
<Company>draconware</Company>
12-
<Description>
13-
ReadonlySpan&lt;T&gt; and Span&lt;T&gt; 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.
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;net5.0;netstandard2.1</TargetFrameworks>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
8+
<Platforms>AnyCPU</Platforms>
9+
<Title>Span Extensions</Title>
10+
<Authors>dragon-cs</Authors>
11+
<Company>draconware</Company>
12+
<Description>
13+
ReadonlySpan&lt;T&gt; and Span&lt;T&gt; 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.
1414

15-
SpanExtensions.Net aims to help developers use ReadonlySpan&lt;T&gt; and Span&lt;T&gt; more productively, efficiently and safely and write overall more performant Programs.
15+
SpanExtensions.Net aims to help developers use ReadonlySpan&lt;T&gt; and Span&lt;T&gt; more productively, efficiently and safely and write overall more performant Programs.
1616

17-
Never again switch back to using string instead of ReadonlySpan&lt;T&gt;, just because the method you seek is not supported.
18-
</Description>
19-
<RepositoryUrl>https://github.com/draconware-dev/SpanExtensions.Net</RepositoryUrl>
20-
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
21-
<Copyright>Copyright (c) 2024 draconware-dev</Copyright>
22-
<PackageTags>Span;Performance;Extension;String</PackageTags>
23-
<PackageReleaseNotes>https://github.com/draconware-dev/SpanExtensions.Net/blob/main/Changelog.md</PackageReleaseNotes>
24-
<PackageLicenseFile>LICENSE</PackageLicenseFile>
25-
<Version>1.5</Version>
26-
<PackageId>SpanExtensions.Net</PackageId>
27-
<PackageReadmeFile>README.md</PackageReadmeFile>
28-
<PackageIcon>icon.png</PackageIcon>
29-
</PropertyGroup>
17+
Never again switch back to using string instead of ReadonlySpan&lt;T&gt;, just because the method you seek is not supported.
18+
</Description>
19+
<RepositoryUrl>https://github.com/draconware-dev/SpanExtensions.Net</RepositoryUrl>
20+
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
21+
<Copyright>Copyright (c) 2024 draconware-dev</Copyright>
22+
<PackageTags>Span;Performance;Extension;String</PackageTags>
23+
<PackageReleaseNotes>https://github.com/draconware-dev/SpanExtensions.Net/blob/main/Changelog.md</PackageReleaseNotes>
24+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
25+
<Version>1.5.1</Version>
26+
<PackageId>SpanExtensions.Net</PackageId>
27+
<PackageReadmeFile>README.md</PackageReadmeFile>
28+
<PackageIcon>icon.png</PackageIcon>
29+
</PropertyGroup>
3030

31-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
32-
<DebugType>portable</DebugType>
33-
</PropertyGroup>
31+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
32+
<DebugType>portable</DebugType>
33+
</PropertyGroup>
3434

35-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
36-
<DebugType>portable</DebugType>
37-
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
36+
<DebugType>portable</DebugType>
37+
</PropertyGroup>
3838

39-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
40-
<DebugType>portable</DebugType>
41-
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
40+
<DebugType>portable</DebugType>
41+
</PropertyGroup>
4242

43-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
44-
<DebugType>portable</DebugType>
45-
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
44+
<DebugType>portable</DebugType>
45+
</PropertyGroup>
4646

47-
<ItemGroup>
48-
<None Include="README.md">
49-
<Pack>True</Pack>
50-
<PackagePath>\</PackagePath>
51-
</None>
52-
<None Include="..\LICENSE">
53-
<Pack>True</Pack>
54-
<PackagePath>\</PackagePath>
55-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
56-
</None>
57-
</ItemGroup>
47+
<ItemGroup>
48+
<None Include="README.md">
49+
<Pack>True</Pack>
50+
<PackagePath>\</PackagePath>
51+
</None>
52+
<None Include="..\LICENSE">
53+
<Pack>True</Pack>
54+
<PackagePath>\</PackagePath>
55+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
56+
</None>
57+
</ItemGroup>
5858

59-
<ItemGroup>
60-
<None Include="icon.png">
61-
<Pack>True</Pack>
62-
<PackagePath>\</PackagePath>
63-
</None>
64-
</ItemGroup>
59+
<ItemGroup>
60+
<None Include="icon.png">
61+
<Pack>True</Pack>
62+
<PackagePath>\</PackagePath>
63+
</None>
64+
</ItemGroup>
6565

6666
</Project>

0 commit comments

Comments
 (0)