Repository navigation
Yield the empty entry after a trailing separator from the span Split [patch] - #473
Merged
Merged
Conversation
…[patch] SpanSplitEnumerator stopped as soon as its remainder was empty, so the empty field after a trailing separator was never yielded and an empty string yielded nothing. It now tracks when the last segment has been read, and matches string.Split under every option: "a,b," gives three parts, ",," three and "" one. This changes the span overload's results for those inputs. Fixes #441 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CcmGrWCwm3uDHcCpVZVcJU
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #441
What was wrong
SpanSplitEnumerator.MoveNextloopedwhile (!_remaining.IsEmpty). Once the last separator had been consumed, the remainder was empty and enumeration stopped. So the empty field after a trailing separator was never yielded, and an empty string yielded nothing at all. That differs fromstring.Split, which the doc comment says this overload replaces:Nonestring.Split"a,b,"",""""a,,"Change
_finishedflag records that the last segment has been read. The loop runs until it is set, rather than until the remainder is empty. The loop is still a loop, so the stack-depth fix from SemanticString.Split(char, RemoveEmptyEntries) crashes the process with a stack overflow on a long run of separators, and ignores combined/TrimEntries options #298 stays.RemoveEmptyEntriesandTrimEntriesare applied exactly as before, so every option combination now matchesstring.Split.Split(char, ...)doc comment now states the parity.Behaviour change: the span overload now returns one more, empty, entry for an empty input or one that ends in a separator. The triage asked for this to be called out in the release notes. It is spelled out in the commit message.
Tests
string.Split's results:""gives one empty part and",,"gives three.SpanSplitEnumerator_MatchesStringSplit_UnderEveryOption. It compares the enumerator withstring.Splitover leading, trailing, consecutive, only-separator and whitespace inputs, under all four option combinations. It loops over a corpus inside the test instead of using[DataRow]because of CA1062, following the existing note inSourceGeneratorTests.SemanticString.cschange reverted, those 3 tests fail.This branch stands alone on
main, and it merges cleanly with #472.Generated by Claude Code