Skip to content

Commit 30c8739

Browse files
committed
handle count equals 1 and RemoveEmptyEntries set
1 parent 8bb8994 commit 30c8739

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/Enumerators/Split/SpanSplitStringSplitOptionsWithCountEnumerator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public SpanSplitStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source,
4343
CountExceedingBehaviour = countExceedingBehaviour.ThrowIfInvalid();
4444
EnumerationDone = count == 0;
4545
Current = default;
46+
47+
if(count == 1) // special case
48+
{
49+
CurrentCount = 0;
50+
}
4651
}
4752

4853
/// <summary>
@@ -68,11 +73,11 @@ public bool MoveNext()
6873
{
6974
int delimiterIndex = Span.IndexOf(Delimiter);
7075

71-
if(delimiterIndex == -1 || CurrentCount == 1)
76+
if(delimiterIndex == -1 || CurrentCount <= 1)
7277
{
7378
EnumerationDone = true;
7479

75-
if(delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
80+
if(CurrentCount != 0 && delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
7681
{
7782
do
7883
{

src/Enumerators/SplitAny/SpanSplitAnyStringSplitOptionsWithCountEnumerator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public SpanSplitAnyStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> sour
4343
CountExceedingBehaviour = countExceedingBehaviour.ThrowIfInvalid();
4444
EnumerationDone = count == 0;
4545
Current = default;
46+
47+
if(count == 1) // special case
48+
{
49+
CurrentCount = 0;
50+
}
4651
}
4752

4853
/// <summary>
@@ -68,11 +73,11 @@ public bool MoveNext()
6873
{
6974
int delimiterIndex = Span.IndexOfAny(Delimiters);
7075

71-
if(delimiterIndex == -1 || CurrentCount == 1)
76+
if(delimiterIndex == -1 || CurrentCount <= 1)
7277
{
7378
EnumerationDone = true;
7479

75-
if(delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
80+
if(CurrentCount != 0 && delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
7681
{
7782
do
7883
{

src/Enumerators/SplitSequence/SpanSplitSequenceStringSplitOptionsWithCountEnumerator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public SpanSplitSequenceStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char>
4444
CountExceedingBehaviour = countExceedingBehaviour.ThrowIfInvalid();
4545
EnumerationDone = count == 0;
4646
Current = default;
47+
48+
if(count == 1) // special case
49+
{
50+
CurrentCount = 0;
51+
}
4752
}
4853

4954
/// <summary>
@@ -69,11 +74,11 @@ public bool MoveNext()
6974
{
7075
int delimiterIndex = Span.IndexOf(Delimiter);
7176

72-
if(delimiterIndex == -1 || CurrentCount == 1)
77+
if(delimiterIndex == -1 || CurrentCount <= 1)
7378
{
7479
EnumerationDone = true;
7580

76-
if(delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
81+
if(CurrentCount != 0 && delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
7782
{
7883
do
7984
{

0 commit comments

Comments
 (0)