Skip to content

Commit 4e860c6

Browse files
author
LinkDotNet Bot
committed
Updating to newest release
2 parents 3a0b343 + db79ca9 commit 4e860c6

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
## [3.4.1] - 2026-02-19
10+
11+
### Fixed
12+
13+
- Use correct culture (`CurrentCulture`) when no `FormatProvider` is provided in `Append` and `Insert` methods.
14+
915
## [3.4.0] - 2026-02-18
1016

1117
### Added
@@ -533,7 +539,8 @@ This release brings extensions to the `ValueStringBuilder` API. For `v1.0` the `
533539

534540
- Initial release
535541

536-
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/3.4.0...HEAD
542+
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/3.4.1...HEAD
543+
[3.4.1]: https://github.com/linkdotnet/StringBuilder/compare/3.4.0...3.4.1
537544
[3.4.0]: https://github.com/linkdotnet/StringBuilder/compare/3.3.0...3.4.0
538545
[3.3.0]: https://github.com/linkdotnet/StringBuilder/compare/3.2.0...3.3.0
539546
[3.2.0]: https://github.com/linkdotnet/StringBuilder/compare/3.1.0...3.2.0

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Globalization;
21
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43
using System.Text;
@@ -53,7 +52,7 @@ public unsafe void Append(bool value)
5352
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
5453
/// <param name="bufferSize">Size of the buffer allocated. If you have a custom type that implements <see cref="ISpanFormattable"/> that
5554
/// requires more space than the default (36 characters), adjust the value.</param>
56-
/// <param name="formatProvider">Optional format provider. If null <see cref="CultureInfo.InvariantCulture"/> is used.</param>
55+
/// <param name="formatProvider">Optional format provider.</param>
5756
/// <typeparam name="T">Any <see cref="ISpanFormattable"/>.</typeparam>
5857
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5958
public void Append<T>(T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36, IFormatProvider? formatProvider = null)
@@ -192,7 +191,7 @@ private void AppendSpanFormattable<T>(T value, scoped ReadOnlySpan<char> format
192191
EnsureCapacity(newSize);
193192
}
194193

195-
if (!value.TryFormat(buffer[bufferPosition..], out var written, format, formatProvider ?? CultureInfo.InvariantCulture))
194+
if (!value.TryFormat(buffer[bufferPosition..], out var written, format, formatProvider))
196195
{
197196
throw new InvalidOperationException($"Could not insert {value} into given buffer. Is the buffer (size: {bufferSize}) large enough?");
198197
}

src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Globalization;
21
using System.Runtime.CompilerServices;
32
using System.Text;
43

@@ -44,7 +43,7 @@ public void Insert(int index, Rune value)
4443
/// <param name="value">Formattable span to insert into this builder.</param>
4544
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
4645
/// <param name="bufferSize">Size of the buffer allocated on the stack.</param>
47-
/// <param name="formatProvider">Optional format provider. If null <see cref="CultureInfo.InvariantCulture"/> is used.</param>
46+
/// <param name="formatProvider">Optional format provider.</param>
4847
/// <typeparam name="T">Any <see cref="ISpanFormattable"/>.</typeparam>
4948
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5049
public void Insert<T>(int index, T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36, IFormatProvider? formatProvider = null)
@@ -105,7 +104,7 @@ private void InsertSpanFormattable<T>(int index, T value, scoped ReadOnlySpan<ch
105104
}
106105

107106
Span<char> tempBuffer = stackalloc char[bufferSize];
108-
if (value.TryFormat(tempBuffer, out var written, format, formatProvider ?? CultureInfo.InvariantCulture))
107+
if (value.TryFormat(tempBuffer, out var written, format, formatProvider))
109108
{
110109
var newLength = bufferPosition + written;
111110
if (newLength > buffer.Length)

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,15 @@ public void ShouldAppendSpanFormattableWithGivenCulture()
100100
}
101101

102102
[Fact]
103-
public void ShouldAppendSpanFormattableWithInvariantCultureWhenFormatProviderIsNull()
103+
public void ShouldAppendSpanFormattableWithCurrentCultureWhenFormatProviderIsNull()
104104
{
105+
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
105106
using var builder = new ValueStringBuilder();
106107
var originalCulture = CultureInfo.CurrentCulture;
107-
try
108-
{
109-
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
110-
builder.Append(1.2m, formatProvider: null);
111-
}
112-
finally
113-
{
114-
CultureInfo.CurrentCulture = originalCulture;
115-
}
108+
builder.Append(1.2m, formatProvider: null);
116109

117-
builder.ToString().ShouldBe("1.2");
110+
CultureInfo.CurrentCulture = originalCulture;
111+
builder.ToString().ShouldBe("1,2");
118112
}
119113

120114
[Fact]

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,14 @@ public void ShouldInsertSpanFormattableWithGivenCulture()
4848
[Fact]
4949
public void ShouldInsertSpanFormattableWithInvariantCultureWhenFormatProviderIsNull()
5050
{
51+
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
5152
using var builder = new ValueStringBuilder();
5253
var originalCulture = CultureInfo.CurrentCulture;
53-
try
54-
{
55-
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
56-
builder.Insert(0, 1.2m, formatProvider: null);
57-
}
58-
finally
59-
{
60-
CultureInfo.CurrentCulture = originalCulture;
61-
}
6254

63-
builder.ToString().ShouldBe("1.2");
55+
builder.Insert(0, 1.2m, formatProvider: null);
56+
57+
CultureInfo.CurrentCulture = originalCulture;
58+
builder.ToString().ShouldBe("1,2");
6459
}
6560

6661
[Fact]

0 commit comments

Comments
 (0)