Skip to content

Commit 0fb8f60

Browse files
author
LinkDotNet Bot
committed
Updating to newest release
2 parents 734bf80 + e37c3ae commit 0fb8f60

File tree

14 files changed

+248
-66
lines changed

14 files changed

+248
-66
lines changed

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222

2323
steps:
2424
- name: Checkout repository
25-
uses: actions/checkout@v5.0.0
25+
uses: actions/checkout@v5
2626

27-
- uses: actions/setup-dotnet@v5.0.0
27+
- uses: actions/setup-dotnet@v5
2828
with:
2929
dotnet-version: |
3030
8.0.x

.github/workflows/create-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ jobs:
2020
steps:
2121

2222
- name: Checkout repository
23-
uses: actions/checkout@v5.0.0
23+
uses: actions/checkout@v5
2424
with:
2525
token: ${{ secrets.SBPAT }}
2626
persist-credentials: true
2727
fetch-depth: 0
2828

2929
- name: Get changelog entries
3030
id: changelog
31-
uses: mindsers/changelog-reader-action@v2.2.3
31+
uses: mindsers/changelog-reader-action@v2
3232
with:
3333
version: Unreleased
3434
path: ./CHANGELOG.md
3535

3636
- name: Setup dotnet
37-
uses: actions/setup-dotnet@v5.0.0
37+
uses: actions/setup-dotnet@v5
3838
with:
3939
dotnet-version: |
4040
8.0.x

.github/workflows/docs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ jobs:
1212
runs-on: windows-latest
1313

1414
steps:
15-
- uses: actions/checkout@v5.0.0
15+
- uses: actions/checkout@v5
1616

1717
- name: Setup .NET
18-
uses: actions/setup-dotnet@v5.0.0
18+
uses: actions/setup-dotnet@v5
1919
with:
2020
dotnet-version: |
2121
8.0.x
2222
9.0.x
2323
10.0.x
2424
2525
- name: Setup DocFX
26-
uses: crazy-max/ghaction-chocolatey@v3.4.0
26+
uses: crazy-max/ghaction-chocolatey@v3
2727
with:
2828
args: install docfx
2929

@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Publish
3636
if: github.event_name == 'push'
37-
uses: peaceiris/actions-gh-pages@v4.0.0
37+
uses: peaceiris/actions-gh-pages@v4
3838
with:
3939
github_token: ${{ secrets.GITHUB_TOKEN }}
4040
publish_dir: docs/site/_site

.github/workflows/dotnet.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v5.0.0
15+
- uses: actions/checkout@v5
1616
- name: Setup .NET
17-
uses: actions/setup-dotnet@v5.0.0
17+
uses: actions/setup-dotnet@v5
1818
with:
1919
dotnet-version: |
2020
8.0.x

