1
1
using System . Runtime . CompilerServices ;
2
+ using System . Text ;
2
3
3
4
namespace LinkDotNet . StringBuilder ;
4
5
@@ -12,6 +13,17 @@ public ref partial struct ValueStringBuilder
12
13
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
13
14
public readonly void Replace ( char oldValue , char newValue ) => Replace ( oldValue , newValue , 0 , Length ) ;
14
15
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
+
15
27
/// <summary>
16
28
/// Replaces all instances of one character with another in this builder.
17
29
/// </summary>
@@ -41,6 +53,27 @@ public readonly void Replace(char oldValue, char newValue, int startIndex, int c
41
53
}
42
54
}
43
55
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
+
44
77
/// <summary>
45
78
/// Replaces all instances of one string with another in this builder.
46
79
/// </summary>
@@ -51,7 +84,7 @@ public readonly void Replace(char oldValue, char newValue, int startIndex, int c
51
84
/// are removed from this builder.
52
85
/// </remarks>
53
86
[ 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 )
55
88
=> Replace ( oldValue , newValue , 0 , Length ) ;
56
89
57
90
/// <summary>
@@ -65,7 +98,7 @@ public void Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue)
65
98
/// </remarks>
66
99
/// /// <typeparam name="T">Any type.</typeparam>
67
100
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
68
- public void ReplaceGeneric < T > ( ReadOnlySpan < char > oldValue , T newValue )
101
+ public void ReplaceGeneric < T > ( scoped ReadOnlySpan < char > oldValue , T newValue )
69
102
=> ReplaceGeneric ( oldValue , newValue , 0 , Length ) ;
70
103
71
104
/// <summary>
@@ -81,7 +114,7 @@ public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue)
81
114
/// </remarks>
82
115
/// /// <typeparam name="T">Any type.</typeparam>
83
116
[ 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 )
85
118
{
86
119
if ( newValue is ISpanFormattable spanFormattable )
87
120
{
0 commit comments