Skip to content

Add net11 span white-space search APIs - #586

Merged
SimonCropp merged 1 commit into
mainfrom
span-whitespace
Sep 9, 2026
Merged

Add net11 span white-space search APIs#586
SimonCropp merged 1 commit into
mainfrom
span-whitespace

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Adds the white-space searches added to ReadOnlySpan<char> in net11:

  • ContainsAnyWhiteSpace()
  • IndexOfAnyWhiteSpace()
  • IndexOfAnyExceptWhiteSpace()
  • LastIndexOfAnyWhiteSpace()
  • LastIndexOfAnyExceptWhiteSpace()

API count 1047 to 1052.

Semantics

The white-space set was checked against net11 across the whole BMP and matches char.IsWhiteSpace on every code point, so the implementation is a straight scan using it rather than a hardcoded set. Empty spans return false and -1, matching net11.

The BCL versions are vectorised and these are not, but both are O(n) and the results are identical, so no //Note: was added.

Placement

In their own Polyfill_Memory_WhiteSpace.cs, following the existing split of Polyfill_Memory into Polyfill_Memory_StartsWith.cs, Polyfill_Memory_EndsWith.cs and so on. That also keeps this clear of #585, which touches the end of Polyfill_Memory.cs, so the two can merge in either order.

Note that MemoryExtensions.IsWhiteSpace(ReadOnlySpan<char>) is not included: it already ships in System.Memory, so it is available wherever FeatureMemory is set.

Verification

  • Solution builds clean in Release. Consume builds clean in Debug across all 22 target frameworks.
  • Tests green on net11.0 (1635), net462 (1612) and net8.0 (1632), plus PublicTests, EmbeddedTests, UnsafeTests, NoRefsTests and NoExtrasTests.
  • The parameterised test covers space, tab, newline, carriage return, vertical tab, no-break space, em space and ideographic space, plus a letter and the zero width space, which is not white-space. The same assertions run against the BCL on net11 and against the polyfill on earlier target frameworks.

Adds the white-space searches on ReadOnlySpan<char>:

* ContainsAnyWhiteSpace()
* IndexOfAnyWhiteSpace()
* IndexOfAnyExceptWhiteSpace()
* LastIndexOfAnyWhiteSpace()
* LastIndexOfAnyExceptWhiteSpace()

The white-space set was checked against net11 over the whole BMP and
matches char.IsWhiteSpace on every code point, so the implementation is a
straight scan using it. Empty spans return false and -1, matching net11.

Placed in their own Polyfill_Memory_WhiteSpace.cs, following the existing
split of Polyfill_Memory.
@SimonCropp SimonCropp added this to the 11.3.0 milestone Sep 9, 2026
@SimonCropp
SimonCropp merged commit 180044d into main Sep 9, 2026
4 of 6 checks passed
@SimonCropp
SimonCropp deleted the span-whitespace branch September 9, 2026 13:19
This was referenced Sep 10, 2026
This was referenced Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant