Skip to content

Commit 67bd592

Browse files
committed
feat: Added Equals comparison with Span
1 parent 683916b commit 67bd592

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
### Added
10+
11+
- Added `Equals(ReadOnlySpan<char>)` overload
12+
913
### Changed
1014

1115
- Slight improvement when appending nullable types to the string builder

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

+7
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ public readonly int LastIndexOf(ReadOnlySpan<char> word, int startIndex)
273273
[MethodImpl(MethodImplOptions.AggressiveInlining)]
274274
public readonly bool Contains(ReadOnlySpan<char> word) => IndexOf(word) != -1;
275275

276+
/// <summary>
277+
/// Returns a value indicating whether the characters in this instance are equal to the characters in a specified read-only character span.
278+
/// </summary>
279+
/// <param name="span">The character span to compare with the current instance.</param>
280+
/// <returns><c>true</c> if the characters are equal to this instance, otherwise <c>false</c>.</returns>
281+
public readonly bool Equals(ReadOnlySpan<char> span) => span.SequenceEqual(AsSpan());
282+
276283
/// <summary>
277284
/// Disposes the instance and returns rented buffer from an array pool if needed.
278285
/// </summary>

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilderTests.cs

+12
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,16 @@ public void ConcatBooleanWithNumber()
440440

441441
result.Should().Be("True1");
442442
}
443+
444+
[Theory]
445+
[InlineData("Hello", true)]
446+
[InlineData("Hallo", false)]
447+
public void GivenReadOnlySpan_WhenCallingEquals_ThenReturningWhenEqual(string input, bool expected)
448+
{
449+
using var builder = new ValueStringBuilder("Hello");
450+
451+
var isEqual = builder.Equals(input);
452+
453+
isEqual.Should().Be(expected);
454+
}
443455
}

0 commit comments

Comments
 (0)