-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add methods from #27912 (Flow System.Text.Rune through more APIs) #117168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a set of new API overloads to support System.Text.Rune across various string and text manipulation APIs, addressing methods such as Equals, Contains, IndexOf/LastIndexOf, Replace, Trim, Append, Insert, and Write. The changes span multiple libraries including System.Runtime and System.Private.CoreLib to fully integrate rune-based operations.
- Added overloads for string comparison methods accepting System.Text.Rune.
- Introduced new methods on StringBuilder, TextWriter, and TextInfo to handle rune conversion and manipulation.
- Updated internal string splitting and trimming routines to support rune separators and trim characters.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/libraries/System.Runtime/ref/System.Runtime.cs | Added new overloads for string API methods accepting System.Text.Rune and StringComparison. |
src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs | Added Append/Insert/Replace methods with System.Text.Rune and Rune retrieval overloads. |
src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs | Updated Equals implementations and added new overloads for comparing Runes with StringComparison. |
src/libraries/System.Private.CoreLib/src/System/String.Searching.cs | Provided new overloads of Contains, IndexOf, and LastIndexOf for System.Text.Rune with careful iteration over surrogates. |
src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs | Added Replace, Split, and Trim overloads using System.Text.Rune for enhanced string manipulation. |
src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs | Extended StartsWith and EndsWith to support System.Text.Rune comparisons. |
src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs | Integrated Write and WriteLine overloads that accept System.Text.Rune. |
src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs | Implemented ToLower and ToUpper for System.Text.Rune conversions. |
src/libraries/System.Private.CoreLib/src/System/Char.cs | Added an overload for Equals accepting a StringComparison using modern array initialization. |
Comments suppressed due to low confidence (1)
src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs:2850
- In GetRuneAt(int index), consider throwing a more specific exception type (such as ArgumentOutOfRangeException) rather than a generic Exception for improved clarity and consistency with API design.
throw new Exception($"Unable to get rune at {index}.");
src/libraries/System.Private.CoreLib/src/System/String.Searching.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Tagging subscribers to this area: @dotnet/area-system-runtime |
@stephentoub - Since this has been open as long as it has, I wanted to check with you that we should still pursue adding the Rune overloads. Any concerns or hesitations? |
@jeffhandley I have made some changes to my PR:
I think #111170 is a relevant pull request to this one. Also, the original creator of the API proposals for both this pull request and the above pull request has this on their profile:
|
@Joy-less I'll get into this PR in the next few days. Thanks! |
@Joy-less do you compile and run the tests locally before submitting changes? curious to know 😄. |
I actually added these to an existing test, do you want them separate? |
No haha, I'm not sure how especially with the lack of .NET 10.0 on my system and issues installing it. |
You don't need to install that. You can do:
I'll try to clone your branch tomorrow and run it myself, would be faster push fixes 😄 |
This works with a single character; we need to test surrogate pairs too. This is why I suggested doing something like the one using the string separator. |
…into rune-overloads
@Joy-less I pushed some changes to fix some behavior and ensure the runtime tests are passing now with no problem. Please take a look and let me know if there is anything else you want to add before I take a last look tomorrow and try to merge. Thanks! |
|
||
return SplitInternal(separatorChars, count, options); | ||
// Ensure matching the string separator overload. | ||
return count <= 1 || Length == 0 ? CreateSplitArrayOfThisAsSoleValue(options, count) : Split(runeSeparator, count, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be easier to read with brackets:
(count <= 1 || Length == 0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change it if you want, 😄
public string[] Split(Rune separator, int count, StringSplitOptions options = StringSplitOptions.None) | ||
{ | ||
if (Length == 0) | ||
ReadOnlySpan<char> runeSeparator = separator.AsSpan(stackalloc char[Rune.MaxUtf16CharsPerRune]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should be separatorChars
instead of runeSeparator
to be consistent with the other implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chars
can indicate multiple separators, I wanted to be clear this is a single separator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about separatorSpan
? runeSeparator
implies that it's separator
typed as a Rune
which is actually the opposite of the case.
I think that's everything done now. Let me know if there's something else I missed or need to look at. Thanks for your diligence. |
Supercedes #111815.
This time the methods are fully implemented and ready to go, and the ref assemblies are added to match the implementations.