Skip to content

Commit ebc9c5a

Browse files
committed
feat: Added ctor overload to pass in a string
1 parent b20250a commit ebc9c5a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
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+
### Addeed
10+
11+
- Added overload which allows an initial string for the ValueStringBuilder
12+
913
## [1.5.1] - 2022-11-05
1014

1115
### Added

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ public ValueStringBuilder(Span<char> initialBuffer)
4141
arrayFromPool = null;
4242
}
4343

44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="ValueStringBuilder"/> struct.
46+
/// </summary>
47+
/// <param name="initialText">The initial text used to initialize this instance. If <paramref name="initialText"/> is <c>null</c>
48+
/// the <see cref="ValueStringBuilder"/> will return an empty string (<see cref="string.Empty"/>).
49+
/// </param>
50+
public ValueStringBuilder(ReadOnlySpan<char> initialText)
51+
{
52+
Append(initialText);
53+
}
54+
4455
/// <summary>
4556
/// Gets the current length of the represented string.
4657
/// </summary>

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilderTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,12 @@ public void ConcatDifferentTypesWithFiveArguments()
384384

385385
result.Should().Be("Test1234");
386386
}
387+
388+
[Fact]
389+
public void ShouldAcceptInitialCharBuffer()
390+
{
391+
var result = new ValueStringBuilder("Hello World").ToString();
392+
393+
result.Should().Be("Hello World");
394+
}
387395
}

0 commit comments

Comments
 (0)