Skip to content

Commit

Permalink
Updating to newest release
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkDotNet Bot committed Jan 14, 2025
2 parents e313cd6 + f1831e7 commit 5f7f509
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 80 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T

## [Unreleased]

## [2.1.0] - 2025-01-14

### Added

- Added `Replace(Rune, Rune)` overload
- Added `Replace(Rune, Rune, int, int)` overload

## [2.0.0] - 2025-01-12

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`.
Expand Down Expand Up @@ -438,7 +445,8 @@ This release brings extensions to the `ValueStringBuilder` API. For `v1.0` the `

- Initial release

[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/2.0.0...HEAD
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/2.1.0...HEAD
[2.1.0]: https://github.com/linkdotnet/StringBuilder/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/linkdotnet/StringBuilder/compare/1.22.0...2.0.0
[1.22.0]: https://github.com/linkdotnet/StringBuilder/compare/1.21.1...1.22.0
[1.21.1]: https://github.com/linkdotnet/StringBuilder/compare/1.21.0...1.21.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<LangVersion>preview</LangVersion>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace LinkDotNet.StringBuilder;
public ref partial struct ValueStringBuilder
{
/// <summary>
/// Appends the string representation of the boolean to the builder.
/// Appends the string representation of the boolean.
/// </summary>
/// <param name="value">Bool value to add.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -46,7 +46,7 @@ public unsafe void Append(bool value)
}

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

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

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

/// <summary>
/// Appends a single character to the string builder.
/// Appends a single character.
/// </summary>
/// <param name="value">Character to add.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -142,7 +142,7 @@ public void AppendLine()
}

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

