Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0f5ba8a
Add missing overloads
Joy-less Sep 30, 2025
6e63506
Add refs to added missing overloads
Joy-less Sep 30, 2025
77fa228
Fix IndexOf/LastIndexOf char OrdinalIgnoreCase
Joy-less Oct 1, 2025
444d4b8
Add tests & fixes
Joy-less Oct 1, 2025
20b8733
Fix Copilot suggestions
Joy-less Oct 2, 2025
8166e82
Rename `right` to `other`
Joy-less Oct 2, 2025
45fd035
Make `LastIndexOf` public
Joy-less Oct 2, 2025
6853c73
Add commented-out test
Joy-less Oct 2, 2025
0812e82
Rename `right` to `other` in refs
Joy-less Oct 2, 2025
f2e0027
Add doc comments to IndexOf char
Joy-less Oct 2, 2025
b7956ac
Update docs from `-1` to `a negative value (e.g. -1)`
Joy-less Oct 2, 2025
832a748
Refactor duplicate return statements
Joy-less Oct 2, 2025
347d59c
Add foreign cases to char Equals StringComparison test
Joy-less Oct 2, 2025
97dba93
Add foreign/empty cases to IndexOf char/Rune
Joy-less Oct 2, 2025
4d126f4
Fix length bounds
Joy-less Oct 2, 2025
2d255b5
Add convert to string test case
Joy-less Oct 2, 2025
48cecde
Fix \0 edge case?
Joy-less Oct 2, 2025
d31505c
Add more convert to string test cases
Joy-less Oct 2, 2025
d2dbd8f
Remove most likely incorrect fix
Joy-less Oct 3, 2025
54c2f80
Add `Length == 0` check to last index of methods
Joy-less Oct 4, 2025
8abd5d3
Merge branch 'main' into add-missing-overloads-to-flow-rune-proposal
tarekgh Oct 5, 2025
7447cee
Simplify `AsSpan` calls
Joy-less Oct 5, 2025
8afe6a6
Fix invalid test arguments
Joy-less Oct 5, 2025
4aa3a29
Add `IsNotAndroid` checks for Turkish "i" tests
Joy-less Oct 6, 2025
b97b5c1
Also add `IsNotAndroid` checks for `char` `EqualsTest`
Joy-less Oct 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/libraries/System.Private.CoreLib/src/System/Char.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,22 @@ public bool Equals(char obj)
return m_value == obj;
}

internal bool Equals(char right, StringComparison comparisonType)
/// <summary>
/// Returns a value that indicates whether the current instance and a specified character are equal using the specified comparison option.
/// </summary>
/// <param name="other">The character to compare with the current instance.</param>
/// <param name="comparisonType">One of the enumeration values that specifies the rules to use in the comparison.</param>
/// <returns><see langword="true"/> if the current instance and <paramref name="other"/> are equal; otherwise, <see langword="false"/>.</returns>
public bool Equals(char other, StringComparison comparisonType)
{
switch (comparisonType)
{
case StringComparison.Ordinal:
return Equals(right);
return Equals(other);
default:
ReadOnlySpan<char> leftCharsSlice = [this];
ReadOnlySpan<char> rightCharsSlice = [right];
return leftCharsSlice.Equals(rightCharsSlice, comparisonType);
ReadOnlySpan<char> thisCharsSlice = [this];
ReadOnlySpan<char> otherCharsSlice = [other];
return thisCharsSlice.Equals(otherCharsSlice, comparisonType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,10 @@ internal static bool NonPackedContainsValueType<T>(ref T searchSpace, T value, i
internal static int IndexOfChar(ref char searchSpace, char value, int length)
=> IndexOfValueType(ref Unsafe.As<char, short>(ref searchSpace), (short)value, length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int LastIndexOfChar(ref char searchSpace, char value, int length)
=> LastIndexOfValueType(ref Unsafe.As<char, short>(ref searchSpace), (short)value, length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int NonPackedIndexOfChar(ref char searchSpace, char value, int length) =>
NonPackedIndexOfValueType<short, DontNegate<short>>(ref Unsafe.As<char, short>(ref searchSpace), (short)value, length);
Expand Down Expand Up @@ -1655,6 +1659,10 @@ internal static int NonPackedIndexOfValueType<TValue, TNegator>(ref TValue searc
internal static int IndexOfAnyChar(ref char searchSpace, char value0, char value1, int length)
=> IndexOfAnyValueType(ref Unsafe.As<char, short>(ref searchSpace), (short)value0, (short)value1, length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int LastIndexOfAnyChar(ref char searchSpace, char value0, char value1, int length)
=> LastIndexOfAnyValueType(ref Unsafe.As<char, short>(ref searchSpace), (short)value0, (short)value1, length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int IndexOfAnyValueType<T>(ref T searchSpace, T value0, T value1, int length) where T : struct, INumber<T>
=> IndexOfAnyValueType<T, DontNegate<T>>(ref searchSpace, value0, value1, length);
Expand Down
Loading
Loading