Skip to content
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

[3.x] C#: Deprecate string extensions that will be removed in 4.x #69304

Merged
merged 1 commit into from
Nov 30, 2022

Conversation

raulsntos
Copy link
Member

  • Equivalent of C#: Cleanup and sync StringExtensions with core #67031 for 3.x that avoids breaking compatibility.
  • Deprecated Length in favor of the string.Length property.
  • Deprecated Insert in favor of the existing instance method with the same signature.
  • Deprecated Erase in favor of StringBuilder.Remove.
  • Deprecated ToLower and ToUpper in favor of the instance methods with the same signature.
  • Deprecated BeginsWith in favor of string.StartsWith.
  • Deprecated EndsWith in favor of the instance method with the same signature.
  • Deprecated Empty in favor of string.IsNullOrEmpty.
  • Deprecated OrdAt in favor of the string[int] indexer.
  • Deprecated LStrip and RStrip in favor of string.TrimStart and string.TrimEnd.

Note
About the deprecation of LStrip / RStrip, these methods don't trim when the chars parameter is "" (no characters) but the string.TrimStart / string.TrimEnd methods trim whitespace when the trimChars parameter is an empty array.
This behavior change is probably not a common scenario but it's worth taking in consideration:

string str = "Hello World";
str.TrimStart(); // Removes whitespace
str.LStrip(""); // Removes nothing

Note
About FindLast, the C++ method was removed in 4.0, in 3.x its implementation was replaced with a call to RFind so they are the same thing but it doesn't break compatibility.
In C# FindLast is implemented as a call to string.LastIndexOf, while RFind is a PInvoke. This means recommending users in 3.x to switch to RFind will result in worse performance.
Should we instead recommend users to switch to string.LastIndexOf even if RFind still exists in 4.0? In 4.0 the RFind implementation has been replaced by a call to string.LastIndexOf but I'm not sure we want to make the same change in 3.x.

- Deprecated `Length` in favor of the `string.Length` property.
- Deprecated `Insert` in favor of the existing instance method with the same signature.
- Deprecated `Erase` in favor of `StringBuilder.Remove`.
- Deprecated `ToLower` and `ToUpper` in favor of the instance methods with the same signature.
- Deprecated `BeginsWith` in favor of `string.StartsWith`.
- Deprecated `EndsWith` in favor of the instance method with the same signature.
- Deprecated `Empty` in favor of `string.IsNullOrEmpty`.
- Deprecated `OrdAt` in favor of the `string[int]` indexer.
- Deprecated `LStrip` and `RStrip` in favor of `string.TrimStart` and `string.TrimEnd`.
@raulsntos raulsntos added this to the 3.x milestone Nov 28, 2022
@raulsntos raulsntos requested a review from a team November 28, 2022 17:33
@akien-mga akien-mga modified the milestones: 3.x, 3.6 Nov 30, 2022
@akien-mga akien-mga merged commit 0693260 into godotengine:3.x Nov 30, 2022
@akien-mga
Copy link
Member

Thanks!

@raulsntos raulsntos deleted the dotnet/string-extensions-3.x branch November 30, 2022 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants