godot icon indicating copy to clipboard operation
godot copied to clipboard

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

Open raulsntos opened this issue 2 years ago • 0 comments

  • Equivalent of #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.

raulsntos avatar Nov 28 '22 17:11 raulsntos