Skip to content

Commit 5f7f509

Browse files
author
LinkDotNet Bot
committed
Updating to newest release
2 parents e313cd6 + f1831e7 commit 5f7f509

10 files changed

+122
-80
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [2.1.0] - 2025-01-14
10+
11+
### Added
12+
13+
- Added `Replace(Rune, Rune)` overload
14+
- Added `Replace(Rune, Rune, int, int)` overload
15+
916
## [2.0.0] - 2025-01-12
1017

1118
This is the `v2` release of the **ValueStringBuilder**. There aren't any noticeable breaking changes. Only old framework versions were removed to make further development easier. The API is the same (with new additions) as in `v1`.
@@ -438,7 +445,8 @@ This release brings extensions to the `ValueStringBuilder` API. For `v1.0` the `
438445

439446
- Initial release
440447

441-
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/2.0.0...HEAD
448+
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/2.1.0...HEAD
449+
[2.1.0]: https://github.com/linkdotnet/StringBuilder/compare/2.0.0...2.1.0
442450
[2.0.0]: https://github.com/linkdotnet/StringBuilder/compare/1.22.0...2.0.0
443451
[1.22.0]: https://github.com/linkdotnet/StringBuilder/compare/1.21.1...1.22.0
444452
[1.21.1]: https://github.com/linkdotnet/StringBuilder/compare/1.21.0...1.21.1

src/LinkDotNet.StringBuilder/LinkDotNet.StringBuilder.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2020
<LangVersion>preview</LangVersion>
2121
<EmbedUntrackedSources>true</EmbedUntrackedSources>
22+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
2223
</PropertyGroup>
2324

2425
<ItemGroup>

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace LinkDotNet.StringBuilder;
77
public ref partial struct ValueStringBuilder
88
{
99
/// <summary>
10-
/// Appends the string representation of the boolean to the builder.
10+
/// Appends the string representation of the boolean.
1111
/// </summary>
1212
/// <param name="value">Bool value to add.</param>
1313
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -46,7 +46,7 @@ public unsafe void Append(bool value)
4646
}
4747

4848
/// <summary>
49-
/// Appends the string representation of the character to the builder.
49+
/// Appends the string representation of the value.
5050
/// </summary>
5151
/// <param name="value">Formattable span to add.</param>
5252
/// <param name="format">Optional formatter. If not provided the default of the given instance is taken.</param>
@@ -58,9 +58,9 @@ public void Append<T>(T value, ReadOnlySpan<char> format = default, int bufferSi
5858
where T : ISpanFormattable => AppendSpanFormattable(value, format, bufferSize);
5959

6060
/// <summary>
61-
/// Appends a string to the string builder.
61+
/// Appends a string.
6262
/// </summary>
63-
/// <param name="str">String, which will be added to this builder.</param>
63+
/// <param name="str">String to be added to this builder.</param>
6464
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6565
public void Append(scoped ReadOnlySpan<char> str)
6666
{
@@ -81,7 +81,7 @@ ref Unsafe.As<char, byte>(ref strRef),
8181
}
8282

8383
/// <summary>
84-
/// Appends a character buffer to this builder.
84+
/// Appends a character buffer.
8585
/// </summary>
8686
/// <param name="value">The pointer to the start of the buffer.</param>
8787
/// <param name="length">The number of characters in the buffer.</param>
@@ -102,7 +102,7 @@ public void Append(ReadOnlyMemory<char> memory)
102102
}
103103

104104
/// <summary>
105-
/// Appends a single character to the string builder.
105+
/// Appends a single character.
106106
/// </summary>
107107
/// <param name="value">Character to add.</param>
108108
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -142,7 +142,7 @@ public void AppendLine()
142142
}
143143

144144
/// <summary>
145-
/// Does the same as <see cref="Append(char)"/> but adds a newline at the end.
145+
/// Calls <see cref="Append(ReadOnlySpan{char})"/> and appends a newline.
146146
/// </summary>
147147
/// <param name="str">String to be added to this builder.</param>
148148
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -153,9 +153,9 @@ public void AppendLine(scoped ReadOnlySpan<char> str)
153153
}
154154

155155
/// <summary>
156-
/// Increases the size of the string builder returning a span of the length appended.
156+
/// Appends a span of the given length, which can be written to later.
157157
/// </summary>
158-
/// <param name="length">Integer representing the length to be appended.</param>
158+
/// <param name="length">Integer representing the number of characters to be appended.</param>
159159
/// <returns>A span with the characters appended.</returns>
160160
[MethodImpl(MethodImplOptions.AggressiveInlining)]
161161
public Span<char> AppendSpan(int length)

src/LinkDotNet.StringBuilder/ValueStringBuilder.AppendFormat.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public void AppendFormat<T>(
6565
/// <param name="format">Format string.</param>
6666
/// <param name="arg1">Argument for <c>{0}</c>.</param>
6767
/// <param name="arg2">Argument for <c>{1}</c>.</param>
68-
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
69-
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
68+
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
69+
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
7070
/// <remarks>
7171
/// The current version does not allow for a custom format.
7272
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.
@@ -132,9 +132,9 @@ public void AppendFormat<T1, T2>(
132132
/// <param name="arg1">Argument for <c>{0}</c>.</param>
133133
/// <param name="arg2">Argument for <c>{1}</c>.</param>
134134
/// <param name="arg3">Argument for <c>{2}</c>.</param>
135-
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
136-
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
137-
/// <typeparam name="T3">Any type for <param name="arg3"></param>.</typeparam>
135+
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
136+
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
137+
/// <typeparam name="T3">Any type for <paramref name="arg3"/>.</typeparam>
138138
/// <remarks>
139139
/// The current version does not allow for a custom format.
140140
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.
@@ -205,10 +205,10 @@ public void AppendFormat<T1, T2, T3>(
205205
/// <param name="arg2">Argument for <c>{1}</c>.</param>
206206
/// <param name="arg3">Argument for <c>{2}</c>.</param>
207207
/// <param name="arg4">Argument for <c>{3}</c>.</param>
208-
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
209-
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
210-
/// <typeparam name="T3">Any type for <param name="arg3"></param>.</typeparam>
211-
/// <typeparam name="T4">Any type for <param name="arg4"></param>.</typeparam>
208+
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
209+
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
210+
/// <typeparam name="T3">Any type for <paramref name="arg3"/>.</typeparam>
211+
/// <typeparam name="T4">Any type for <paramref name="arg4"/>.</typeparam>
212212
/// <remarks>
213213
/// The current version does not allow for a custom format.
214214
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.
@@ -284,11 +284,11 @@ public void AppendFormat<T1, T2, T3, T4>(
284284
/// <param name="arg3">Argument for <c>{2}</c>.</param>
285285
/// <param name="arg4">Argument for <c>{3}</c>.</param>
286286
/// <param name="arg5">Argument for <c>{4}</c>.</param>
287-
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
288-
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
289-
/// <typeparam name="T3">Any type for <param name="arg3"></param>.</typeparam>
290-
/// <typeparam name="T4">Any type for <param name="arg4"></param>.</typeparam>
291-
/// <typeparam name="T5">Any type for <param name="arg5"></param>.</typeparam>
287+
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
288+
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
289+
/// <typeparam name="T3">Any type for <paramref name="arg3"/>.</typeparam>
290+
/// <typeparam name="T4">Any type for <paramref name="arg4"/>.</typeparam>
291+
/// <typeparam name="T5">Any type for <paramref name="arg5"/>.</typeparam>
292292
/// <remarks>
293293
/// The current version does not allow for a custom format.
294294
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public ref partial struct ValueStringBuilder
77
/// <summary>
88
/// Concatenates multiple objects together.
99
/// </summary>
10-
/// <param name="values">Values, which will be concatenated together.</param>
10+
/// <param name="values">Values to be concatenated together.</param>
1111
/// <typeparam name="T">Any given type, which can be translated to <see cref="string"/>.</typeparam>
12-
/// <returns>Concatenated string or an empty string if <see cref="values"/> is empty.</returns>
12+
/// <returns>Concatenated string or an empty string if <paramref name="values"/> is empty.</returns>
1313
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1414
public static string Concat<T>(params T[] values)
1515
{

src/LinkDotNet.StringBuilder/ValueStringBuilder.Enumerator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ namespace LinkDotNet.StringBuilder;
55

66
public ref partial struct ValueStringBuilder
77
{
8+
/// <summary>
9+
/// Creates an enumerator over the characters in the builder.
10+
/// </summary>
11+
/// <returns>An enumerator over the characters in the builder.</returns>
812
public readonly Enumerator GetEnumerator() => new(buffer[..bufferPosition]);
913

1014
/// <summary>Enumerates the elements of a <see cref="Span{T}"/>.</summary>
@@ -32,7 +36,7 @@ public readonly char Current
3236
}
3337

3438
/// <summary>Advances the enumerator to the next element of the span.</summary>
35-
/// <returns>True if the enumerator was successfully advancing to the next element; false if the enumerator has passed the end of the span.</returns>
39+
/// <returns><see langword="true"/> if the enumerator successfully advanced to the next element; <see langword="false"/> if the enumerator reached the end of the span.</returns>
3640
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3741
public bool MoveNext() => ++index < span.Length;
3842
}

src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ref partial struct ValueStringBuilder
2121
/// <param name="bufferSize">Size of the buffer allocated on the stack.</param>
2222
/// <typeparam name="T">Any <see cref="ISpanFormattable"/>.</typeparam>
2323
[MethodImpl(MethodImplOptions.AggressiveInlining)]
24-
public void Insert<T>(int index, T value, ReadOnlySpan<char> format = default, int bufferSize = 36)
24+
public void Insert<T>(int index, T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36)
2525
where T : ISpanFormattable => InsertSpanFormattable(index, value, format, bufferSize);
2626

2727
/// <summary>
@@ -60,7 +60,7 @@ public void Insert(int index, scoped ReadOnlySpan<char> value)
6060
}
6161

6262
[MethodImpl(MethodImplOptions.AggressiveInlining)]
63-
private void InsertSpanFormattable<T>(int index, T value, ReadOnlySpan<char> format, int bufferSize)
63+
private void InsertSpanFormattable<T>(int index, T value, scoped ReadOnlySpan<char> format, int bufferSize)
6464
where T : ISpanFormattable
6565
{
6666
if (index < 0)

src/LinkDotNet.StringBuilder/ValueStringBuilder.Replace.cs

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

34
namespace LinkDotNet.StringBuilder;
45

@@ -12,6 +13,17 @@ public ref partial struct ValueStringBuilder
1213
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1314
public readonly void Replace(char oldValue, char newValue) => Replace(oldValue, newValue, 0, Length);
1415

16+
/// <summary>
17+
/// Replaces all instances of one rune with another in this builder.
18+
/// </summary>
19+
/// <param name="oldValue">The rune to replace.</param>
20+
/// <param name="newValue">The rune to replace <paramref name="oldValue"/> with.</param>
21+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22+
public void Replace(Rune oldValue, Rune newValue)
23+
{
24+
Replace(oldValue, newValue, 0, Length);
25+
}
26+
1527
/// <summary>
1628
/// Replaces all instances of one character with another in this builder.
1729
/// </summary>
@@ -42,60 +54,37 @@ public readonly void Replace(char oldValue, char newValue, int startIndex, int c
4254
}
4355

4456
/// <summary>
45-
/// Replaces all instances of one string with another in this builder.
57+
/// Replaces all instances of one rune with another in this builder.
4658
/// </summary>
47-
/// <param name="oldValue">The string to replace.</param>
48-
/// <param name="newValue">The string to replace <paramref name="oldValue"/> with.</param>
49-
/// <remarks>
50-
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/>
51-
/// are removed from this builder.
52-
/// </remarks>
59+
/// <param name="oldValue">The rune to replace.</param>
60+
/// <param name="newValue">The rune to replace <paramref name="oldValue"/> with.</param>
61+
/// <param name="startIndex">The index to start in this builder.</param>
62+
/// <param name="count">The number of characters to read in this builder.</param>
5363
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54-
public void Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue)
55-
=> Replace(oldValue, newValue, 0, Length);
64+
public void Replace(Rune oldValue, Rune newValue, int startIndex, int count)
65+
{
66+
Span<char> oldValueChars = stackalloc char[2];
67+
int oldValueCharsWritten = oldValue.EncodeToUtf16(oldValueChars);
68+
ReadOnlySpan<char> oldValueCharsReadOnly = oldValueChars[..oldValueCharsWritten];
5669

57-
/// <summary>
58-
/// Replaces all instances of one string with another in this builder.
59-
/// </summary>
60-
/// <param name="oldValue">The string to replace.</param>
61-
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
62-
/// <remarks>
63-
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
64-
/// Otherwise the ToString method is called.
65-
/// </remarks>
66-
/// /// <typeparam name="T">Any type.</typeparam>
67-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
68-
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue)
69-
=> ReplaceGeneric(oldValue, newValue, 0, Length);
70+
Span<char> newValueChars = stackalloc char[2];
71+
int newValueCharsWritten = newValue.EncodeToUtf16(newValueChars);
72+
ReadOnlySpan<char> newValueCharsReadOnly = newValueChars[..newValueCharsWritten];
73+
74+
Replace(oldValueCharsReadOnly, newValueCharsReadOnly, startIndex, count);
75+
}
7076

7177
/// <summary>
7278
/// Replaces all instances of one string with another in this builder.
7379
/// </summary>
7480
/// <param name="oldValue">The string to replace.</param>
75-
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
76-
/// <param name="startIndex">The index to start in this builder.</param>
77-
/// <param name="count">The number of characters to read in this builder.</param>
81+
/// <param name="newValue">The string to replace <paramref name="oldValue"/> with.</param>
7882
/// <remarks>
79-
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
80-
/// Otherwise the ToString method is called.
83+
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/> are removed.
8184
/// </remarks>
82-
/// /// <typeparam name="T">Any type.</typeparam>
8385
[MethodImpl(MethodImplOptions.AggressiveInlining)]
84-
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue, int startIndex, int count)
85-
{
86-
if (newValue is ISpanFormattable spanFormattable)
87-
{
88-
Span<char> tempBuffer = stackalloc char[24];
89-
if (spanFormattable.TryFormat(tempBuffer, out var written, default, null))
90-
{
91-
Replace(oldValue, tempBuffer[..written], startIndex, count);
92-
}
93-
}
94-
else
95-
{
96-
Replace(oldValue, (ReadOnlySpan<char>)newValue?.ToString(), startIndex, count);
97-
}
98-
}
86+
public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char> newValue)
87+
=> Replace(oldValue, newValue, 0, Length);
9988

10089
/// <summary>
10190
/// Replaces all instances of one string with another in this builder.
@@ -105,8 +94,7 @@ public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue, int start
10594
/// <param name="startIndex">The index to start in this builder.</param>
10695
/// <param name="count">The number of characters to read in this builder.</param>
10796
/// <remarks>
108-
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/>
109-
/// are removed from this builder.
97+
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/> are removed.
11098
/// </remarks>
11199
[MethodImpl(MethodImplOptions.AggressiveInlining)]
112100
public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char> newValue, int startIndex, int count)
@@ -160,4 +148,47 @@ public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char
160148
}
161149
}
162150
}
151+
152+
/// <summary>
153+
/// Replaces all instances of one string with another in this builder.
154+
/// </summary>
155+
/// <param name="oldValue">The string to replace.</param>
156+
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
157+
/// <remarks>
158+
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
159+
/// Otherwise the ToString method is called.
160+
/// </remarks>
161+
/// /// <typeparam name="T">Any type.</typeparam>
162+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
163+
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue)
164+
=> ReplaceGeneric(oldValue, newValue, 0, Length);
165+
166+
/// <summary>
167+
/// Replaces all instances of one string with another in this builder.
168+
/// </summary>
169+
/// <param name="oldValue">The string to replace.</param>
170+
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
171+
/// <param name="startIndex">The index to start in this builder.</param>
172+
/// <param name="count">The number of characters to read in this builder.</param>
173+
/// <remarks>
174+
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
175+
/// Otherwise the ToString method is called.
176+
/// </remarks>
177+
/// /// <typeparam name="T">Any type.</typeparam>
178+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
179+
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue, int startIndex, int count)
180+
{
181+
if (newValue is ISpanFormattable spanFormattable)
182+
{
183+
Span<char> tempBuffer = stackalloc char[24];
184+
if (spanFormattable.TryFormat(tempBuffer, out var written, default, null))
185+
{
186+
Replace(oldValue, tempBuffer[..written], startIndex, count);
187+
}
188+
}
189+
else
190+
{
191+
Replace(oldValue, (ReadOnlySpan<char>)newValue?.ToString(), startIndex, count);
192+
}
193+
}
163194
}

0 commit comments

Comments
 (0)