Skip to content

Commit 074792e

Browse files
committed
add: New api
1 parent 30b15d3 commit 074792e

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public void AppendLine(ReadOnlySpan<char> str)
101101
/// <returns>True, if the copy was successful, otherwise false.</returns>
102102
public bool TryCopyTo(Span<char> destination) => buffer[..bufferPosition].TryCopyTo(destination);
103103

104+
public void Clear()
105+
{
106+
buffer.Clear();
107+
bufferPosition = 0;
108+
}
109+
104110
private void Grow(int capacity = 0)
105111
{
106112
var currentSize = buffer.Length;

src/LinkDotNet.StringBuilder/ValueStringBuilderExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class ValueStringBuilderExtensions
1010
/// </summary>
1111
/// <param name="builder">The builder from which the new instance is derived.</param>
1212
/// <returns>A new <see cref="System.Text.StringBuilder"/> instance with the string represented
13-
/// by this <see cref="builder"/>.
13+
/// by this <paramref name="builder"/>.
1414
/// </returns>
1515
public static System.Text.StringBuilder ToStringBuilder(ref this ValueStringBuilder builder)
1616
{
@@ -20,11 +20,11 @@ public static System.Text.StringBuilder ToStringBuilder(ref this ValueStringBuil
2020
}
2121

2222
/// <summary>
23-
/// Creates a new <see cref="ValueStringBuilder"/> from the given <see cref="builder"/>.
23+
/// Creates a new <see cref="ValueStringBuilder"/> from the given <paramref name="builder"/>.
2424
/// </summary>
2525
/// <param name="builder">The builder from which the new instance is derived.</param>
2626
/// <returns>A new <see cref="ValueStringBuilder"/> instance with the string represented by this <see cref="builder"/>.</returns>
27-
/// <exception cref="ArgumentNullException">Throws if <see cref="builder"/> is null.</exception>
27+
/// <exception cref="ArgumentNullException">Throws if <paramref name="builder"/> is null.</exception>
2828
public static ValueStringBuilder ToValueStringBuilder(this System.Text.StringBuilder? builder)
2929
{
3030
if (builder == null)

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilderTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,24 @@ public void ShouldReturnLength()
120120

121121
length.Should().Be(5);
122122
}
123+
124+
[Fact]
125+
public void ShouldClear()
126+
{
127+
var stringBuilder = new ValueStringBuilder();
128+
stringBuilder.Append("Hello");
129+
130+
stringBuilder.Clear();
131+
132+
stringBuilder.Length.Should().Be(0);
133+
stringBuilder.ToString().Should().Be(string.Empty);
134+
}
135+
136+
[Fact]
137+
public void ShouldReturnEmptyStringWhenInitialized()
138+
{
139+
var stringBuilder = new ValueStringBuilder();
140+
141+
stringBuilder.ToString().Should().Be(string.Empty);
142+
}
123143
}

0 commit comments

Comments
 (0)