Skip to content

Commit dd39217

Browse files
authored
Merge pull request #234 from Joy-less/add-equals-stringcomparison
Add Equals(ReadOnlySpan<char>, StringComparison)
2 parents 07afdad + 704fed2 commit dd39217

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Added `Equals(ReadOnlySpan<char>, StringComparison)` (by @Joy-less in #234)
12+
913
### Changed
1014

15+
- Improved `Equals(ReadOnlySpan<char>)` (by @Joy-less in #234)
1116
- Added performance short-circuit when span is empty in `Append(ReadOnlySpan<char>)`, `AppendSpan(int)`, `Insert(int, ReadOnlySpan<char>)` in #233 (by @Joy-less)
1217

1318
## [2.2.0] - 2025-01-25

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

+12-3
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)