11using System . Runtime . CompilerServices ;
2+ using System . Text ;
23
34namespace 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>
@@ -41,6 +53,27 @@ public readonly void Replace(char oldValue, char newValue, int startIndex, int c
4153 }
4254 }
4355
56+ /// <summary>
57+ /// Replaces all instances of one rune with another in this builder.
58+ /// </summary>
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>
63+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
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 ] ;
69+
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+ }
76+
4477 /// <summary>
4578 /// Replaces all instances of one string with another in this builder.
4679 /// </summary>
@@ -51,7 +84,7 @@ public readonly void Replace(char oldValue, char newValue, int startIndex, int c
5184 /// are removed from this builder.
5285 /// </remarks>
5386 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
54- public void Replace ( ReadOnlySpan < char > oldValue , ReadOnlySpan < char > newValue )
87+ public void Replace ( scoped ReadOnlySpan < char > oldValue , scoped ReadOnlySpan < char > newValue )
5588 => Replace ( oldValue , newValue , 0 , Length ) ;
5689
5790 /// <summary>
@@ -65,7 +98,7 @@ public void Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue)
6598 /// </remarks>
6699 /// /// <typeparam name="T">Any type.</typeparam>
67100 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
68- public void ReplaceGeneric < T > ( ReadOnlySpan < char > oldValue , T newValue )
101+ public void ReplaceGeneric < T > ( scoped ReadOnlySpan < char > oldValue , T newValue )
69102 => ReplaceGeneric ( oldValue , newValue , 0 , Length ) ;
70103
71104 /// <summary>
@@ -81,7 +114,7 @@ public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue)
81114 /// </remarks>
82115 /// /// <typeparam name="T">Any type.</typeparam>
83116 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
84- public void ReplaceGeneric < T > ( ReadOnlySpan < char > oldValue , T newValue , int startIndex , int count )
117+ public void ReplaceGeneric < T > ( scoped ReadOnlySpan < char > oldValue , T newValue , int startIndex , int count )
85118 {
86119 if ( newValue is ISpanFormattable spanFormattable )
87120 {
0 commit comments