@@ -47,56 +47,12 @@ public readonly void Replace(char oldValue, char newValue, int startIndex, int c
4747 /// <param name="oldValue">The string to replace.</param>
4848 /// <param name="newValue">The string to replace <paramref name="oldValue"/> with.</param>
4949 /// <remarks>
50- /// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/>
51- /// are removed from this builder.
50+ /// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/> are removed.
5251 /// </remarks>
5352 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5453 public void Replace ( ReadOnlySpan < char > oldValue , ReadOnlySpan < char > newValue )
5554 => Replace ( oldValue , newValue , 0 , Length ) ;
5655
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-
71- /// <summary>
72- /// Replaces all instances of one string with another in this builder.
73- /// </summary>
74- /// <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>
78- /// <remarks>
79- /// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
80- /// Otherwise the ToString method is called.
81- /// </remarks>
82- /// /// <typeparam name="T">Any type.</typeparam>
83- [ 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- }
99-
10056 /// <summary>
10157 /// Replaces all instances of one string with another in this builder.
10258 /// </summary>
@@ -105,8 +61,7 @@ public void ReplaceGeneric<T>(ReadOnlySpan<char> oldValue, T newValue, int start
10561 /// <param name="startIndex">The index to start in this builder.</param>
10662 /// <param name="count">The number of characters to read in this builder.</param>
10763 /// <remarks>
108- /// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/>
109- /// are removed from this builder.
64+ /// If <paramref name="newValue"/> is <c>empty</c>, instances of <paramref name="oldValue"/> are removed.
11065 /// </remarks>
11166 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
11267 public void Replace ( scoped ReadOnlySpan < char > oldValue , scoped ReadOnlySpan < char > newValue , int startIndex , int count )
@@ -160,4 +115,47 @@ public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char
160115 }
161116 }
162117 }
118+
119+ /// <summary>
120+ /// Replaces all instances of one string with another in this builder.
121+ /// </summary>
122+ /// <param name="oldValue">The string to replace.</param>
123+ /// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
124+ /// <remarks>
125+ /// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
126+ /// Otherwise the ToString method is called.
127+ /// </remarks>
128+ /// /// <typeparam name="T">Any type.</typeparam>
129+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
130+ public void ReplaceGeneric < T > ( ReadOnlySpan < char > oldValue , T newValue )
131+ => ReplaceGeneric ( oldValue , newValue , 0 , Length ) ;
132+
133+ /// <summary>
134+ /// Replaces all instances of one string with another in this builder.
135+ /// </summary>
136+ /// <param name="oldValue">The string to replace.</param>
137+ /// <param name="newValue">Object to replace <paramref name="oldValue"/> with.</param>
138+ /// <param name="startIndex">The index to start in this builder.</param>
139+ /// <param name="count">The number of characters to read in this builder.</param>
140+ /// <remarks>
141+ /// If <paramref name="newValue"/> is from type <see cref="ISpanFormattable"/> an optimized version is taken.
142+ /// Otherwise the ToString method is called.
143+ /// </remarks>
144+ /// /// <typeparam name="T">Any type.</typeparam>
145+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
146+ public void ReplaceGeneric < T > ( ReadOnlySpan < char > oldValue , T newValue , int startIndex , int count )
147+ {
148+ if ( newValue is ISpanFormattable spanFormattable )
149+ {
150+ Span < char > tempBuffer = stackalloc char [ 24 ] ;
151+ if ( spanFormattable . TryFormat ( tempBuffer , out var written , default , null ) )
152+ {
153+ Replace ( oldValue , tempBuffer [ ..written ] , startIndex , count ) ;
154+ }
155+ }
156+ else
157+ {
158+ Replace ( oldValue , ( ReadOnlySpan < char > ) newValue ? . ToString ( ) , startIndex , count ) ;
159+ }
160+ }
163161}
0 commit comments