Skip to content

Commit 0057055

Browse files
committed
Added format overload
1 parent ae30c9d commit 0057055

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
1010

1111
- `ToString(startIndex, length)` to get a substring from the builder
1212
- `Append(Guid guid)` and `Insert(Guid guid)` as new overload
13+
- Added optional format string for `Append` and `Insert`
1314

1415
## [1.6.2] - 2022-11-11
1516

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,81 @@ public ref partial struct ValueStringBuilder
1515
/// Appends the string representation of the character to the builder.
1616
/// </summary>
1717
/// <param name="value">Integer to add.</param>
18+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
1819
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19-
public void Append(char value) => AppendSpanFormattable(value);
20+
public void Append(char value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
2021

2122
/// <summary>
2223
/// Appends the string representation of the signed byte to the builder.
2324
/// </summary>
2425
/// <param name="value">Signed byte to add.</param>
26+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
2527
[MethodImpl(MethodImplOptions.AggressiveInlining)]
26-
public void Append(sbyte value) => AppendSpanFormattable(value);
28+
public void Append(sbyte value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
2729

2830
/// <summary>
2931
/// Appends the string representation of the byte to the builder.
3032
/// </summary>
3133
/// <param name="value">Byte to add.</param>
34+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
3235
[MethodImpl(MethodImplOptions.AggressiveInlining)]
33-
public void Append(byte value) => AppendSpanFormattable(value);
36+
public void Append(byte value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
3437

3538
/// <summary>
3639
/// Appends the string representation of the short to the builder.
3740
/// </summary>
3841
/// <param name="value">Short to add.</param>
42+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
3943
[MethodImpl(MethodImplOptions.AggressiveInlining)]
40-
public void Append(short value) => AppendSpanFormattable(value);
44+
public void Append(short value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
4145

4246
/// <summary>
4347
/// Appends the string representation of the integer to the builder.
4448
/// </summary>
4549
/// <param name="value">Integer to add.</param>
50+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
4651
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47-
public void Append(int value) => AppendSpanFormattable(value);
52+
public void Append(int value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
4853

4954
/// <summary>
5055
/// Appends the string representation of the long integer to the builder.
5156
/// </summary>
5257
/// <param name="value">Long integer to add.</param>
58+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
5359
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54-
public void Append(long value) => AppendSpanFormattable(value);
60+
public void Append(long value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
5561

5662
/// <summary>
5763
/// Appends the string representation of the float to the builder.
5864
/// </summary>
5965
/// <param name="value">Float to add.</param>
66+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
6067
[MethodImpl(MethodImplOptions.AggressiveInlining)]
61-
public void Append(float value) => AppendSpanFormattable(value);
68+
public void Append(float value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
6269

6370
/// <summary>
6471
/// Appends the string representation of the double to the builder.
6572
/// </summary>
6673
/// <param name="value">Double to add.</param>
74+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
6775
[MethodImpl(MethodImplOptions.AggressiveInlining)]
68-
public void Append(double value) => AppendSpanFormattable(value);
76+
public void Append(double value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
6977

7078
/// <summary>
7179
/// Appends the string representation of the decimal to the builder.
7280
/// </summary>
7381
/// <param name="value">Decimal to add.</param>
82+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
7483
[MethodImpl(MethodImplOptions.AggressiveInlining)]
75-
public void Append(decimal value) => AppendSpanFormattable(value);
84+
public void Append(decimal value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
7685

7786
/// <summary>
7887
/// Appends the string representation of the Guid to the builder.
7988
/// </summary>
8089
/// <param name="value">Guid to add.</param>
90+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
8191
[MethodImpl(MethodImplOptions.AggressiveInlining)]
82-
public void Append(Guid value) => AppendSpanFormattable(value, "D");
92+
public void Append(Guid value, ReadOnlySpan<char> format = default) => AppendSpanFormattable(value, format);
8393

8494
/// <summary>
8595
/// Appends a string to the string builder.

src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,90 @@ public ref partial struct ValueStringBuilder
1717
/// </summary>
1818
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
1919
/// <param name="value">Character to insert into this builder.</param>
20+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
2021
[MethodImpl(MethodImplOptions.AggressiveInlining)]
21-
public void Insert(int index, char value) => InsertSpanFormattable(index, value);
22+
public void Insert(int index, char value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
2223

2324
/// <summary>
2425
/// Insert the string representation of the signed byte to the builder at the given index.
2526
/// </summary>
2627
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
2728
/// <param name="value">Signed byte to insert into this builder.</param>
29+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
2830
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29-
public void Insert(int index, sbyte value) => InsertSpanFormattable(index, value);
31+
public void Insert(int index, sbyte value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
3032

3133
/// <summary>
3234
/// Insert the string representation of the byte to the builder at the given index.
3335
/// </summary>
3436
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
3537
/// <param name="value">Byte to insert into this builder.</param>
38+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
3639
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37-
public void Insert(int index, byte value) => InsertSpanFormattable(index, value);
40+
public void Insert(int index, byte value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
3841

3942
/// <summary>
4043
/// Insert the string representation of the short to the builder at the given index.
4144
/// </summary>
4245
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
4346
/// <param name="value">Short to insert into this builder.</param>
47+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
4448
[MethodImpl(MethodImplOptions.AggressiveInlining)]
45-
public void Insert(int index, short value) => InsertSpanFormattable(index, value);
49+
public void Insert(int index, short value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
4650

4751
/// <summary>
4852
/// Insert the string representation of the integer to the builder at the given index.
4953
/// </summary>
5054
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
5155
/// <param name="value">Integer to insert into this builder.</param>
56+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
5257
[MethodImpl(MethodImplOptions.AggressiveInlining)]
53-
public void Insert(int index, int value) => InsertSpanFormattable(index, value);
58+
public void Insert(int index, int value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
5459

5560
/// <summary>
5661
/// Insert the string representation of the long to the builder at the given index.
5762
/// </summary>
5863
/// <param name="index">Long where <paramref name="value"/> should be inserted.</param>
5964
/// <param name="value">String to insert into this builder.</param>
65+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
6066
[MethodImpl(MethodImplOptions.AggressiveInlining)]
61-
public void Insert(int index, long value) => InsertSpanFormattable(index, value);
67+
public void Insert(int index, long value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
6268

6369
/// <summary>
6470
/// Insert the string representation of the float to the builder at the given index.
6571
/// </summary>
6672
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
6773
/// <param name="value">Float to insert into this builder.</param>
74+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
6875
[MethodImpl(MethodImplOptions.AggressiveInlining)]
69-
public void Insert(int index, float value) => InsertSpanFormattable(index, value);
76+
public void Insert(int index, float value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
7077

7178
/// <summary>
7279
/// Insert the string representation of the double to the builder at the given index.
7380
/// </summary>
7481
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
7582
/// <param name="value">Double to insert into this builder.</param>
83+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
7684
[MethodImpl(MethodImplOptions.AggressiveInlining)]
77-
public void Insert(int index, double value) => InsertSpanFormattable(index, value);
85+
public void Insert(int index, double value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
7886

7987
/// <summary>
8088
/// Insert the string representation of the decimal to the builder at the given index.
8189
/// </summary>
8290
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
8391
/// <param name="value">Decimal to insert into this builder.</param>
92+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
8493
[MethodImpl(MethodImplOptions.AggressiveInlining)]
85-
public void Insert(int index, decimal value) => InsertSpanFormattable(index, value);
94+
public void Insert(int index, decimal value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
8695

8796
/// <summary>
8897
/// Insert the string representation of the Guid to the builder at the given index.
8998
/// </summary>
9099
/// <param name="index">Index where <paramref name="value"/> should be inserted.</param>
91100
/// <param name="value">Guid to insert into this builder.</param>
101+
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
92102
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93-
public void Insert(int index, Guid value) => InsertSpanFormattable(index, value);
103+
public void Insert(int index, Guid value, ReadOnlySpan<char> format = default) => InsertSpanFormattable(index, value, format);
94104

95105
/// <summary>
96106
/// Appends the string representation of the boolean to the builder.

0 commit comments

Comments
 (0)