diff --git a/apiCount.include.md b/apiCount.include.md index 3aa32697..c6931d36 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1,28 +1,28 @@ -**API count: 1047** +**API count: 1052** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 980 | -| `net462` | 980 | -| `net47` | 979 | -| `net471` | 978 | -| `net472` | 974 | -| `net48` | 974 | -| `net481` | 974 | -| `netstandard2.0` | 976 | -| `netstandard2.1` | 829 | -| `netcoreapp2.0` | 899 | -| `netcoreapp2.1` | 840 | -| `netcoreapp2.2` | 840 | -| `netcoreapp3.0` | 792 | -| `netcoreapp3.1` | 791 | -| `net5.0` | 663 | -| `net6.0` | 564 | -| `net7.0` | 409 | -| `net8.0` | 290 | -| `net9.0` | 196 | -| `net10.0` | 142 | +| `net461` | 986 | +| `net462` | 986 | +| `net47` | 985 | +| `net471` | 984 | +| `net472` | 980 | +| `net48` | 980 | +| `net481` | 980 | +| `netstandard2.0` | 982 | +| `netstandard2.1` | 835 | +| `netcoreapp2.0` | 905 | +| `netcoreapp2.1` | 846 | +| `netcoreapp2.2` | 846 | +| `netcoreapp3.0` | 801 | +| `netcoreapp3.1` | 800 | +| `net5.0` | 672 | +| `net6.0` | 573 | +| `net7.0` | 418 | +| `net8.0` | 299 | +| `net9.0` | 205 | +| `net10.0` | 151 | | `net11.0` | 58 | -| `uap10.0` | 966 | +| `uap10.0` | 972 | diff --git a/api_list.include.md b/api_list.include.md index 52855e7a..a0f45e66 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -873,10 +873,15 @@ #### ReadOnlySpan + * `bool ContainsAnyWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanywhitespace?view=net-11.0) * `bool EndsWith(string, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith?view=net-11.0#system-memoryextensions-endswith-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `SpanLineEnumerator EnumerateLines()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.enumeratelines?view=net-11.0#system-memoryextensions-enumeratelines(system-readonlyspan((system-char)))) * `int GetNormalizedLength(NormalizationForm)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.stringnormalizationextensions.getnormalizedlength?view=net-11.0#system-stringnormalizationextensions-getnormalizedlength(system-readonlyspan((system-char))-system-text-normalizationform)) + * `int IndexOfAnyExceptWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexceptwhitespace?view=net-11.0) + * `int IndexOfAnyWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanywhitespace?view=net-11.0) * `bool IsNormalized(NormalizationForm)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.stringnormalizationextensions.isnormalized?view=net-11.0#system-stringnormalizationextensions-isnormalized(system-readonlyspan((system-char))-system-text-normalizationform)) + * `int LastIndexOfAnyExceptWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexceptwhitespace?view=net-11.0) + * `int LastIndexOfAnyWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanywhitespace?view=net-11.0) * `bool SequenceEqual(string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sequenceequal?view=net-11.0#system-memoryextensions-sequenceequal-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `int Split(Span, char, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.split?view=net-11.0#system-memoryextensions-split(system-readonlyspan((system-char))-system-span((system-range))-system-char-system-stringsplitoptions)) * `int Split(Span, ReadOnlySpan, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.split?view=net-11.0#system-memoryextensions-split(system-readonlyspan((system-char))-system-span((system-range))-system-readonlyspan((system-char))-system-stringsplitoptions)) diff --git a/assemblySize.include.md b/assemblySize.include.md index 644fb47e..84d31564 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -2,51 +2,51 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 361.5KB | +353.5KB | +7.5KB | +7.0KB | +8.0KB | +12.5KB | -| netstandard2.1 | 8.5KB | 315.5KB | +307.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net461 | 8.5KB | 360.5KB | +352.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| net462 | 7.0KB | 364.0KB | +357.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net47 | 7.0KB | 363.5KB | +356.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net471 | 8.5KB | 363.0KB | +354.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net472 | 8.5KB | 361.5KB | +353.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| net48 | 8.5KB | 361.5KB | +353.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| net481 | 8.5KB | 361.5KB | +353.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| netcoreapp2.0 | 9.0KB | 339.0KB | +330.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 319.0KB | +310.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp2.2 | 9.0KB | 319.0KB | +310.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp3.0 | 9.5KB | 312.5KB | +303.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 310.5KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net5.0 | 9.5KB | 274.5KB | +265.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net6.0 | 10.0KB | 216.0KB | +206.0KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | -| net7.0 | 10.0KB | 178.0KB | +168.0KB | +12.0KB | +8.0KB | +512bytes | +3.0KB | -| net8.0 | 9.5KB | 148.5KB | +139.0KB | +8.5KB | | +512bytes | +3.0KB | -| net9.0 | 9.5KB | 101.5KB | +92.0KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 79.0KB | +69.0KB | +8.5KB | | +512bytes | +3.5KB | -| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | +512bytes | +1.0KB | +4.0KB | +| netstandard2.0 | 8.0KB | 363.5KB | +355.5KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | +| netstandard2.1 | 8.5KB | 317.5KB | +309.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 362.0KB | +353.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | +| net462 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| net47 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net471 | 8.5KB | 364.5KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net472 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +7.0KB | +8.0KB | +12.5KB | +| net48 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +5.5KB | +8.0KB | +12.5KB | +| net481 | 8.5KB | 363.5KB | +355.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netcoreapp2.0 | 9.0KB | 341.0KB | +332.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.2 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.0 | 9.5KB | 315.0KB | +305.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.1 | 9.5KB | 313.0KB | +303.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net5.0 | 9.5KB | 277.5KB | +268.0KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| net6.0 | 10.0KB | 218.5KB | +208.5KB | +10.0KB | +7.0KB | +1.0KB | +3.5KB | +| net7.0 | 10.0KB | 180.5KB | +170.5KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 151.0KB | +141.5KB | +8.5KB | +512bytes | +1.0KB | +3.5KB | +| net9.0 | 9.5KB | 104.5KB | +95.0KB | +8.5KB | | +512bytes | +3.0KB | +| net10.0 | 10.0KB | 82.0KB | +72.0KB | +8.5KB | | +512bytes | +3.5KB | +| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | | +1.0KB | +4.0KB | ### Assembly Sizes with EmbedUntrackedSources | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 530.1KB | +522.1KB | +15.2KB | +8.7KB | +12.9KB | +17.9KB | -| netstandard2.1 | 8.5KB | 457.5KB | +449.0KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net461 | 8.5KB | 530.2KB | +521.7KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| net462 | 7.0KB | 533.7KB | +526.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net47 | 7.0KB | 532.9KB | +525.9KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net471 | 8.5KB | 532.0KB | +523.5KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net472 | 8.5KB | 529.5KB | +521.0KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| net48 | 8.5KB | 529.5KB | +521.0KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| net481 | 8.5KB | 529.5KB | +521.0KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| netcoreapp2.0 | 9.0KB | 497.0KB | +488.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 464.7KB | +455.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp2.2 | 9.0KB | 464.7KB | +455.7KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp3.0 | 9.5KB | 449.3KB | +439.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 447.3KB | +437.8KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net5.0 | 9.5KB | 393.2KB | +383.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net6.0 | 10.0KB | 314.5KB | +304.5KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | -| net7.0 | 10.0KB | 257.7KB | +247.7KB | +19.6KB | +9.4KB | +1.1KB | +3.7KB | -| net8.0 | 9.5KB | 212.7KB | +203.2KB | +16.0KB | +299bytes | +1.1KB | +3.7KB | -| net9.0 | 9.5KB | 144.5KB | +135.0KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 113.4KB | +103.4KB | +16.0KB | | +1.1KB | +4.2KB | -| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | +512bytes | +1.6KB | +4.7KB | +| netstandard2.0 | 8.0KB | 533.1KB | +525.1KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | +| netstandard2.1 | 8.5KB | 460.5KB | +452.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 532.7KB | +524.2KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | +| net462 | 7.0KB | 536.2KB | +529.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| net47 | 7.0KB | 535.9KB | +528.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net471 | 8.5KB | 534.6KB | +526.1KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net472 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +8.7KB | +12.9KB | +17.9KB | +| net48 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +7.2KB | +12.9KB | +17.9KB | +| net481 | 8.5KB | 532.5KB | +524.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netcoreapp2.0 | 9.0KB | 500.1KB | +491.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.2 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.0 | 9.5KB | 453.6KB | +444.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.1 | 9.5KB | 451.6KB | +442.1KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net5.0 | 9.5KB | 398.0KB | +388.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| net6.0 | 10.0KB | 319.0KB | +309.0KB | +17.7KB | +8.7KB | +1.6KB | +4.2KB | +| net7.0 | 10.0KB | 262.2KB | +252.2KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 217.3KB | +207.8KB | +16.0KB | +811bytes | +1.6KB | +4.2KB | +| net9.0 | 9.5KB | 149.7KB | +140.2KB | +16.0KB | | +1.1KB | +3.7KB | +| net10.0 | 10.0KB | 118.5KB | +108.5KB | +16.0KB | | +1.1KB | +4.2KB | +| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | | +1.6KB | +4.7KB | diff --git a/readme.md b/readme.md index 2406c98c..16bffd4e 100644 --- a/readme.md +++ b/readme.md @@ -13,34 +13,34 @@ The package targets `netstandard2.0` and is designed to support the following ru * `uap10` -**API count: 1047** +**API count: 1052** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 980 | -| `net462` | 980 | -| `net47` | 979 | -| `net471` | 978 | -| `net472` | 974 | -| `net48` | 974 | -| `net481` | 974 | -| `netstandard2.0` | 976 | -| `netstandard2.1` | 829 | -| `netcoreapp2.0` | 899 | -| `netcoreapp2.1` | 840 | -| `netcoreapp2.2` | 840 | -| `netcoreapp3.0` | 792 | -| `netcoreapp3.1` | 791 | -| `net5.0` | 663 | -| `net6.0` | 564 | -| `net7.0` | 409 | -| `net8.0` | 290 | -| `net9.0` | 196 | -| `net10.0` | 142 | +| `net461` | 986 | +| `net462` | 986 | +| `net47` | 985 | +| `net471` | 984 | +| `net472` | 980 | +| `net48` | 980 | +| `net481` | 980 | +| `netstandard2.0` | 982 | +| `netstandard2.1` | 835 | +| `netcoreapp2.0` | 905 | +| `netcoreapp2.1` | 846 | +| `netcoreapp2.2` | 846 | +| `netcoreapp3.0` | 801 | +| `netcoreapp3.1` | 800 | +| `net5.0` | 672 | +| `net6.0` | 573 | +| `net7.0` | 418 | +| `net8.0` | 299 | +| `net9.0` | 205 | +| `net10.0` | 151 | | `net11.0` | 58 | -| `uap10.0` | 966 | +| `uap10.0` | 972 | @@ -96,54 +96,54 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 361.5KB | +353.5KB | +7.5KB | +7.0KB | +8.0KB | +12.5KB | -| netstandard2.1 | 8.5KB | 315.5KB | +307.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net461 | 8.5KB | 360.5KB | +352.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| net462 | 7.0KB | 364.0KB | +357.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net47 | 7.0KB | 363.5KB | +356.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net471 | 8.5KB | 363.0KB | +354.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net472 | 8.5KB | 361.5KB | +353.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| net48 | 8.5KB | 361.5KB | +353.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| net481 | 8.5KB | 361.5KB | +353.0KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| netcoreapp2.0 | 9.0KB | 339.0KB | +330.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 319.0KB | +310.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp2.2 | 9.0KB | 319.0KB | +310.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp3.0 | 9.5KB | 312.5KB | +303.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 310.5KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net5.0 | 9.5KB | 274.5KB | +265.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net6.0 | 10.0KB | 216.0KB | +206.0KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | -| net7.0 | 10.0KB | 178.0KB | +168.0KB | +12.0KB | +8.0KB | +512bytes | +3.0KB | -| net8.0 | 9.5KB | 148.5KB | +139.0KB | +8.5KB | | +512bytes | +3.0KB | -| net9.0 | 9.5KB | 101.5KB | +92.0KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 79.0KB | +69.0KB | +8.5KB | | +512bytes | +3.5KB | -| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | +512bytes | +1.0KB | +4.0KB | +| netstandard2.0 | 8.0KB | 363.5KB | +355.5KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | +| netstandard2.1 | 8.5KB | 317.5KB | +309.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 362.0KB | +353.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | +| net462 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | +| net47 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net471 | 8.5KB | 364.5KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net472 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +7.0KB | +8.0KB | +12.5KB | +| net48 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +5.5KB | +8.0KB | +12.5KB | +| net481 | 8.5KB | 363.5KB | +355.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netcoreapp2.0 | 9.0KB | 341.0KB | +332.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.2 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.0 | 9.5KB | 315.0KB | +305.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.1 | 9.5KB | 313.0KB | +303.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net5.0 | 9.5KB | 277.5KB | +268.0KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| net6.0 | 10.0KB | 218.5KB | +208.5KB | +10.0KB | +7.0KB | +1.0KB | +3.5KB | +| net7.0 | 10.0KB | 180.5KB | +170.5KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 151.0KB | +141.5KB | +8.5KB | +512bytes | +1.0KB | +3.5KB | +| net9.0 | 9.5KB | 104.5KB | +95.0KB | +8.5KB | | +512bytes | +3.0KB | +| net10.0 | 10.0KB | 82.0KB | +72.0KB | +8.5KB | | +512bytes | +3.5KB | +| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | | +1.0KB | +4.0KB | ### Assembly Sizes with EmbedUntrackedSources | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 530.1KB | +522.1KB | +15.2KB | +8.7KB | +12.9KB | +17.9KB | -| netstandard2.1 | 8.5KB | 457.5KB | +449.0KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net461 | 8.5KB | 530.2KB | +521.7KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| net462 | 7.0KB | 533.7KB | +526.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net47 | 7.0KB | 532.9KB | +525.9KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net471 | 8.5KB | 532.0KB | +523.5KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net472 | 8.5KB | 529.5KB | +521.0KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| net48 | 8.5KB | 529.5KB | +521.0KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| net481 | 8.5KB | 529.5KB | +521.0KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| netcoreapp2.0 | 9.0KB | 497.0KB | +488.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 464.7KB | +455.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp2.2 | 9.0KB | 464.7KB | +455.7KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp3.0 | 9.5KB | 449.3KB | +439.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 447.3KB | +437.8KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net5.0 | 9.5KB | 393.2KB | +383.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net6.0 | 10.0KB | 314.5KB | +304.5KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | -| net7.0 | 10.0KB | 257.7KB | +247.7KB | +19.6KB | +9.4KB | +1.1KB | +3.7KB | -| net8.0 | 9.5KB | 212.7KB | +203.2KB | +16.0KB | +299bytes | +1.1KB | +3.7KB | -| net9.0 | 9.5KB | 144.5KB | +135.0KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 113.4KB | +103.4KB | +16.0KB | | +1.1KB | +4.2KB | -| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | +512bytes | +1.6KB | +4.7KB | +| netstandard2.0 | 8.0KB | 533.1KB | +525.1KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | +| netstandard2.1 | 8.5KB | 460.5KB | +452.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 532.7KB | +524.2KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | +| net462 | 7.0KB | 536.2KB | +529.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | +| net47 | 7.0KB | 535.9KB | +528.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net471 | 8.5KB | 534.6KB | +526.1KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net472 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +8.7KB | +12.9KB | +17.9KB | +| net48 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +7.2KB | +12.9KB | +17.9KB | +| net481 | 8.5KB | 532.5KB | +524.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netcoreapp2.0 | 9.0KB | 500.1KB | +491.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.2 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.0 | 9.5KB | 453.6KB | +444.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.1 | 9.5KB | 451.6KB | +442.1KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net5.0 | 9.5KB | 398.0KB | +388.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| net6.0 | 10.0KB | 319.0KB | +309.0KB | +17.7KB | +8.7KB | +1.6KB | +4.2KB | +| net7.0 | 10.0KB | 262.2KB | +252.2KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 217.3KB | +207.8KB | +16.0KB | +811bytes | +1.6KB | +4.2KB | +| net9.0 | 9.5KB | 149.7KB | +140.2KB | +16.0KB | | +1.1KB | +3.7KB | +| net10.0 | 10.0KB | 118.5KB | +108.5KB | +16.0KB | | +1.1KB | +4.2KB | +| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | | +1.6KB | +4.7KB | @@ -1488,10 +1488,15 @@ The class `Polyfill` includes the following extension methods: #### ReadOnlySpan + * `bool ContainsAnyWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanywhitespace?view=net-11.0) * `bool EndsWith(string, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith?view=net-11.0#system-memoryextensions-endswith-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `SpanLineEnumerator EnumerateLines()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.enumeratelines?view=net-11.0#system-memoryextensions-enumeratelines(system-readonlyspan((system-char)))) * `int GetNormalizedLength(NormalizationForm)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.stringnormalizationextensions.getnormalizedlength?view=net-11.0#system-stringnormalizationextensions-getnormalizedlength(system-readonlyspan((system-char))-system-text-normalizationform)) + * `int IndexOfAnyExceptWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexceptwhitespace?view=net-11.0) + * `int IndexOfAnyWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanywhitespace?view=net-11.0) * `bool IsNormalized(NormalizationForm)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.stringnormalizationextensions.isnormalized?view=net-11.0#system-stringnormalizationextensions-isnormalized(system-readonlyspan((system-char))-system-text-normalizationform)) + * `int LastIndexOfAnyExceptWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexceptwhitespace?view=net-11.0) + * `int LastIndexOfAnyWhiteSpace()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanywhitespace?view=net-11.0) * `bool SequenceEqual(string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sequenceequal?view=net-11.0#system-memoryextensions-sequenceequal-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `int Split(Span, char, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.split?view=net-11.0#system-memoryextensions-split(system-readonlyspan((system-char))-system-span((system-range))-system-char-system-stringsplitoptions)) * `int Split(Span, ReadOnlySpan, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.split?view=net-11.0#system-memoryextensions-split(system-readonlyspan((system-char))-system-span((system-range))-system-readonlyspan((system-char))-system-stringsplitoptions)) diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index dca6aca4..13f20ce3 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -1518,6 +1518,13 @@ void ReadOnlySpan_Methods() _ = readOnlySpan.LastIndexOfAnyExcept('a', 'b'); _ = readOnlySpan.LastIndexOfAnyExcept('a', 'b', 'c'); _ = readOnlySpan.LastIndexOfAnyExcept("ab".AsSpan()); + + bool containsAnyWhiteSpace = readOnlySpan.ContainsAnyWhiteSpace(); + int indexOfAnyWhiteSpace = readOnlySpan.IndexOfAnyWhiteSpace(); + int indexOfAnyExceptWhiteSpace = readOnlySpan.IndexOfAnyExceptWhiteSpace(); + int lastIndexOfAnyWhiteSpace = readOnlySpan.LastIndexOfAnyWhiteSpace(); + int lastIndexOfAnyExceptWhiteSpace = readOnlySpan.LastIndexOfAnyExceptWhiteSpace(); + #if FeatureValueTuple var split = readOnlySpan.Split('a'); split = readOnlySpan.Split("a".AsSpan()); diff --git a/src/Polyfill/Polyfill_Memory_WhiteSpace.cs b/src/Polyfill/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..c2a58201 --- /dev/null +++ b/src/Polyfill/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,85 @@ +#if FeatureMemory && !NET11_0_OR_GREATER + +namespace Polyfills; + +using System; + +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanywhitespace?view=net-11.0 + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + + /// + /// Searches for the first index of any white-space character in the span. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanywhitespace?view=net-11.0 + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + + return -1; + } + + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexceptwhitespace?view=net-11.0 + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + + return -1; + } + + /// + /// Searches for the last index of any white-space character in the span. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanywhitespace?view=net-11.0 + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + + return -1; + } + + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexceptwhitespace?view=net-11.0 + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + + return -1; + } +} + +#endif diff --git a/src/Split/net10.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/net10.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net10.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net461/Polyfill_Memory_WhiteSpace.cs b/src/Split/net461/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net461/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net462/Polyfill_Memory_WhiteSpace.cs b/src/Split/net462/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net462/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net47/Polyfill_Memory_WhiteSpace.cs b/src/Split/net47/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net47/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net471/Polyfill_Memory_WhiteSpace.cs b/src/Split/net471/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net471/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net472/Polyfill_Memory_WhiteSpace.cs b/src/Split/net472/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net472/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net48/Polyfill_Memory_WhiteSpace.cs b/src/Split/net48/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net48/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net481/Polyfill_Memory_WhiteSpace.cs b/src/Split/net481/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net481/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net5.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/net5.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net5.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net6.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/net6.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net6.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net7.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/net7.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net7.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net8.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/net8.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net8.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/net9.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/net9.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/net9.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/netcoreapp2.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/netcoreapp2.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/netcoreapp2.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/netcoreapp2.1/Polyfill_Memory_WhiteSpace.cs b/src/Split/netcoreapp2.1/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/netcoreapp2.1/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/netcoreapp2.2/Polyfill_Memory_WhiteSpace.cs b/src/Split/netcoreapp2.2/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/netcoreapp2.2/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/netcoreapp3.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/netcoreapp3.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/netcoreapp3.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/netcoreapp3.1/Polyfill_Memory_WhiteSpace.cs b/src/Split/netcoreapp3.1/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/netcoreapp3.1/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/netstandard2.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/netstandard2.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/netstandard2.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/netstandard2.1/Polyfill_Memory_WhiteSpace.cs b/src/Split/netstandard2.1/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/netstandard2.1/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Split/uap10.0/Polyfill_Memory_WhiteSpace.cs b/src/Split/uap10.0/Polyfill_Memory_WhiteSpace.cs new file mode 100644 index 00000000..8c73afec --- /dev/null +++ b/src/Split/uap10.0/Polyfill_Memory_WhiteSpace.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable +#if FeatureMemory +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Searches for any white-space character in the span. + /// + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + span.IndexOfAnyWhiteSpace() >= 0; + /// + /// Searches for the first index of any white-space character in the span. + /// + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the first index of any character other than a white-space character in the span. + /// + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = 0; index < span.Length; index++) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any white-space character in the span. + /// + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } + /// + /// Searches for the last index of any character other than a white-space character in the span. + /// + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) + { + for (var index = span.Length - 1; index >= 0; index--) + { + if (!char.IsWhiteSpace(span[index])) + { + return index; + } + } + return -1; + } +} +#endif diff --git a/src/Tests/PolyfillTests_SpanWhiteSpace.cs b/src/Tests/PolyfillTests_SpanWhiteSpace.cs new file mode 100644 index 00000000..97da6ab1 --- /dev/null +++ b/src/Tests/PolyfillTests_SpanWhiteSpace.cs @@ -0,0 +1,73 @@ +#if FeatureMemory + +partial class PolyfillTests +{ + [Test] + public async Task Span_ContainsAnyWhiteSpace() + { + await Assert.That("ab cd".AsSpan().ContainsAnyWhiteSpace()).IsTrue(); + await Assert.That("abcd".AsSpan().ContainsAnyWhiteSpace()).IsFalse(); + await Assert.That("\t".AsSpan().ContainsAnyWhiteSpace()).IsTrue(); + await Assert.That(ReadOnlySpan.Empty.ContainsAnyWhiteSpace()).IsFalse(); + } + + [Test] + public async Task Span_IndexOfAnyWhiteSpace() + { + await Assert.That("ab cd ef".AsSpan().IndexOfAnyWhiteSpace()).IsEqualTo(2); + await Assert.That("abc".AsSpan().IndexOfAnyWhiteSpace()).IsEqualTo(-1); + await Assert.That(" ".AsSpan().IndexOfAnyWhiteSpace()).IsEqualTo(0); + await Assert.That(ReadOnlySpan.Empty.IndexOfAnyWhiteSpace()).IsEqualTo(-1); + } + + [Test] + public async Task Span_IndexOfAnyExceptWhiteSpace() + { + await Assert.That("ab cd ef".AsSpan().IndexOfAnyExceptWhiteSpace()).IsEqualTo(0); + await Assert.That(" abc".AsSpan().IndexOfAnyExceptWhiteSpace()).IsEqualTo(2); + await Assert.That(" ".AsSpan().IndexOfAnyExceptWhiteSpace()).IsEqualTo(-1); + await Assert.That(ReadOnlySpan.Empty.IndexOfAnyExceptWhiteSpace()).IsEqualTo(-1); + } + + [Test] + public async Task Span_LastIndexOfAnyWhiteSpace() + { + await Assert.That("ab cd ef".AsSpan().LastIndexOfAnyWhiteSpace()).IsEqualTo(5); + await Assert.That("abc".AsSpan().LastIndexOfAnyWhiteSpace()).IsEqualTo(-1); + await Assert.That(" ".AsSpan().LastIndexOfAnyWhiteSpace()).IsEqualTo(2); + await Assert.That(ReadOnlySpan.Empty.LastIndexOfAnyWhiteSpace()).IsEqualTo(-1); + } + + [Test] + public async Task Span_LastIndexOfAnyExceptWhiteSpace() + { + await Assert.That("ab cd ef".AsSpan().LastIndexOfAnyExceptWhiteSpace()).IsEqualTo(7); + await Assert.That("abc ".AsSpan().LastIndexOfAnyExceptWhiteSpace()).IsEqualTo(2); + await Assert.That(" ".AsSpan().LastIndexOfAnyExceptWhiteSpace()).IsEqualTo(-1); + await Assert.That(ReadOnlySpan.Empty.LastIndexOfAnyExceptWhiteSpace()).IsEqualTo(-1); + } + + [Test] + [Arguments(' ')] + [Arguments('\t')] + [Arguments('\n')] + [Arguments('\r')] + [Arguments(' ')] // vertical tab + [Arguments(' ')] // no-break space + [Arguments(' ')] // em space + [Arguments(' ')] // ideographic space + [Arguments('a')] + [Arguments('​')] // zero width space, which is not white-space + public async Task Span_WhiteSpace_MatchesCharIsWhiteSpace(char value) + { + var contains = value.ToString().AsSpan().ContainsAnyWhiteSpace(); + var index = value.ToString().AsSpan().IndexOfAnyWhiteSpace(); + var except = value.ToString().AsSpan().IndexOfAnyExceptWhiteSpace(); + var isWhiteSpace = char.IsWhiteSpace(value); + await Assert.That(contains).IsEqualTo(isWhiteSpace); + await Assert.That(index).IsEqualTo(isWhiteSpace ? 0 : -1); + await Assert.That(except).IsEqualTo(isWhiteSpace ? -1 : 0); + } +} + +#endif