.github/workflows/update-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout repository
16-
uses: actions/checkout@v5.0.0
16+
uses: actions/checkout@v5
1717
with:
1818
token: ${{ secrets.SBPAT }}
1919
persist-credentials: false
@@ -32,7 +32,7 @@ jobs:
3232
git merge --no-ff -X theirs origin/main -m "Updating to newest release"
3333
3434
- name: Push changes
35-
uses: ad-m/github-push-action@v1.0.0
35+
uses: ad-m/github-push-action@v1
3636
with:
3737
github_token: ${{ secrets.SBPAT }}
3838
branch: stable

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.1.0] - 2025-10-31
10+
11+
### Added
12+
13+
- Added `PadLeft(ReadOnlySpan<char>, int, char)` and `PadRight(ReadOnlySpan<char>, int, char)` methods to append padded strings without allocating additional memory (by [@SMAH1](https://github.com/SMAH1) in #260)
14+
915
## [3.0.0] - 2025-10-30
1016

1117
This is the `v3` major release. The API is almost the same as in `v2` - there is only a slight change in the `Concat` static helper method to reflect a less-boxed API.
@@ -509,7 +515,8 @@ This release brings extensions to the `ValueStringBuilder` API. For `v1.0` the `
509515

510516
- Initial release
511517

512-
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/3.0.0...HEAD
518+
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/3.1.0...HEAD
519+
[3.1.0]: https://github.com/linkdotnet/StringBuilder/compare/3.0.0...3.1.0
513520
[3.0.0]: https://github.com/linkdotnet/StringBuilder/compare/2.4.1...3.0.0
514521
[2.4.1]: https://github.com/linkdotnet/StringBuilder/compare/2.4.0...2.4.1
515522
[2.4.0]: https://github.com/linkdotnet/StringBuilder/compare/2.3.1...2.4.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.9.0.115408">
4+
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.15.0.120848">
55
<PrivateAssets>all</PrivateAssets>
66
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
77
</PackageReference>

src/LinkDotNet.StringBuilder/LinkDotNet.StringBuilder.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</PropertyGroup>
4343

4444
<ItemGroup>
45-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.200">
45+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.239">
4646
<PrivateAssets>all</PrivateAssets>
4747
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4848
</PackageReference>

src/LinkDotNet.StringBuilder/ValueStringBuilder.Concat.Helper.cs

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace LinkDotNet.StringBuilder;
55
public ref partial struct ValueStringBuilder
66
{
77
/// <summary>
8-
/// Concatenates multiple objects together.
8+
/// Concatenates the string representation of multiple objects together.
99
/// </summary>
10-
/// <param name="values">Values to be concatenated together.</param>
11-
/// <typeparam name="T">Any given type, which can be translated to <see cref="string"/>.</typeparam>
12-
/// <returns>Concatenated string or an empty string if <paramref name="values"/> is empty.</returns>
10+
/// <param name="values">Values to be concatenated.</param>
11+
/// <typeparam name="T">Any type for <paramref name="values"/> that can be converted to <see cref="string"/>.</typeparam>
12+
/// <returns>The concatenated string, or an empty string if <paramref name="values"/> is empty.</returns>
1313
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1414
public static string Concat<T>(params scoped ReadOnlySpan<T> values)
1515
{
16-
if (values.Length == 0)
16+
if (values.IsEmpty)
1717
{
1818
return string.Empty;
1919
}
@@ -25,13 +25,28 @@ public static string Concat<T>(params scoped ReadOnlySpan<T> values)
2525
}
2626

2727
/// <summary>
28-
/// Concatenates two different types together.
28+
/// Creates the string representation of an object.
2929
/// </summary>
30-
/// <typeparam name="T1">Typeparameter of <paramref name="arg1"/>.</typeparam>
31-
/// <typeparam name="T2">Typeparameter of <paramref name="arg2"/>.</typeparam>
32-
/// <param name="arg1">First argument.</param>
33-
/// <param name="arg2">Second argument.</param>
34-
/// <returns>String representation of the concateneted result.</returns>
30+
/// <typeparam name="T1">Any type for <paramref name="arg1"/> that can be converted to <see cref="string"/>.</typeparam>
31+
/// <param name="arg1">First value to be concatenated.</param>
32+
/// <returns>The string representation of the object.</returns>
33+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34+
public static string Concat<T1>(T1 arg1)
35+
{
36+
using var sb = new ValueStringBuilder(stackalloc char[128]);
37+
sb.AppendInternal(arg1);
38+
39+
return sb.ToString();
40+
}
41+
42+
/// <summary>
43+
/// Concatenates the string representation of two objects together.
44+
/// </summary>
45+
/// <typeparam name="T1">Any type for <paramref name="arg1"/> that can be converted to <see cref="string"/>.</typeparam>
46+
/// <typeparam name="T2">Any type for <paramref name="arg2"/> that can be converted to <see cref="string"/>.</typeparam>
47+
/// <param name="arg1">First value to be concatenated.</param>
48+
/// <param name="arg2">Second value to be concatenated.</param>
49+
/// <returns>The concatenated string.</returns>
3550
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3651
public static string Concat<T1, T2>(T1 arg1, T2 arg2)
3752
{
@@ -43,15 +58,15 @@ public static string Concat<T1, T2>(T1 arg1, T2 arg2)
4358
}
4459

4560
/// <summary>
46-
/// Concatenates two different types together.
61+
/// Concatenates the string representation of three objects together.
4762
/// </summary>
48-
/// <typeparam name="T1">Typeparameter of <paramref name="arg1"/>.</typeparam>
49-
/// <typeparam name="T2">Typeparameter of <paramref name="arg2"/>.</typeparam>
50-
/// <typeparam name="T3">Typeparameter of <paramref name="arg3"/>.</typeparam>
51-
/// <param name="arg1">First argument.</param>
52-
/// <param name="arg2">Second argument.</param>
53-
/// <param name="arg3">Third argument.</param>
54-
/// <returns>String representation of the concateneted result.</returns>
63+
/// <typeparam name="T1">Any type for <paramref name="arg1"/> that can be converted to <see cref="string"/>.</typeparam>
64+
/// <typeparam name="T2">Any type for <paramref name="arg2"/> that can be converted to <see cref="string"/>.</typeparam>
65+
/// <typeparam name="T3">Any type for <paramref name="arg3"/> that can be converted to <see cref="string"/>.</typeparam>
66+
/// <param name="arg1">First value to be concatenated.</param>
67+
/// <param name="arg2">Second value to be concatenated.</param>
68+
/// <param name="arg3">Third value to be concatenated.</param>
69+
/// <returns>The concatenated string.</returns>
5570
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5671
public static string Concat<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3)
5772
{
@@ -64,17 +79,17 @@ public static string Concat<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3)
6479
}
6580

6681
/// <summary>
67-
/// Concatenates two different types together.
82+
/// Concatenates the string representation of four objects together.
6883
/// </summary>
69-
/// <typeparam name="T1">Typeparameter of <paramref name="arg1"/>.</typeparam>
70-
/// <typeparam name="T2">Typeparameter of <paramref name="arg2"/>.</typeparam>
71-
/// <typeparam name="T3">Typeparameter of <paramref name="arg3"/>.</typeparam>
72-
/// <typeparam name="T4">Typeparameter of <paramref name="arg4"/>.</typeparam>
73-
/// <param name="arg1">First argument.</param>
74-
/// <param name="arg2">Second argument.</param>
75-
/// <param name="arg3">Third argument.</param>
76-
/// <param name="arg4">Fourth argument.</param>
77-
/// <returns>String representation of the concateneted result.</returns>
84+
/// <typeparam name="T1">Any type for <paramref name="arg1"/> that can be converted to <see cref="string"/>.</typeparam>
85+
/// <typeparam name="T2">Any type for <paramref name="arg2"/> that can be converted to <see cref="string"/>.</typeparam>
86+
/// <typeparam name="T3">Any type for <paramref name="arg3"/> that can be converted to <see cref="string"/>.</typeparam>
87+
/// <typeparam name="T4">Any type for <paramref name="arg4"/> that can be converted to <see cref="string"/>.</typeparam>
88+
/// <param name="arg1">First value to be concatenated.</param>
89+
/// <param name="arg2">Second value to be concatenated.</param>
90+
/// <param name="arg3">Third value to be concatenated.</param>
91+
/// <param name="arg4">Fourth value to be concatenated.</param>
92+
/// <returns>The concatenated string.</returns>
7893
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7994
public static string Concat<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
8095
{
@@ -88,19 +103,19 @@ public static string Concat<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
88103
}
89104

90105
/// <summary>
91-
/// Concatenates two different types together.
106+
/// Concatenates the string representation of five objects together.
92107
/// </summary>
93-
/// <typeparam name="T1">Typeparameter of <paramref name="arg1"/>.</typeparam>
94-
/// <typeparam name="T2">Typeparameter of <paramref name="arg2"/>.</typeparam>
95-
/// <typeparam name="T3">Typeparameter of <paramref name="arg3"/>.</typeparam>
96-
/// <typeparam name="T4">Typeparameter of <paramref name="arg4"/>.</typeparam>
97-
/// <typeparam name="T5">Typeparameter of <paramref name="arg5"/>.</typeparam>
98-
/// <param name="arg1">First argument.</param>
99-
/// <param name="arg2">Second argument.</param>
100-
/// <param name="arg3">Third argument.</param>
101-
/// <param name="arg4">Fourth argument.</param>
102-
/// <param name="arg5">Fifth argument.</param>
103-
/// <returns>String representation of the concateneted result.</returns>
108+
/// <typeparam name="T1">Any type for <paramref name="arg1"/> that can be converted to <see cref="string"/>.</typeparam>
109+
/// <typeparam name="T2">Any type for <paramref name="arg2"/> that can be converted to <see cref="string"/>.</typeparam>
110+
/// <typeparam name="T3">Any type for <paramref name="arg3"/> that can be converted to <see cref="string"/>.</typeparam>
111+
/// <typeparam name="T4">Any type for <paramref name="arg4"/> that can be converted to <see cref="string"/>.</typeparam>
112+
/// <typeparam name="T5">Any type for <paramref name="arg5"/> that can be converted to <see cref="string"/>.</typeparam>
113+
/// <param name="arg1">First value to be concatenated.</param>
114+
/// <param name="arg2">Second value to be concatenated.</param>
115+
/// <param name="arg3">Third value to be concatenated.</param>
116+
/// <param name="arg4">Fourth value to be concatenated.</param>
117+
/// <param name="arg5">Fifth value to be concatenated.</param>
118+
/// <returns>The concatenated string.</returns>
104119
[MethodImpl(MethodImplOptions.AggressiveInlining)]
105120
public static string Concat<T1, T2, T3, T4, T5>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
106121
{

src/LinkDotNet.StringBuilder/ValueStringBuilder.Pad.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,54 @@ public void PadRight(int totalWidth, char paddingChar)
4343
buffer[bufferPosition..totalWidth].Fill(paddingChar);
4444
bufferPosition = totalWidth;
4545
}
46+
47+
/// <summary>
48+
/// Appends the source string padded on the left with the given character to reach the specified total width.
49+
/// </summary>
50+
/// <param name="source">The source string to pad and append.</param>
51+
/// <param name="totalWidth">Total width of the padded string.</param>
52+
/// <param name="paddingChar">Character to pad the string with. Defaults to space.</param>
53+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54+
public void PadLeft(ReadOnlySpan<char> source, int totalWidth, char paddingChar = ' ')
55+
{
56+
if (totalWidth <= source.Length)
57+
{
58+
Append(source);
59+
return;
60+
}
61+
62+
var padding = totalWidth - source.Length;
63+
EnsureCapacity(bufferPosition + totalWidth);
64+
65+
buffer.Slice(bufferPosition, padding).Fill(paddingChar);
66+
bufferPosition += padding;
67+
68+
source.CopyTo(buffer[bufferPosition..]);
69+
bufferPosition += source.Length;
70+
}
71+
72+
/// <summary>
73+
/// Appends the source string padded on the right with the given character to reach the specified total width.
74+
/// </summary>
75+
/// <param name="source">The source string to pad and append.</param>
76+
/// <param name="totalWidth">Total width of the padded string.</param>
77+
/// <param name="paddingChar">Character to pad the string with. Defaults to space.</param>
78+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
79+
public void PadRight(ReadOnlySpan<char> source, int totalWidth, char paddingChar = ' ')
80+
{
81+
if (totalWidth <= source.Length)
82+
{
83+
Append(source);
84+
return;
85+
}
86+
87+
var padding = totalWidth - source.Length;
88+
EnsureCapacity(bufferPosition + totalWidth);
89+
90+
source.CopyTo(buffer[bufferPosition..]);
91+
bufferPosition += source.Length;
92+
93+
buffer.Slice(bufferPosition, padding).Fill(paddingChar);
94+
bufferPosition += padding;
95+
}
4696
}

0 commit comments

Comments
 (0)