Skip to content

Commit f9f735d

Browse files
committed
Added overload with char* buffer
1 parent ef414a8 commit f9f735d

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
### Added
10+
- `Append(char* value, int length)` overload.
11+
912
## [1.9.0] - 2022-11-18
1013

1114
### Added

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public void Append(scoped ReadOnlySpan<char> str)
3939
bufferPosition += str.Length;
4040
}
4141

42+
/// <summary>
43+
/// Appends a character buffer to this builder.
44+
/// </summary>
45+
/// <param name="value">The pointer to the start of the buffer.</param>
46+
/// <param name="length">The number of characters in the buffer.</param>
47+
public unsafe void Append(char* value, int length)
48+
{
49+
Append(new ReadOnlySpan<char>(value, length));
50+
}
51+
4252
/// <summary>
4353
/// Adds the default new line separator.
4454
/// </summary>

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilder.Append.Tests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,18 @@ public void ShouldAppendBoolean(bool value, string expected)
141141

142142
builder.ToString().Should().Be(expected);
143143
}
144+
145+
[Fact]
146+
public unsafe void ShouldAddCharPointer()
147+
{
148+
using var builder = new ValueStringBuilder();
149+
const string text = "Hello World";
150+
151+
fixed (char* pText = text)
152+
{
153+
builder.Append(pText, 5);
154+
}
155+
156+
builder.ToString().Should().Be("Hello");
157+
}
144158
}

0 commit comments

Comments
 (0)