Skip to content

Commit 3a0b343

Browse files
author
LinkDotNet Bot
committed
Updating to newest release
2 parents e4bf4e7 + 43f98f8 commit 3a0b343

10 files changed

+97
-17
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.0] - 2026-02-18
10+
11+
### Added
12+
13+
- `Append` and `Insert` can have `FormatProvider`. Reported by [@SMAH1](https://github.com/SMAH1) in #276
14+
915
## [3.3.0] - 2026-01-19
1016

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

528534
- Initial release
529535

530-
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/3.3.0...HEAD
536+
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/3.4.0...HEAD
537+
[3.4.0]: https://github.com/linkdotnet/StringBuilder/compare/3.3.0...3.4.0
531538
[3.3.0]: https://github.com/linkdotnet/StringBuilder/compare/3.2.0...3.3.0
532539
[3.2.0]: https://github.com/linkdotnet/StringBuilder/compare/3.1.0...3.2.0
533540
[3.1.0]: https://github.com/linkdotnet/StringBuilder/compare/3.0.0...3.1.0

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.17.0.131074">
4+
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.19.0.132793">
55
<PrivateAssets>all</PrivateAssets>
66
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
77
</PackageReference>

SE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/Users/stevengiesel/repos/StringBuilder/LinkDotNet.StringBuilder.slnx.metaproj : error MSB4126: The specified solution configuration "RELE|Any CPU" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [/Users/stevengiesel/repos/StringBuilder/LinkDotNet.StringBuilder.slnx]
2+
3+
Build FAILED.
4+
5+
/Users/stevengiesel/repos/StringBuilder/LinkDotNet.StringBuilder.slnx.metaproj : error MSB4126: The specified solution configuration "RELE|Any CPU" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [/Users/stevengiesel/repos/StringBuilder/LinkDotNet.StringBuilder.slnx]
6+
0 Warning(s)
7+
1 Error(s)
8+
9+
Time Elapsed 00:00:00.06

src/LinkDotNet.StringBuilder/LinkDotNet.StringBuilder.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
</PropertyGroup>
4343

4444
<ItemGroup>
45-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.267">
45+
<PackageReference Include="Meziantou.Analyzer" Version="3.0.1">
4646
<PrivateAssets>all</PrivateAssets>
4747
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4848
</PackageReference>
49-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
49+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.103">
5050
<PrivateAssets>all</PrivateAssets>
5151
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5252
</PackageReference>

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using System.Runtime.CompilerServices;
23
using System.Runtime.InteropServices;
34
using System.Text;
@@ -52,10 +53,11 @@ public unsafe void Append(bool value)
5253
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
5354
/// <param name="bufferSize">Size of the buffer allocated. If you have a custom type that implements <see cref="ISpanFormattable"/> that
5455
/// 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>
5557
/// <typeparam name="T">Any <see cref="ISpanFormattable"/>.</typeparam>
5658
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57-
public void Append<T>(T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36)
58-
where T : ISpanFormattable => AppendSpanFormattable(value, format, bufferSize);
59+
public void Append<T>(T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36, IFormatProvider? formatProvider = null)
60+
where T : ISpanFormattable => AppendSpanFormattable(value, format, bufferSize, formatProvider);
5961

6062
/// <summary>
6163
/// Appends a string.
@@ -181,7 +183,7 @@ public Span<char> AppendSpan(int length)
181183
}
182184

183185
[MethodImpl(MethodImplOptions.AggressiveInlining)]
184-
private void AppendSpanFormattable<T>(T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36)
186+
private void AppendSpanFormattable<T>(T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36, IFormatProvider? formatProvider = null)
185187
where T : ISpanFormattable
186188
{
187189
var newSize = bufferSize + bufferPosition;
@@ -190,7 +192,7 @@ private void AppendSpanFormattable<T>(T value, scoped ReadOnlySpan<char> format
190192
EnsureCapacity(newSize);
191193
}
192194

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

src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
using System.Globalization;
2+
using System.Runtime.CompilerServices;
23
using System.Text;
34

45
namespace LinkDotNet.StringBuilder;
@@ -43,10 +44,11 @@ public void Insert(int index, Rune value)
4344
/// <param name="value">Formattable span to insert into this builder.</param>
4445
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
4546
/// <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>
4648
/// <typeparam name="T">Any <see cref="ISpanFormattable"/>.</typeparam>
4749
[MethodImpl(MethodImplOptions.AggressiveInlining)]
48-
public void Insert<T>(int index, T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36)
49-
where T : ISpanFormattable => InsertSpanFormattable(index, value, format, bufferSize);
50+
public void Insert<T>(int index, T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36, IFormatProvider? formatProvider = null)
51+
where T : ISpanFormattable => InsertSpanFormattable(index, value, format, bufferSize, formatProvider);
5052

5153
/// <summary>
5254
/// Appends the string representation of the boolean to the builder.
@@ -89,7 +91,7 @@ public void Insert(int index, scoped ReadOnlySpan<char> value)
8991
}
9092

