Skip to content

Commit 2e2212a

Browse files
Add Span<char> Equals overloads for nullable string
Added two Equals extension method overloads to TextExtensions, enabling Span<char> and ReadOnlySpan<char> comparisons with nullable strings using StringComparison. These handle null strings safely and delegate to existing span-based logic.
1 parent f8e8c50 commit 2e2212a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Source/Extensions.Equals.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public static bool Equals(this Span<char> source, StringSegment other, StringCom
3434
};
3535
}
3636

37+
// Cover the edge case of string null:
38+
39+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
40+
public static bool Equals(this Span<char> source, string? other, StringComparison comparisonType)
41+
=> other is not null && source.Equals(other.AsSpan(), comparisonType);
42+
43+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
44+
public static bool Equals(this ReadOnlySpan<char> source, string? other, StringComparison comparisonType)
45+
=> other is not null && source.Equals(other.AsSpan(), comparisonType);
46+
3747
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
3848
public static bool Equals(this Span<char> source, ReadOnlySpan<char> other, StringComparison comparisonType)
3949
{

0 commit comments

Comments
 (0)