Skip to content

Commit ae30c9d

Browse files
committed
Corrected documentation and added Guid Insert
1 parent ff8b948 commit ae30c9d

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
99
### Added
1010

1111
- `ToString(startIndex, length)` to get a substring from the builder
12-
- `Append(Guid guid)` as new overload
12+
- `Append(Guid guid)` and `Insert(Guid guid)` as new overload
1313

1414
## [1.6.2] - 2022-11-11
1515

src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,54 @@ public ref partial struct ValueStringBuilder
88
/// Insert the string representation of the boolean to the builder at the given index.
99
/// </summary>
1010
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
11-
/// <param name="value">String to insert into this builder.</param>
11+
/// <param name="value">Boolean to insert into this builder.</param>
1212
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1313
public void Insert(int index, bool value) => Insert(index, value.ToString());
1414

1515
/// <summary>
1616
/// Insert the string representation of the char to the builder at the given index.
1717
/// </summary>
1818
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
19-
/// <param name="value">String to insert into this builder.</param>
19+
/// <param name="value">Character to insert into this builder.</param>
2020
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2121
public void Insert(int index, char value) => InsertSpanFormattable(index, value);
2222

2323
/// <summary>
2424
/// Insert the string representation of the signed byte to the builder at the given index.
2525
/// </summary>
2626
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
27-
/// <param name="value">String to insert into this builder.</param>
27+
/// <param name="value">Signed byte to insert into this builder.</param>
2828
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2929
public void Insert(int index, sbyte value) => InsertSpanFormattable(index, value);
3030

3131
/// <summary>
3232
/// Insert the string representation of the byte to the builder at the given index.
3333
/// </summary>
3434
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
35-
/// <param name="value">String to insert into this builder.</param>
35+
/// <param name="value">Byte to insert into this builder.</param>
3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3737
public void Insert(int index, byte value) => InsertSpanFormattable(index, value);
3838

3939
/// <summary>
4040
/// Insert the string representation of the short to the builder at the given index.
4141
/// </summary>
4242
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
43-
/// <param name="value">String to insert into this builder.</param>
43+
/// <param name="value">Short to insert into this builder.</param>
4444
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4545
public void Insert(int index, short value) => InsertSpanFormattable(index, value);
4646

4747
/// <summary>
4848
/// Insert the string representation of the integer to the builder at the given index.
4949
/// </summary>
5050
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
51-
/// <param name="value">String to insert into this builder.</param>
51+
/// <param name="value">Integer to insert into this builder.</param>
5252
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5353
public void Insert(int index, int value) => InsertSpanFormattable(index, value);
5454

5555
/// <summary>
5656
/// Insert the string representation of the long to the builder at the given index.
5757
/// </summary>
58-
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
58+
/// <param name="index">Long where <paramref name="value"/> should be inserted.</param>
5959
/// <param name="value">String to insert into this builder.</param>
6060
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6161
public void Insert(int index, long value) => InsertSpanFormattable(index, value);
@@ -64,26 +64,34 @@ public ref partial struct ValueStringBuilder
6464
/// Insert the string representation of the float to the builder at the given index.
6565
/// </summary>
6666
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
67-
/// <param name="value">String to insert into this builder.</param>
67+
/// <param name="value">Float to insert into this builder.</param>
6868
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6969
public void Insert(int index, float value) => InsertSpanFormattable(index, value);
7070

7171
/// <summary>
7272
/// Insert the string representation of the double to the builder at the given index.
7373
/// </summary>
7474
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
75-
/// <param name="value">String to insert into this builder.</param>
75+
/// <param name="value">Double to insert into this builder.</param>
7676
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7777
public void Insert(int index, double value) => InsertSpanFormattable(index, value);
7878

7979
/// <summary>
8080
/// Insert the string representation of the decimal to the builder at the given index.
8181
/// </summary>
8282
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
83-
/// <param name="value">String to insert into this builder.</param>
83+
/// <param name="value">Decimal to insert into this builder.</param>
8484
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8585
public void Insert(int index, decimal value) => InsertSpanFormattable(index, value);
8686

87+
/// <summary>
88+
/// Insert the string representation of the Guid to the builder at the given index.
89+
/// </summary>
90+
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
91+
/// <param name="value">Guid to insert into this builder.</param>
92+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93+
public void Insert(int index, Guid value) => InsertSpanFormattable(index, value);
94+
8795
/// <summary>
8896
/// Appends the string representation of the boolean to the builder.
8997
/// </summary>
@@ -118,7 +126,7 @@ public void Insert(int index, scoped ReadOnlySpan<char> value)
118126
}
119127

120128
[MethodImpl(MethodImplOptions.AggressiveInlining)]
121-
private void InsertSpanFormattable<T>(int index, T value)
129+
private void InsertSpanFormattable<T>(int index, T value, ReadOnlySpan<char> format = default)
122130
where T : ISpanFormattable
123131
{
124132
if (index < 0)
@@ -131,8 +139,8 @@ private void InsertSpanFormattable<T>(int index, T value)
131139
throw new ArgumentOutOfRangeException(nameof(index), "The given index can't be bigger than the string itself.");
132140
}
133141

134-
Span<char> tempBuffer = stackalloc char[24];
135-
if (value.TryFormat(tempBuffer, out var written, default, null))
142+
Span<char> tempBuffer = stackalloc char[36];
143+
if (value.TryFormat(tempBuffer, out var written, format, null))
136144
{
137145
bufferPosition += written;
138146
if (bufferPosition > buffer.Length)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,14 @@ public void ShouldThrowWhenIndexIsBehindBufferLengthForFormattableSpan()
206206

207207
Assert.False(true);
208208
}
209+
210+
[Fact]
211+
public void ShouldAppendGuid()
212+
{
213+
using var builder = new ValueStringBuilder();
214+
215+
builder.Insert(0, Guid.Empty);
216+
217+
builder.ToString().Should().Be("00000000-0000-0000-0000-000000000000");
218+
}
209219
}

0 commit comments

Comments
 (0)