[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed and optimized split methods #11

Merged
Prev Previous commit
Next Next commit
handle count equals 1 and RemoveEmptyEntries set
  • Loading branch information
Guiorgy committed Feb 5, 2024
commit 30c8739630ae00a56c56e47bd78dcef974ef9ddf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public SpanSplitStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source,
CountExceedingBehaviour = countExceedingBehaviour.ThrowIfInvalid();
EnumerationDone = count == 0;
Current = default;

if(count == 1) // special case
{
CurrentCount = 0;
}
}

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

if(delimiterIndex == -1 || CurrentCount == 1)
if(delimiterIndex == -1 || CurrentCount <= 1)
{
EnumerationDone = true;

if(delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
if(CurrentCount != 0 && delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
{
do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public SpanSplitAnyStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> sour
CountExceedingBehaviour = countExceedingBehaviour.ThrowIfInvalid();
EnumerationDone = count == 0;
Current = default;

if(count == 1) // special case
{
CurrentCount = 0;
}
}

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

if(delimiterIndex == -1 || CurrentCount == 1)
if(delimiterIndex == -1 || CurrentCount <= 1)
{
EnumerationDone = true;

if(delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
if(CurrentCount != 0 && delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
{
do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public SpanSplitSequenceStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char>
CountExceedingBehaviour = countExceedingBehaviour.ThrowIfInvalid();
EnumerationDone = count == 0;
Current = default;

if(count == 1) // special case
{
CurrentCount = 0;
}
}

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

if(delimiterIndex == -1 || CurrentCount == 1)
if(delimiterIndex == -1 || CurrentCount <= 1)
{
EnumerationDone = true;

if(delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
if(CurrentCount != 0 && delimiterIndex != -1 && RemoveEmptyEntries) // skip all empty (after trimming if necessary) entries from the left
{
do
{
Expand Down