9193
[MethodImpl(MethodImplOptions.AggressiveInlining)]
92-
private void InsertSpanFormattable<T>(int index, T value, scoped ReadOnlySpan<char> format, int bufferSize)
94+
private void InsertSpanFormattable<T>(int index, T value, scoped ReadOnlySpan<char> format, int bufferSize, IFormatProvider? formatProvider = null)
9395
where T : ISpanFormattable
9496
{
9597
if (index < 0)
@@ -103,7 +105,7 @@ private void InsertSpanFormattable<T>(int index, T value, scoped ReadOnlySpan<ch
103105
}
104106

105107
Span<char> tempBuffer = stackalloc char[bufferSize];
106-
if (value.TryFormat(tempBuffer, out var written, format, null))
108+
if (value.TryFormat(tempBuffer, out var written, format, formatProvider ?? CultureInfo.InvariantCulture))
107109
{
108110
var newLength = bufferPosition + written;
109111
if (newLength > buffer.Length)

src/LinkDotNet.StringBuilder/ValueStringBuilder.InterpolatedStringHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public ref struct AppendInterpolatedStringHandler
4242
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4343
public AppendInterpolatedStringHandler(int literalLength, int formattedCount, ValueStringBuilder builder)
4444
{
45-
this.Builder = builder;
45+
Builder = builder;
4646

4747
// A conservative guess for the capacity.
48-
this.Builder.EnsureCapacity(this.Builder.Length + literalLength + (formattedCount * 11));
48+
Builder.EnsureCapacity(Builder.Length + literalLength + (formattedCount * 11));
4949
}
5050

5151
/// <summary>

tests/LinkDotNet.StringBuilder.UnitTests/LinkDotNet.StringBuilder.UnitTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
1313
<PackageReference Include="Shouldly" Version="4.3.0" />
14-
<PackageReference Include="xunit.v3" Version="3.2.1" />
14+
<PackageReference Include="xunit.v3" Version="3.2.2" />
1515
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>
19-
<PackageReference Include="coverlet.collector" Version="6.0.4">
19+
<PackageReference Include="coverlet.collector" Version="8.0.0">
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
<PrivateAssets>all</PrivateAssets>
2222
</PackageReference>

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Globalization;
2+
13
namespace LinkDotNet.StringBuilder.UnitTests;
24

35
public class ValueStringBuilderAppendTests
@@ -87,6 +89,34 @@ public void ShouldAppendSpanFormattable()
8789
builder.ToString().ShouldBe("2.2");
8890
}
8991

92+
[Fact]
93+
public void ShouldAppendSpanFormattableWithGivenCulture()
94+
{
95+
using var builder = new ValueStringBuilder();
96+
97+
builder.Append(1.2m, formatProvider: CultureInfo.GetCultureInfo("de-DE"));
98+
99+
builder.ToString().ShouldBe("1,2");
100+
}
101+
102+
[Fact]
103+
public void ShouldAppendSpanFormattableWithInvariantCultureWhenFormatProviderIsNull()
104+
{
105+
using var builder = new ValueStringBuilder();
106+
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+
}
116+
117+
builder.ToString().ShouldBe("1.2");
118+
}
119+
90120
[Fact]
91121
public void ShouldAppendMultipleChars()
92122
{

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Globalization;
2+
13
namespace LinkDotNet.StringBuilder.UnitTests;
24

35
public class ValueStringBuilderInsertTests
@@ -33,6 +35,34 @@ public void ShouldAppendSpanFormattable()
3335
builder.ToString().ShouldBe("2.2");
3436
}
3537

38+
[Fact]
39+
public void ShouldInsertSpanFormattableWithGivenCulture()
40+
{
41+
using var builder = new ValueStringBuilder();
42+
43+
builder.Insert(0, 1.2m, formatProvider: CultureInfo.GetCultureInfo("de-DE"));
44+
45+
builder.ToString().ShouldBe("1,2");
46+
}
47+
48+
[Fact]
49+
public void ShouldInsertSpanFormattableWithInvariantCultureWhenFormatProviderIsNull()
50+
{
51+
using var builder = new ValueStringBuilder();
52+
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+
}
62+
63+
builder.ToString().ShouldBe("1.2");
64+
}
65+
3666
[Fact]
3767
public void ShouldThrowWhenIndexIsNegative()
3868
{

0 commit comments

Comments
 (0)