/// <summary>
/// Increases the size of the string builder returning a span of the length appended.
/// Appends a span of the given length, which can be written to later.
/// </summary>
/// <param name="length">Integer representing the length to be appended.</param>
/// <param name="length">Integer representing the number of characters to be appended.</param>
/// <returns>A span with the characters appended.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<char> AppendSpan(int length)
Expand Down
28 changes: 14 additions & 14 deletions src/LinkDotNet.StringBuilder/ValueStringBuilder.AppendFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void AppendFormat<T>(
/// <param name="format">Format string.</param>
/// <param name="arg1">Argument for <c>{0}</c>.</param>
/// <param name="arg2">Argument for <c>{1}</c>.</param>
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
/// <remarks>
/// The current version does not allow for a custom format.
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.
Expand Down Expand Up @@ -132,9 +132,9 @@ public void AppendFormat<T1, T2>(
/// <param name="arg1">Argument for <c>{0}</c>.</param>
/// <param name="arg2">Argument for <c>{1}</c>.</param>
/// <param name="arg3">Argument for <c>{2}</c>.</param>
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
/// <typeparam name="T3">Any type for <param name="arg3"></param>.</typeparam>
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
/// <typeparam name="T3">Any type for <paramref name="arg3"/>.</typeparam>
/// <remarks>
/// The current version does not allow for a custom format.
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.
Expand Down Expand Up @@ -205,10 +205,10 @@ public void AppendFormat<T1, T2, T3>(
/// <param name="arg2">Argument for <c>{1}</c>.</param>
/// <param name="arg3">Argument for <c>{2}</c>.</param>
/// <param name="arg4">Argument for <c>{3}</c>.</param>
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
/// <typeparam name="T3">Any type for <param name="arg3"></param>.</typeparam>
/// <typeparam name="T4">Any type for <param name="arg4"></param>.</typeparam>
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
/// <typeparam name="T3">Any type for <paramref name="arg3"/>.</typeparam>
/// <typeparam name="T4">Any type for <paramref name="arg4"/>.</typeparam>
/// <remarks>
/// The current version does not allow for a custom format.
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.
Expand Down Expand Up @@ -284,11 +284,11 @@ public void AppendFormat<T1, T2, T3, T4>(
/// <param name="arg3">Argument for <c>{2}</c>.</param>
/// <param name="arg4">Argument for <c>{3}</c>.</param>
/// <param name="arg5">Argument for <c>{4}</c>.</param>
/// <typeparam name="T1">Any type for <param name="arg1"></param>.</typeparam>
/// <typeparam name="T2">Any type for <param name="arg2"></param>.</typeparam>
/// <typeparam name="T3">Any type for <param name="arg3"></param>.</typeparam>
/// <typeparam name="T4">Any type for <param name="arg4"></param>.</typeparam>
/// <typeparam name="T5">Any type for <param name="arg5"></param>.</typeparam>
/// <typeparam name="T1">Any type for <paramref name="arg1"/>.</typeparam>
/// <typeparam name="T2">Any type for <paramref name="arg2"/>.</typeparam>
/// <typeparam name="T3">Any type for <paramref name="arg3"/>.</typeparam>
/// <typeparam name="T4">Any type for <paramref name="arg4"/>.</typeparam>
/// <typeparam name="T5">Any type for <paramref name="arg5"/>.</typeparam>
/// <remarks>
/// The current version does not allow for a custom format.
/// So: <code>AppendFormat("{0:00}")</code> is not allowed and will result in an exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public ref partial struct ValueStringBuilder
/// <summary>
/// Concatenates multiple objects together.
/// </summary>
/// <param name="values">Values, which will be concatenated together.</param>
/// <param name="values">Values to be concatenated together.</param>
/// <typeparam name="T">Any given type, which can be translated to <see cref="string"/>.</typeparam>
/// <returns>Concatenated string or an empty string if <see cref="values"/> is empty.</returns>
/// <returns>Concatenated string or an empty string if <paramref name="values"/> is empty.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Concat<T>(params T[] values)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ namespace LinkDotNet.StringBuilder;

public ref partial struct ValueStringBuilder
{
/// <summary>
/// Creates an enumerator over the characters in the builder.
/// </summary>
/// <returns>An enumerator over the characters in the builder.</returns>
public readonly Enumerator GetEnumerator() => new(buffer[..bufferPosition]);

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

/// <summary>Advances the enumerator to the next element of the span.</summary>
/// <returns>True if the enumerator was successfully advancing to the next element; false if the enumerator has passed the end of the span.</returns>
/// <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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext() => ++index < span.Length;
}
Expand Down
4 changes: 2 additions & 2 deletions src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ref partial struct ValueStringBuilder
/// <param name="bufferSize">Size of the buffer allocated on the stack.</param>
/// <typeparam name="T">Any <see cref="ISpanFormattable"/>.</typeparam>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Insert<T>(int index, T value, ReadOnlySpan<char> format = default, int bufferSize = 36)
public void Insert<T>(int index, T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36)
where T : ISpanFormattable => InsertSpanFormattable(index, value, format, bufferSize);

/// <summary>
Expand Down Expand Up @@ -60,7 +60,7 @@ public void Insert(int index, scoped ReadOnlySpan<char> value)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void InsertSpanFormattable<T>(int index, T value, ReadOnlySpan<char> format, int bufferSize)
private void InsertSpanFormattable<T>(int index, T value, scoped ReadOnlySpan<char> format, int bufferSize)
where T : ISpanFormattable
{
if (index < 0)
Expand Down
121 changes: 76 additions & 45 deletions src/LinkDotNet.StringBuilder/ValueStringBuilder.Replace.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using System.Text;

namespace LinkDotNet.StringBuilder;

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

/// <summary>
/// Replaces all instances of one rune with another in this builder.
/// </summary>
/// <param name="oldValue">The rune to replace.</param>
/// <param name="newValue">The rune to replace <paramref name="oldValue"/> with.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Replace(Rune oldValue, Rune newValue)
{
Replace(oldValue, newValue, 0, Length);
}

/// <summary>
/// Replaces all instances of one character with another in this builder.
/// </summary>
Expand Down Expand Up @@ -42,60 +54,37 @@ public readonly void Replace(char oldValue, char newValue, int startIndex, int c
}

/// <summary>
/// Replaces all instances of one string with another in this builder.
/// Replaces all instances of one rune with another in this builder.
/// </summary>
/// <param name="oldValue">The string to replace.</param>
/// <param name="newValue">The string to replace <paramref name="oldValue"/> with.</param>
/// <remarks>
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/>
/// are removed from this builder.
/// </remarks>
/// <param name="oldValue">The rune to replace.</param>
/// <param name="newValue">The rune to replace <paramref name="oldValue"/> with.</param>
/// <param name="startIndex">The index to start in this builder.</param>
/// <param name="count">The number of characters to read in this builder.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue)
=> Replace(oldValue, newValue, 0, Length);
public void Replace(Rune oldValue, Rune newValue, int startIndex, int count)
{
Span<char> oldValueChars = stackalloc char[2];
int oldValueCharsWritten = oldValue.EncodeToUtf16(oldValueChars);
ReadOnlySpan<char> oldValueCharsReadOnly = oldValueChars[..oldValueCharsWritten];

/// <summary>
/// Replaces all instances of one string with another in this builder.
/// </summary>
/// <param name="oldValue">The string to replace.</param>
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
/// <remarks>
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
/// Otherwise the ToString method is called.
/// </remarks>
/// /// <typeparam name="T">Any type.</typeparam>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue)
=> ReplaceGeneric(oldValue, newValue, 0, Length);
Span<char> newValueChars = stackalloc char[2];
int newValueCharsWritten = newValue.EncodeToUtf16(newValueChars);
ReadOnlySpan<char> newValueCharsReadOnly = newValueChars[..newValueCharsWritten];

Replace(oldValueCharsReadOnly, newValueCharsReadOnly, startIndex, count);
}

/// <summary>
/// Replaces all instances of one string with another in this builder.
/// </summary>
/// <param name="oldValue">The string to replace.</param>
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
/// <param name="startIndex">The index to start in this builder.</param>
/// <param name="count">The number of characters to read in this builder.</param>
/// <param name="newValue">The string to replace <paramref name="oldValue"/> with.</param>
/// <remarks>
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
/// Otherwise the ToString method is called.
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/> are removed.
/// </remarks>
/// /// <typeparam name="T">Any type.</typeparam>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue, int startIndex, int count)
{
if (newValue is ISpanFormattable spanFormattable)
{
Span<char> tempBuffer = stackalloc char[24];
if (spanFormattable.TryFormat(tempBuffer, out var written, default, null))
{
Replace(oldValue, tempBuffer[..written], startIndex, count);
}
}
else
{
Replace(oldValue, (ReadOnlySpan<char>)newValue?.ToString(), startIndex, count);
}
}
public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char> newValue)
=> Replace(oldValue, newValue, 0, Length);

/// <summary>
/// Replaces all instances of one string with another in this builder.
Expand All @@ -105,8 +94,7 @@ public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue, int start
/// <param name="startIndex">The index to start in this builder.</param>
/// <param name="count">The number of characters to read in this builder.</param>
/// <remarks>
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/>
/// are removed from this builder.
/// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/> are removed.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char> newValue, int startIndex, int count)
Expand Down Expand Up @@ -160,4 +148,47 @@ public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char
}
}
}

/// <summary>
/// Replaces all instances of one string with another in this builder.
/// </summary>
/// <param name="oldValue">The string to replace.</param>
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
/// <remarks>
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
/// Otherwise the ToString method is called.
/// </remarks>
/// /// <typeparam name="T">Any type.</typeparam>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue)
=> ReplaceGeneric(oldValue, newValue, 0, Length);

/// <summary>
/// Replaces all instances of one string with another in this builder.
/// </summary>
/// <param name="oldValue">The string to replace.</param>
/// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
/// <param name="startIndex">The index to start in this builder.</param>
/// <param name="count">The number of characters to read in this builder.</param>
/// <remarks>
/// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
/// Otherwise the ToString method is called.
/// </remarks>
/// /// <typeparam name="T">Any type.</typeparam>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue, int startIndex, int count)
{
if (newValue is ISpanFormattable spanFormattable)
{
Span<char> tempBuffer = stackalloc char[24];
if (spanFormattable.TryFormat(tempBuffer, out var written, default, null))
{
Replace(oldValue, tempBuffer[..written], startIndex, count);
}
}
else
{
Replace(oldValue, (ReadOnlySpan<char>)newValue?.ToString(), startIndex, count);
}
}
}
Loading

0 comments on commit 5f7f509

Please sign in to comment.