-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
C#: Fix StringExtensions.CompareTo
IndexOutOfRangeException
#91203
Conversation
StringExtensions.CompareTo
IndexOutOfRangeException
facbf67
to
2de3738
Compare
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.
Thanks a lot for contributing to the .NET module!
This looks great already, I'm only requesting a few changes based on the discussion in #91118.
modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Outdated
Show resolved
Hide resolved
thank you for the improvements! I'll update the documentation and squash the changes |
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.
Just a few comments about the documentation to make it sound a bit less repetitive, taking inspiration from the C# documentation.
modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Outdated
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Outdated
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Outdated
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Outdated
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Outdated
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Outdated
Show resolved
Hide resolved
fixes godotengine#91118 marked CompareTo obsolete dropped CompareTo [-1,1] range Co-authored-by: Raul Santos <raulsntos@gmail.com>
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.
Looks good to me, thanks! Just want to confirm that we agree on the new implementation.
toIndex++; | ||
} | ||
} | ||
return string.Compare(instance, to, !caseSensitive); |
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.
@paulloz Are you OK with using this overload in the new implementation? It will use the current culture: https://github.com/dotnet/runtime/blob/ee93104aa0e7ac77ca7e4c6db9873356a9e3e622/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs#L210
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.
Yep, I think it's fine. Anyone is then free to use another locale if they wish anyway 👍
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 was not thinking, but calling string.Compare(string, string, bool)
(instead of string.Compare(string, string, bool, CultureInfo)
) warns with CA1304
and CA1309
.
Thanks! And congrats for your first merged Godot contribution 🎉 |
/// </summary> | ||
/// <param name="instance">The string to compare.</param> | ||
/// <param name="to">The other string to compare.</param> | ||
/// <param name="caseSensitive"> | ||
/// If <see langword="true"/>, the comparison will be case sensitive. | ||
/// </param> | ||
/// <returns>-1 if less, 0 if equal and +1 if greater.</returns> | ||
/// <returns>An integer that indicates the lexical relationship between the two comparands.</returns> | ||
[Obsolete("Use string.Compare instead.")] |
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.
It didn't occur to me while reviewing earlier, but this means the calls in CasecmpTo
and NocasecmpTo
now warn with CS0618
. It probably should be silenced.
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.
Oh oops, I totally missed this. Yeah, or we can also call the BCL's string.Compare
directly.
replaced StringExtensions.CompareTo which expects null terminated strings with String.Compare.
fixes #91118
I tested the correction and found that it matches the result from the old method 100% of the time.
Ran test: TestCompareToDifference.cs.txt