Skip to content

Commit c90d0fd

Browse files
committed
Add Equals(ReadOnlySpan<char>, StringComparison)
1 parent 7a93115 commit c90d0fd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public readonly int LastIndexOf(ReadOnlySpan<char> word, int startIndex)
243243
}
244244

245245
/// <summary>
246-
/// Returns a value indicating whether a specified substring occurs within this string.
246+
/// Returns whether a specified substring occurs within this string.
247247
/// </summary>
248248
/// <param name="word">Word to look for in this string.</param>
249249
/// <returns>True if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false.</returns>
@@ -254,12 +254,21 @@ public readonly int LastIndexOf(ReadOnlySpan<char> word, int startIndex)
254254
public readonly bool Contains(ReadOnlySpan<char> word) => IndexOf(word) != -1;
255255

256256
/// <summary>
257-
/// Returns a value indicating whether the characters in this instance are equal to the characters in a specified read-only character span.
257+
/// Returns whether the characters in this builder are equal to the characters in the given span.
258258
/// </summary>
259259
/// <param name="span">The character span to compare with the current instance.</param>
260260
/// <returns><see langword="true"/> if the characters are equal to this instance, otherwise <see langword="false"/>.</returns>
261261
[MethodImpl(MethodImplOptions.AggressiveInlining)]
262-
public readonly bool Equals(ReadOnlySpan<char> span) => span.SequenceEqual(AsSpan());
262+
public readonly bool Equals(ReadOnlySpan<char> span) => span.Equals(AsSpan(), StringComparison.Ordinal);
263+
264+
/// <summary>
265+
/// Returns whether the characters in this builder are equal to the characters in the given span according to the given comparison type.
266+
/// </summary>
267+
/// <param name="span">The character span to compare with the current instance.</param>
268+
/// <param name="comparisonType">The way to compare the sequences of characters.</param>
269+
/// <returns><see langword="true"/> if the characters are equal to this instance, otherwise <see langword="false"/>.</returns>
270+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
271+
public readonly bool Equals(ReadOnlySpan<char> span, StringComparison comparisonType) => span.Equals(AsSpan(), comparisonType);
263272

264273
/// <summary>
265274
/// Disposes the instance and returns the rented buffer to the array pool if needed.

0 commit comments

Comments
 (0)