diff --git a/apiCount.include.md b/apiCount.include.md index 6555938d..c0e7a582 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1 +1 @@ -**API count: 776** \ No newline at end of file +**API count: 784** \ No newline at end of file diff --git a/api_list.include.md b/api_list.include.md index 9240c05e..f6477e6c 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -92,6 +92,7 @@ #### Char + * `bool Equals(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.equals?view=net-11.0#system-char-equals(system-char-system-stringcomparison)) * `bool IsAscii(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.isascii?view=net-11.0) * `bool IsAsciiDigit(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.isasciidigit?view=net-11.0) * `bool IsAsciiHexDigit(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.isasciihexdigit?view=net-11.0) @@ -832,6 +833,7 @@ * `bool Contains(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains?view=net-11.0#system-string-contains(system-char)) * `bool Contains(string, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains?view=net-11.0#system-string-contains(system-string-system-stringcomparison)) * `void CopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.copyto?view=net-11.0) + * `bool EndsWith(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith?view=net-11.0#system-string-endswith(system-char-system-stringcomparison)) * `bool EndsWith(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith?view=net-11.0#system-string-endswith(system-char)) * `IEnumerable EnumerateDirectories(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratedirectories?view=net-11.0#system-io-directory-enumeratedirectories(system-string-system-string-system-io-enumerationoptions)) * `IEnumerable EnumerateFiles(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=net-11.0#system-io-directory-enumeratefiles(system-string-system-string-system-io-enumerationoptions)) @@ -840,13 +842,19 @@ * `string[] GetFiles(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=net-11.0#system-io-directory-getfiles(system-string-system-string-system-io-enumerationoptions)) * `string[] GetFileSystemEntries(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.getfilesystementries?view=net-11.0#system-io-directory-getfilesystementries(system-string-system-string-system-io-enumerationoptions)) * `int GetHashCode(StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.gethashcode?view=net-11.0#system-string-gethashcode(system-stringcomparison)) + * `int IndexOf(char, int, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-int32-system-int32-system-stringcomparison)) + * `int IndexOf(char, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-int32-system-stringcomparison)) * `int IndexOf(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-stringcomparison)) + * `int LastIndexOf(char, int, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-int32-system-int32-system-stringcomparison)) + * `int LastIndexOf(char, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-int32-system-stringcomparison)) + * `int LastIndexOf(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-stringcomparison)) * `string ReplaceLineEndings(string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.replacelineendings?view=net-11.0#system-string-replacelineendings(system-string)) * `string ReplaceLineEndings()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.replacelineendings?view=net-11.0#system-string-replacelineendings) * `string[] Split(char, int, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-char-system-int32-system-stringsplitoptions)) * `string[] Split(char, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-char-system-stringsplitoptions)) * `string[] Split(string, int, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-string-system-int32-system-stringsplitoptions)) * `string[] Split(string, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-string-system-stringsplitoptions)) + * `bool StartsWith(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.startswith?view=net-11.0#system-string-startswith(system-char-system-stringcomparison)) * `bool StartsWith(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.startswith?view=net-11.0#system-string-startswith(system-char)) * `bool TryCopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.trycopyto?view=net-11.0) * `string Create(int, TState, System.Buffers.SpanAction)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.create?view=net-11.0#system-string-create-1(system-int32-0-system-buffers-spanaction((system-char-0)))) diff --git a/assemblySize.include.md b/assemblySize.include.md index dc6947a0..ed945f22 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -2,26 +2,26 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 247.0KB | +239.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 200.5KB | +192.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net461 | 8.5KB | 253.5KB | +245.0KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| net462 | 7.0KB | 252.0KB | +245.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net47 | 7.0KB | 252.0KB | +245.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 252.0KB | +243.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 250.5KB | +242.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net48 | 8.5KB | 250.5KB | +242.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net481 | 8.5KB | 250.5KB | +242.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.0 | 9.0KB | 226.5KB | +217.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 208.0KB | +199.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp2.2 | 9.0KB | 208.0KB | +199.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp3.0 | 9.5KB | 199.0KB | +189.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 197.0KB | +187.5KB | +9.5KB | +6.5KB | +9.0KB | +14.0KB | -| net5.0 | 9.5KB | 161.5KB | +152.0KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 116.5KB | +106.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | -| net7.0 | 10.0KB | 86.0KB | +76.0KB | +9.5KB | +6.0KB | +1.0KB | +3.5KB | -| net8.0 | 9.5KB | 69.5KB | +60.0KB | +8.5KB | +512bytes | +512bytes | +3.5KB | -| net9.0 | 10.0KB | 35.5KB | +25.5KB | +9.0KB | | +1.0KB | +4.0KB | -| net10.0 | 10.0KB | 22.5KB | +12.5KB | +9.0KB | | +512bytes | +3.5KB | +| netstandard2.0 | 8.0KB | 248.0KB | +240.0KB | +8.5KB | +6.0KB | +9.0KB | +13.5KB | +| netstandard2.1 | 8.5KB | 201.5KB | +193.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net461 | 8.5KB | 254.0KB | +245.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net462 | 7.0KB | 253.0KB | +246.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net47 | 7.0KB | 252.5KB | +245.5KB | +9.5KB | +6.5KB | +9.0KB | +14.0KB | +| net471 | 8.5KB | 253.0KB | +244.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 251.5KB | +243.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net48 | 8.5KB | 251.5KB | +243.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net481 | 8.5KB | 251.5KB | +243.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.0 | 9.0KB | 227.0KB | +218.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp2.1 | 9.0KB | 209.0KB | +200.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp2.2 | 9.0KB | 209.0KB | +200.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 199.5KB | +190.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp3.1 | 9.5KB | 198.0KB | +188.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net5.0 | 9.5KB | 162.0KB | +152.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| net6.0 | 10.0KB | 117.5KB | +107.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | +| net7.0 | 10.0KB | 87.0KB | +77.0KB | +9.5KB | +5.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 70.5KB | +61.0KB | +8.5KB | | +512bytes | +3.5KB | +| net9.0 | 10.0KB | 36.5KB | +26.5KB | +9.0KB | | +1.0KB | +3.5KB | +| net10.0 | 10.0KB | 23.0KB | +13.0KB | +9.0KB | | +1.0KB | +4.0KB | | net11.0 | 10.0KB | 19.0KB | +9.0KB | +9.5KB | | +1.0KB | +4.0KB | @@ -29,24 +29,24 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 366.3KB | +358.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netstandard2.1 | 8.5KB | 294.8KB | +286.3KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net461 | 8.5KB | 373.2KB | +364.7KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| net462 | 7.0KB | 371.7KB | +364.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net47 | 7.0KB | 371.5KB | +364.5KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 371.5KB | +363.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net472 | 8.5KB | 368.9KB | +360.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net48 | 8.5KB | 368.9KB | +360.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net481 | 8.5KB | 368.9KB | +360.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.0 | 9.0KB | 335.5KB | +326.5KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 306.5KB | +297.5KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp2.2 | 9.0KB | 306.5KB | +297.5KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp3.0 | 9.5KB | 288.4KB | +278.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 286.4KB | +276.9KB | +17.2KB | +8.2KB | +13.9KB | +19.4KB | -| net5.0 | 9.5KB | 233.8KB | +224.3KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 171.9KB | +161.9KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | -| net7.0 | 10.0KB | 124.6KB | +114.6KB | +17.1KB | +7.4KB | +1.6KB | +4.2KB | -| net8.0 | 9.5KB | 99.1KB | +89.6KB | +16.0KB | +811bytes | +1.1KB | +4.2KB | -| net9.0 | 10.0KB | 51.6KB | +41.6KB | +16.5KB | | +1.6KB | +4.7KB | -| net10.0 | 10.0KB | 33.9KB | +23.9KB | +16.5KB | | +1.1KB | +4.2KB | +| netstandard2.0 | 8.0KB | 367.8KB | +359.8KB | +16.2KB | +7.7KB | +13.9KB | +18.9KB | +| netstandard2.1 | 8.5KB | 296.5KB | +288.0KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net461 | 8.5KB | 374.2KB | +365.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net462 | 7.0KB | 373.2KB | +366.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net47 | 7.0KB | 372.5KB | +365.5KB | +17.2KB | +8.2KB | +13.9KB | +19.4KB | +| net471 | 8.5KB | 373.0KB | +364.5KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | +| net472 | 8.5KB | 370.4KB | +361.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net48 | 8.5KB | 370.4KB | +361.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net481 | 8.5KB | 370.4KB | +361.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.0 | 9.0KB | 336.7KB | +327.7KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp2.1 | 9.0KB | 308.2KB | +299.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp2.2 | 9.0KB | 308.2KB | +299.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 289.6KB | +280.1KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp3.1 | 9.5KB | 288.0KB | +278.5KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net5.0 | 9.5KB | 234.9KB | +225.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| net6.0 | 10.0KB | 173.8KB | +163.8KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | +| net7.0 | 10.0KB | 126.4KB | +116.4KB | +17.1KB | +6.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 100.9KB | +91.4KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | +| net9.0 | 10.0KB | 53.4KB | +43.4KB | +16.5KB | | +1.6KB | +4.2KB | +| net10.0 | 10.0KB | 35.2KB | +25.2KB | +16.5KB | | +1.6KB | +4.7KB | | net11.0 | 10.0KB | 28.5KB | +18.5KB | +17.0KB | | +1.6KB | +4.7KB | diff --git a/readme.md b/readme.md index 6ccc1757..281abe13 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ The package targets `netstandard2.0` and is designed to support the following ru * `uap10` -**API count: 776** +**API count: 784** **See [Milestones](../../milestones?state=closed) for release notes.** @@ -68,26 +68,26 @@ This project uses features from the current stable SDK and C# language. As such | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 247.0KB | +239.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 200.5KB | +192.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net461 | 8.5KB | 253.5KB | +245.0KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| net462 | 7.0KB | 252.0KB | +245.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net47 | 7.0KB | 252.0KB | +245.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 252.0KB | +243.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 250.5KB | +242.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net48 | 8.5KB | 250.5KB | +242.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net481 | 8.5KB | 250.5KB | +242.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.0 | 9.0KB | 226.5KB | +217.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 208.0KB | +199.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp2.2 | 9.0KB | 208.0KB | +199.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp3.0 | 9.5KB | 199.0KB | +189.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 197.0KB | +187.5KB | +9.5KB | +6.5KB | +9.0KB | +14.0KB | -| net5.0 | 9.5KB | 161.5KB | +152.0KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 116.5KB | +106.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | -| net7.0 | 10.0KB | 86.0KB | +76.0KB | +9.5KB | +6.0KB | +1.0KB | +3.5KB | -| net8.0 | 9.5KB | 69.5KB | +60.0KB | +8.5KB | +512bytes | +512bytes | +3.5KB | -| net9.0 | 10.0KB | 35.5KB | +25.5KB | +9.0KB | | +1.0KB | +4.0KB | -| net10.0 | 10.0KB | 22.5KB | +12.5KB | +9.0KB | | +512bytes | +3.5KB | +| netstandard2.0 | 8.0KB | 248.0KB | +240.0KB | +8.5KB | +6.0KB | +9.0KB | +13.5KB | +| netstandard2.1 | 8.5KB | 201.5KB | +193.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net461 | 8.5KB | 254.0KB | +245.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net462 | 7.0KB | 253.0KB | +246.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net47 | 7.0KB | 252.5KB | +245.5KB | +9.5KB | +6.5KB | +9.0KB | +14.0KB | +| net471 | 8.5KB | 253.0KB | +244.5KB | +9.0KB | +6.0KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 251.5KB | +243.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net48 | 8.5KB | 251.5KB | +243.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net481 | 8.5KB | 251.5KB | +243.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.0 | 9.0KB | 227.0KB | +218.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp2.1 | 9.0KB | 209.0KB | +200.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp2.2 | 9.0KB | 209.0KB | +200.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 199.5KB | +190.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| netcoreapp3.1 | 9.5KB | 198.0KB | +188.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net5.0 | 9.5KB | 162.0KB | +152.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| net6.0 | 10.0KB | 117.5KB | +107.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | +| net7.0 | 10.0KB | 87.0KB | +77.0KB | +9.5KB | +5.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 70.5KB | +61.0KB | +8.5KB | | +512bytes | +3.5KB | +| net9.0 | 10.0KB | 36.5KB | +26.5KB | +9.0KB | | +1.0KB | +3.5KB | +| net10.0 | 10.0KB | 23.0KB | +13.0KB | +9.0KB | | +1.0KB | +4.0KB | | net11.0 | 10.0KB | 19.0KB | +9.0KB | +9.5KB | | +1.0KB | +4.0KB | @@ -95,26 +95,26 @@ This project uses features from the current stable SDK and C# language. As such | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 366.3KB | +358.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netstandard2.1 | 8.5KB | 294.8KB | +286.3KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net461 | 8.5KB | 373.2KB | +364.7KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| net462 | 7.0KB | 371.7KB | +364.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net47 | 7.0KB | 371.5KB | +364.5KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 371.5KB | +363.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net472 | 8.5KB | 368.9KB | +360.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net48 | 8.5KB | 368.9KB | +360.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net481 | 8.5KB | 368.9KB | +360.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.0 | 9.0KB | 335.5KB | +326.5KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 306.5KB | +297.5KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp2.2 | 9.0KB | 306.5KB | +297.5KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp3.0 | 9.5KB | 288.4KB | +278.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 286.4KB | +276.9KB | +17.2KB | +8.2KB | +13.9KB | +19.4KB | -| net5.0 | 9.5KB | 233.8KB | +224.3KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 171.9KB | +161.9KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | -| net7.0 | 10.0KB | 124.6KB | +114.6KB | +17.1KB | +7.4KB | +1.6KB | +4.2KB | -| net8.0 | 9.5KB | 99.1KB | +89.6KB | +16.0KB | +811bytes | +1.1KB | +4.2KB | -| net9.0 | 10.0KB | 51.6KB | +41.6KB | +16.5KB | | +1.6KB | +4.7KB | -| net10.0 | 10.0KB | 33.9KB | +23.9KB | +16.5KB | | +1.1KB | +4.2KB | +| netstandard2.0 | 8.0KB | 367.8KB | +359.8KB | +16.2KB | +7.7KB | +13.9KB | +18.9KB | +| netstandard2.1 | 8.5KB | 296.5KB | +288.0KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net461 | 8.5KB | 374.2KB | +365.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net462 | 7.0KB | 373.2KB | +366.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net47 | 7.0KB | 372.5KB | +365.5KB | +17.2KB | +8.2KB | +13.9KB | +19.4KB | +| net471 | 8.5KB | 373.0KB | +364.5KB | +16.7KB | +7.7KB | +13.9KB | +18.9KB | +| net472 | 8.5KB | 370.4KB | +361.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net48 | 8.5KB | 370.4KB | +361.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net481 | 8.5KB | 370.4KB | +361.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.0 | 9.0KB | 336.7KB | +327.7KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp2.1 | 9.0KB | 308.2KB | +299.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp2.2 | 9.0KB | 308.2KB | +299.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 289.6KB | +280.1KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| netcoreapp3.1 | 9.5KB | 288.0KB | +278.5KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net5.0 | 9.5KB | 234.9KB | +225.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| net6.0 | 10.0KB | 173.8KB | +163.8KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | +| net7.0 | 10.0KB | 126.4KB | +116.4KB | +17.1KB | +6.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 100.9KB | +91.4KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | +| net9.0 | 10.0KB | 53.4KB | +43.4KB | +16.5KB | | +1.6KB | +4.2KB | +| net10.0 | 10.0KB | 35.2KB | +25.2KB | +16.5KB | | +1.6KB | +4.7KB | | net11.0 | 10.0KB | 28.5KB | +18.5KB | +17.0KB | | +1.6KB | +4.7KB | @@ -595,6 +595,7 @@ The class `Polyfill` includes the following extension methods: #### Char + * `bool Equals(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.equals?view=net-11.0#system-char-equals(system-char-system-stringcomparison)) * `bool IsAscii(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.isascii?view=net-11.0) * `bool IsAsciiDigit(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.isasciidigit?view=net-11.0) * `bool IsAsciiHexDigit(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.char.isasciihexdigit?view=net-11.0) @@ -1335,6 +1336,7 @@ The class `Polyfill` includes the following extension methods: * `bool Contains(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains?view=net-11.0#system-string-contains(system-char)) * `bool Contains(string, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains?view=net-11.0#system-string-contains(system-string-system-stringcomparison)) * `void CopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.copyto?view=net-11.0) + * `bool EndsWith(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith?view=net-11.0#system-string-endswith(system-char-system-stringcomparison)) * `bool EndsWith(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith?view=net-11.0#system-string-endswith(system-char)) * `IEnumerable EnumerateDirectories(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratedirectories?view=net-11.0#system-io-directory-enumeratedirectories(system-string-system-string-system-io-enumerationoptions)) * `IEnumerable EnumerateFiles(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=net-11.0#system-io-directory-enumeratefiles(system-string-system-string-system-io-enumerationoptions)) @@ -1343,13 +1345,19 @@ The class `Polyfill` includes the following extension methods: * `string[] GetFiles(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=net-11.0#system-io-directory-getfiles(system-string-system-string-system-io-enumerationoptions)) * `string[] GetFileSystemEntries(string, string, EnumerationOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.getfilesystementries?view=net-11.0#system-io-directory-getfilesystementries(system-string-system-string-system-io-enumerationoptions)) * `int GetHashCode(StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.gethashcode?view=net-11.0#system-string-gethashcode(system-stringcomparison)) + * `int IndexOf(char, int, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-int32-system-int32-system-stringcomparison)) + * `int IndexOf(char, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-int32-system-stringcomparison)) * `int IndexOf(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-stringcomparison)) + * `int LastIndexOf(char, int, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-int32-system-int32-system-stringcomparison)) + * `int LastIndexOf(char, int, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-int32-system-stringcomparison)) + * `int LastIndexOf(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-stringcomparison)) * `string ReplaceLineEndings(string)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.replacelineendings?view=net-11.0#system-string-replacelineendings(system-string)) * `string ReplaceLineEndings()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.replacelineendings?view=net-11.0#system-string-replacelineendings) * `string[] Split(char, int, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-char-system-int32-system-stringsplitoptions)) * `string[] Split(char, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-char-system-stringsplitoptions)) * `string[] Split(string, int, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-string-system-int32-system-stringsplitoptions)) * `string[] Split(string, StringSplitOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-11.0#system-string-split(system-string-system-stringsplitoptions)) + * `bool StartsWith(char, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.startswith?view=net-11.0#system-string-startswith(system-char-system-stringcomparison)) * `bool StartsWith(char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.startswith?view=net-11.0#system-string-startswith(system-char)) * `bool TryCopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.trycopyto?view=net-11.0) * `string Create(int, TState, System.Buffers.SpanAction)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.create?view=net-11.0#system-string-create-1(system-int32-0-system-buffers-spanaction((system-char-0)))) @@ -1850,7 +1858,7 @@ void ObjectDisposedExceptionExample(bool isDisposed) ObjectDisposedException.ThrowIf(isDisposed, typeof(Consume)); } ``` -snippet source | anchor +snippet source | anchor @@ -1869,7 +1877,7 @@ void EnsureExample(Order order, Customer customer, string customerId, string ema this.quantity = Ensure.NotNegativeOrZero(quantity); } ``` -snippet source | anchor +snippet source | anchor diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index 8e57c818..d3bdb417 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -89,6 +89,11 @@ class Consume type = typeof(InterpolatedStringHandlerAttribute); #endif type = typeof(StringSyntaxAttribute); +#if !NET7_0_OR_GREATER || NET11_0_OR_GREATER + var csharpSyntax = StringSyntaxAttribute.CSharp; + var fsharpSyntax = StringSyntaxAttribute.FSharp; + var vbSyntax = StringSyntaxAttribute.VisualBasic; +#endif type = typeof(DynamicallyAccessedMembersAttribute); type = typeof(DynamicDependencyAttribute); type = typeof(RequiresDynamicCodeAttribute); @@ -423,6 +428,7 @@ void Char_Methods() var isAsciiHexDigit = char.IsAsciiHexDigit('\u0066'); var isAsciiHexDigitLower = char.IsAsciiHexDigitLower('\u0063'); var isAsciiHexDigitUpper = char.IsAsciiHexDigitUpper('\u0041'); + var charEquals = 'A'.Equals('a', StringComparison.OrdinalIgnoreCase); } class WithMethods @@ -1093,8 +1099,17 @@ void String_Methods() var splitString = "a b".Split(" ", StringSplitOptions.RemoveEmptyEntries); splitString = "a b".Split(" ", 2, StringSplitOptions.RemoveEmptyEntries); + + var startsWithChar = "value".StartsWith('v', StringComparison.Ordinal); + var endsWithChar = "value".EndsWith('e', StringComparison.Ordinal); + var indexOfChar = "value".IndexOf('a', 1, StringComparison.Ordinal); + var indexOfCharCount = "value".IndexOf('a', 1, 3, StringComparison.Ordinal); + var lastIndexOfChar = "value".LastIndexOf('a', StringComparison.Ordinal); + var lastIndexOfCharStart = "value".LastIndexOf('a', 3, StringComparison.Ordinal); + var lastIndexOfCharStartCount = "value".LastIndexOf('a', 3, 2, StringComparison.Ordinal); } + #if !NoStringInterpolation && FeatureMemory void DefaultInterpolatedStringHandler_Methods() { diff --git a/src/Polyfill/Polyfill_Char.cs b/src/Polyfill/Polyfill_Char.cs new file mode 100644 index 00000000..c16c5a31 --- /dev/null +++ b/src/Polyfill/Polyfill_Char.cs @@ -0,0 +1,21 @@ +#if !NET11_0_OR_GREATER +namespace Polyfills; + +using System; + +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.char.equals?view=net-11.0#system-char-equals(system-char-system-stringcomparison) + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} + +#endif diff --git a/src/Polyfill/Polyfill_String.cs b/src/Polyfill/Polyfill_String.cs index d43abb9e..95efc5c9 100644 --- a/src/Polyfill/Polyfill_String.cs +++ b/src/Polyfill/Polyfill_String.cs @@ -135,6 +135,68 @@ public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; #endif +#if !NET11_0_OR_GREATER + + /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.startswith?view=net-11.0#system-string-startswith(system-char-system-stringcomparison) + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith?view=net-11.0#system-string-endswith(system-char-system-stringcomparison) + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-int32-system-stringcomparison) + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-11.0#system-string-indexof(system-char-system-int32-system-int32-system-stringcomparison) + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-stringcomparison) + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-int32-system-stringcomparison) + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof?view=net-11.0#system-string-lastindexof(system-char-system-int32-system-int32-system-stringcomparison) + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + +#endif + #if !NET6_0_OR_GREATER /// /// Replaces all newline sequences in the current string with . diff --git a/src/Polyfill/StringSyntaxAttribute.cs b/src/Polyfill/StringSyntaxAttribute.cs index 2797c51b..1942f48a 100644 --- a/src/Polyfill/StringSyntaxAttribute.cs +++ b/src/Polyfill/StringSyntaxAttribute.cs @@ -79,6 +79,15 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } #else [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute))] diff --git a/src/Split/net10.0/Polyfill_Char.cs b/src/Split/net10.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net10.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net10.0/Polyfill_String.cs b/src/Split/net10.0/Polyfill_String.cs new file mode 100644 index 00000000..dc72e38f --- /dev/null +++ b/src/Split/net10.0/Polyfill_String.cs @@ -0,0 +1,54 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Text; +using System.IO; +using System.Runtime.CompilerServices; +static partial class Polyfill +{ + /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); +} diff --git a/src/Split/net461/Polyfill_Char.cs b/src/Split/net461/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net461/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net461/Polyfill_String.cs b/src/Split/net461/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/net461/Polyfill_String.cs +++ b/src/Split/net461/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net461/StringSyntaxAttribute.cs b/src/Split/net461/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net461/StringSyntaxAttribute.cs +++ b/src/Split/net461/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net462/Polyfill_Char.cs b/src/Split/net462/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net462/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net462/Polyfill_String.cs b/src/Split/net462/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/net462/Polyfill_String.cs +++ b/src/Split/net462/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net462/StringSyntaxAttribute.cs b/src/Split/net462/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net462/StringSyntaxAttribute.cs +++ b/src/Split/net462/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net47/Polyfill_Char.cs b/src/Split/net47/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net47/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net47/Polyfill_String.cs b/src/Split/net47/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/net47/Polyfill_String.cs +++ b/src/Split/net47/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net47/StringSyntaxAttribute.cs b/src/Split/net47/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net47/StringSyntaxAttribute.cs +++ b/src/Split/net47/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net471/Polyfill_Char.cs b/src/Split/net471/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net471/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net471/Polyfill_String.cs b/src/Split/net471/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/net471/Polyfill_String.cs +++ b/src/Split/net471/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net471/StringSyntaxAttribute.cs b/src/Split/net471/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net471/StringSyntaxAttribute.cs +++ b/src/Split/net471/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net472/Polyfill_Char.cs b/src/Split/net472/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net472/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net472/Polyfill_String.cs b/src/Split/net472/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/net472/Polyfill_String.cs +++ b/src/Split/net472/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net472/StringSyntaxAttribute.cs b/src/Split/net472/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net472/StringSyntaxAttribute.cs +++ b/src/Split/net472/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net48/Polyfill_Char.cs b/src/Split/net48/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net48/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net48/Polyfill_String.cs b/src/Split/net48/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/net48/Polyfill_String.cs +++ b/src/Split/net48/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net48/StringSyntaxAttribute.cs b/src/Split/net48/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net48/StringSyntaxAttribute.cs +++ b/src/Split/net48/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net481/Polyfill_Char.cs b/src/Split/net481/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net481/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net481/Polyfill_String.cs b/src/Split/net481/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/net481/Polyfill_String.cs +++ b/src/Split/net481/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net481/StringSyntaxAttribute.cs b/src/Split/net481/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net481/StringSyntaxAttribute.cs +++ b/src/Split/net481/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net5.0/Polyfill_Char.cs b/src/Split/net5.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net5.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net5.0/Polyfill_String.cs b/src/Split/net5.0/Polyfill_String.cs index 028c9382..2f9a508f 100644 --- a/src/Split/net5.0/Polyfill_String.cs +++ b/src/Split/net5.0/Polyfill_String.cs @@ -20,6 +20,50 @@ public static bool TryCopyTo(this string target, Span destination) => target.AsSpan().TryCopyTo(destination); #endif /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/net5.0/StringSyntaxAttribute.cs b/src/Split/net5.0/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net5.0/StringSyntaxAttribute.cs +++ b/src/Split/net5.0/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net6.0/Polyfill_Char.cs b/src/Split/net6.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net6.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net6.0/Polyfill_String.cs b/src/Split/net6.0/Polyfill_String.cs new file mode 100644 index 00000000..dc72e38f --- /dev/null +++ b/src/Split/net6.0/Polyfill_String.cs @@ -0,0 +1,54 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Text; +using System.IO; +using System.Runtime.CompilerServices; +static partial class Polyfill +{ + /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); +} diff --git a/src/Split/net6.0/StringSyntaxAttribute.cs b/src/Split/net6.0/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/net6.0/StringSyntaxAttribute.cs +++ b/src/Split/net6.0/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/net7.0/Polyfill_Char.cs b/src/Split/net7.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net7.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net7.0/Polyfill_String.cs b/src/Split/net7.0/Polyfill_String.cs new file mode 100644 index 00000000..dc72e38f --- /dev/null +++ b/src/Split/net7.0/Polyfill_String.cs @@ -0,0 +1,54 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Text; +using System.IO; +using System.Runtime.CompilerServices; +static partial class Polyfill +{ + /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); +} diff --git a/src/Split/net8.0/Polyfill_Char.cs b/src/Split/net8.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net8.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net8.0/Polyfill_String.cs b/src/Split/net8.0/Polyfill_String.cs new file mode 100644 index 00000000..dc72e38f --- /dev/null +++ b/src/Split/net8.0/Polyfill_String.cs @@ -0,0 +1,54 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Text; +using System.IO; +using System.Runtime.CompilerServices; +static partial class Polyfill +{ + /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); +} diff --git a/src/Split/net9.0/Polyfill_Char.cs b/src/Split/net9.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/net9.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/net9.0/Polyfill_String.cs b/src/Split/net9.0/Polyfill_String.cs new file mode 100644 index 00000000..dc72e38f --- /dev/null +++ b/src/Split/net9.0/Polyfill_String.cs @@ -0,0 +1,54 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Text; +using System.IO; +using System.Runtime.CompilerServices; +static partial class Polyfill +{ + /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); +} diff --git a/src/Split/netcoreapp2.0/Polyfill_Char.cs b/src/Split/netcoreapp2.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/netcoreapp2.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/netcoreapp2.0/Polyfill_String.cs b/src/Split/netcoreapp2.0/Polyfill_String.cs index 89f33729..26afdec8 100644 --- a/src/Split/netcoreapp2.0/Polyfill_String.cs +++ b/src/Split/netcoreapp2.0/Polyfill_String.cs @@ -25,6 +25,50 @@ public static bool TryCopyTo(this string target, Span destination) => public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/netcoreapp2.0/StringSyntaxAttribute.cs b/src/Split/netcoreapp2.0/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/netcoreapp2.0/StringSyntaxAttribute.cs +++ b/src/Split/netcoreapp2.0/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/netcoreapp2.1/Polyfill_Char.cs b/src/Split/netcoreapp2.1/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/netcoreapp2.1/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/netcoreapp2.1/Polyfill_String.cs b/src/Split/netcoreapp2.1/Polyfill_String.cs index 028c9382..2f9a508f 100644 --- a/src/Split/netcoreapp2.1/Polyfill_String.cs +++ b/src/Split/netcoreapp2.1/Polyfill_String.cs @@ -20,6 +20,50 @@ public static bool TryCopyTo(this string target, Span destination) => target.AsSpan().TryCopyTo(destination); #endif /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/netcoreapp2.1/StringSyntaxAttribute.cs b/src/Split/netcoreapp2.1/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/netcoreapp2.1/StringSyntaxAttribute.cs +++ b/src/Split/netcoreapp2.1/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/netcoreapp2.2/Polyfill_Char.cs b/src/Split/netcoreapp2.2/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/netcoreapp2.2/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/netcoreapp2.2/Polyfill_String.cs b/src/Split/netcoreapp2.2/Polyfill_String.cs index 028c9382..2f9a508f 100644 --- a/src/Split/netcoreapp2.2/Polyfill_String.cs +++ b/src/Split/netcoreapp2.2/Polyfill_String.cs @@ -20,6 +20,50 @@ public static bool TryCopyTo(this string target, Span destination) => target.AsSpan().TryCopyTo(destination); #endif /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/netcoreapp2.2/StringSyntaxAttribute.cs b/src/Split/netcoreapp2.2/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/netcoreapp2.2/StringSyntaxAttribute.cs +++ b/src/Split/netcoreapp2.2/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/netcoreapp3.0/Polyfill_Char.cs b/src/Split/netcoreapp3.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/netcoreapp3.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/netcoreapp3.0/Polyfill_String.cs b/src/Split/netcoreapp3.0/Polyfill_String.cs index 028c9382..2f9a508f 100644 --- a/src/Split/netcoreapp3.0/Polyfill_String.cs +++ b/src/Split/netcoreapp3.0/Polyfill_String.cs @@ -20,6 +20,50 @@ public static bool TryCopyTo(this string target, Span destination) => target.AsSpan().TryCopyTo(destination); #endif /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/netcoreapp3.0/StringSyntaxAttribute.cs b/src/Split/netcoreapp3.0/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/netcoreapp3.0/StringSyntaxAttribute.cs +++ b/src/Split/netcoreapp3.0/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/netcoreapp3.1/Polyfill_Char.cs b/src/Split/netcoreapp3.1/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/netcoreapp3.1/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/netcoreapp3.1/Polyfill_String.cs b/src/Split/netcoreapp3.1/Polyfill_String.cs index 028c9382..2f9a508f 100644 --- a/src/Split/netcoreapp3.1/Polyfill_String.cs +++ b/src/Split/netcoreapp3.1/Polyfill_String.cs @@ -20,6 +20,50 @@ public static bool TryCopyTo(this string target, Span destination) => target.AsSpan().TryCopyTo(destination); #endif /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/netcoreapp3.1/StringSyntaxAttribute.cs b/src/Split/netcoreapp3.1/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/netcoreapp3.1/StringSyntaxAttribute.cs +++ b/src/Split/netcoreapp3.1/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/netstandard2.0/Polyfill_Char.cs b/src/Split/netstandard2.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/netstandard2.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/netstandard2.0/Polyfill_String.cs b/src/Split/netstandard2.0/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/netstandard2.0/Polyfill_String.cs +++ b/src/Split/netstandard2.0/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/netstandard2.0/StringSyntaxAttribute.cs b/src/Split/netstandard2.0/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/netstandard2.0/StringSyntaxAttribute.cs +++ b/src/Split/netstandard2.0/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/netstandard2.1/Polyfill_Char.cs b/src/Split/netstandard2.1/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/netstandard2.1/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/netstandard2.1/Polyfill_String.cs b/src/Split/netstandard2.1/Polyfill_String.cs index 028c9382..2f9a508f 100644 --- a/src/Split/netstandard2.1/Polyfill_String.cs +++ b/src/Split/netstandard2.1/Polyfill_String.cs @@ -20,6 +20,50 @@ public static bool TryCopyTo(this string target, Span destination) => target.AsSpan().TryCopyTo(destination); #endif /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/netstandard2.1/StringSyntaxAttribute.cs b/src/Split/netstandard2.1/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/netstandard2.1/StringSyntaxAttribute.cs +++ b/src/Split/netstandard2.1/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Split/uap10.0/Polyfill_Char.cs b/src/Split/uap10.0/Polyfill_Char.cs new file mode 100644 index 00000000..ff49813b --- /dev/null +++ b/src/Split/uap10.0/Polyfill_Char.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + /// + /// Determines whether the specified character is equal to the current character, using the specified comparison type. + /// + public static bool Equals(this char target, char other, StringComparison comparisonType) => + comparisonType switch + { + StringComparison.Ordinal => target == other, + StringComparison.OrdinalIgnoreCase => char.ToUpperInvariant(target) == char.ToUpperInvariant(other), + _ => target.ToString().Equals(other.ToString(), comparisonType) + }; +} diff --git a/src/Split/uap10.0/Polyfill_String.cs b/src/Split/uap10.0/Polyfill_String.cs index 25eb3502..bab55956 100644 --- a/src/Split/uap10.0/Polyfill_String.cs +++ b/src/Split/uap10.0/Polyfill_String.cs @@ -101,6 +101,50 @@ public static string[] Split(this string target, string separator, int count, St public static bool Contains(this string target, char value) => target.IndexOf(value) >= 0; /// + /// Determines whether this string instance starts with the specified character when compared using the specified comparison option. + /// + public static bool StartsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.StartsWith(value.ToString(), comparisonType); + /// + /// Determines whether the end of this string instance matches the specified character when compared using the specified comparison option. + /// + public static bool EndsWith(this string target, char value, StringComparison comparisonType) => + target.Length != 0 && target.EndsWith(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the first occurrence of the specified character in this string. + /// The search starts at a specified character position and examines a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int IndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.IndexOf(value.ToString(), startIndex, count, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, comparisonType); + /// + /// Reports the zero-based index of the last occurrence of a specified character within the current string. + /// The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. + /// A parameter specifies the type of search to use. + /// + public static int LastIndexOf(this string target, char value, int startIndex, int count, StringComparison comparisonType) => + target.LastIndexOf(value.ToString(), startIndex, count, comparisonType); + /// /// Replaces all newline sequences in the current string with . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Split/uap10.0/StringSyntaxAttribute.cs b/src/Split/uap10.0/StringSyntaxAttribute.cs index 0fcc5657..39eae62d 100644 --- a/src/Split/uap10.0/StringSyntaxAttribute.cs +++ b/src/Split/uap10.0/StringSyntaxAttribute.cs @@ -60,4 +60,10 @@ public StringSyntaxAttribute(string syntax, params object?[] arguments) public const string Uri = nameof(Uri); /// The syntax identifier for strings containing XML. public const string Xml = nameof(Xml); + /// The syntax identifier for strings containing C# code. + public const string CSharp = "C#"; + /// The syntax identifier for strings containing F# code. + public const string FSharp = "F#"; + /// The syntax identifier for strings containing Visual Basic code. + public const string VisualBasic = "Visual Basic"; } diff --git a/src/Tests/PolyfillTests_String.cs b/src/Tests/PolyfillTests_String.cs index 7255d9f3..0744f574 100644 --- a/src/Tests/PolyfillTests_String.cs +++ b/src/Tests/PolyfillTests_String.cs @@ -117,4 +117,66 @@ public async Task IndexOfCharStringComparison() await Assert.That("Value".IndexOf('v', StringComparison.OrdinalIgnoreCase)).IsEqualTo(0); await Assert.That("Value".IndexOf('v', StringComparison.Ordinal)).IsEqualTo(-1); } + + [Test] + public async Task StartsWithCharStringComparison() + { + await Assert.That("Value".StartsWith('v', StringComparison.OrdinalIgnoreCase)).IsTrue(); + await Assert.That("Value".StartsWith('v', StringComparison.Ordinal)).IsFalse(); + await Assert.That("Value".StartsWith('V', StringComparison.Ordinal)).IsTrue(); + await Assert.That("".StartsWith('v', StringComparison.Ordinal)).IsFalse(); + } + + [Test] + public async Task EndsWithCharStringComparison() + { + await Assert.That("valuE".EndsWith('e', StringComparison.OrdinalIgnoreCase)).IsTrue(); + await Assert.That("valuE".EndsWith('e', StringComparison.Ordinal)).IsFalse(); + await Assert.That("valuE".EndsWith('E', StringComparison.Ordinal)).IsTrue(); + await Assert.That("".EndsWith('e', StringComparison.Ordinal)).IsFalse(); + } + + [Test] + public async Task IndexOfCharStartIndexStringComparison() + { + await Assert.That("abcabc".IndexOf('b', 2, StringComparison.Ordinal)).IsEqualTo(4); + await Assert.That("ABCABC".IndexOf('b', 0, StringComparison.OrdinalIgnoreCase)).IsEqualTo(1); + } + + [Test] + public async Task IndexOfCharStartIndexCountStringComparison() + { + await Assert.That("abcabc".IndexOf('b', 0, 3, StringComparison.Ordinal)).IsEqualTo(1); + await Assert.That("abcabc".IndexOf('b', 0, 1, StringComparison.Ordinal)).IsEqualTo(-1); + } + + [Test] + public async Task LastIndexOfCharStringComparison() + { + await Assert.That("abcabc".LastIndexOf('b', StringComparison.Ordinal)).IsEqualTo(4); + await Assert.That("ABCABC".LastIndexOf('b', StringComparison.OrdinalIgnoreCase)).IsEqualTo(4); + await Assert.That("abcabc".LastIndexOf('x', StringComparison.Ordinal)).IsEqualTo(-1); + } + + [Test] + public async Task LastIndexOfCharStartIndexStringComparison() + { + await Assert.That("abcabc".LastIndexOf('b', 3, StringComparison.Ordinal)).IsEqualTo(1); + await Assert.That("ABCABC".LastIndexOf('b', 5, StringComparison.OrdinalIgnoreCase)).IsEqualTo(4); + } + + [Test] + public async Task LastIndexOfCharStartIndexCountStringComparison() + { + await Assert.That("abcabc".LastIndexOf('b', 5, 3, StringComparison.Ordinal)).IsEqualTo(4); + await Assert.That("abcabc".LastIndexOf('a', 5, 3, StringComparison.Ordinal)).IsEqualTo(3); + } + + [Test] + public async Task CharEqualsStringComparison() + { + await Assert.That('A'.Equals('a', StringComparison.OrdinalIgnoreCase)).IsTrue(); + await Assert.That('A'.Equals('a', StringComparison.Ordinal)).IsFalse(); + await Assert.That('A'.Equals('A', StringComparison.Ordinal)).IsTrue(); + } }