@@ -5,7 +5,7 @@ namespace LinkDotNet.StringBuilder;
55public ref partial struct ValueStringBuilder
66{
77 /// <summary>
8- /// Removes a set of whitespace characters from the beginning and ending of this string .
8+ /// Removes all whitespace characters from the start and end of this builder .
99 /// </summary>
1010 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1111 public void Trim ( )
@@ -33,22 +33,22 @@ public void Trim()
3333 }
3434
3535 /// <summary>
36- /// Removes the specified character from the beginning and end of this string .
36+ /// Removes all occurrences of the specified character from the start and end of this builder .
3737 /// </summary>
38- /// <param name="c ">The character to remove.</param>
38+ /// <param name="value ">The character to remove.</param>
3939 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
40- public void Trim ( char c )
40+ public void Trim ( char value )
4141 {
4242 // Remove character from the beginning
4343 var start = 0 ;
44- while ( start < bufferPosition && buffer [ start ] == c )
44+ while ( start < bufferPosition && buffer [ start ] == value )
4545 {
4646 start ++ ;
4747 }
4848
4949 // Remove character from the end
5050 var end = bufferPosition - 1 ;
51- while ( end >= start && buffer [ end ] == c )
51+ while ( end >= start && buffer [ end ] == value )
5252 {
5353 end -- ;
5454 }
@@ -62,7 +62,7 @@ public void Trim(char c)
6262 }
6363
6464 /// <summary>
65- /// Removes a set of whitespace characters from the beginning of this string .
65+ /// Removes all whitespace characters from the start of this builder .
6666 /// </summary>
6767 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
6868 public void TrimStart ( )
@@ -82,14 +82,14 @@ public void TrimStart()
8282 }
8383
8484 /// <summary>
85- /// Removes the specified character from the beginning of this string .
85+ /// Removes all occurrences of the specified character from the start of this builder .
8686 /// </summary>
87- /// <param name="c ">The character to remove.</param>
87+ /// <param name="value ">The character to remove.</param>
8888 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
89- public void TrimStart ( char c )
89+ public void TrimStart ( char value )
9090 {
9191 var start = 0 ;
92- while ( start < bufferPosition && buffer [ start ] == c )
92+ while ( start < bufferPosition && buffer [ start ] == value )
9393 {
9494 start ++ ;
9595 }
@@ -103,7 +103,7 @@ public void TrimStart(char c)
103103 }
104104
105105 /// <summary>
106- /// Removes a set of whitespace characters from the ending of this string .
106+ /// Removes all whitespace characters from the end of this builder .
107107 /// </summary>
108108 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
109109 public void TrimEnd ( )
@@ -118,18 +118,46 @@ public void TrimEnd()
118118 }
119119
120120 /// <summary>
121- /// Removes the specified character from the end of this string .
121+ /// Removes all occurrences of the specified character from the end of this builder .
122122 /// </summary>
123- /// <param name="c ">The character to remove.</param>
123+ /// <param name="value ">The character to remove.</param>
124124 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
125- public void TrimEnd ( char c )
125+ public void TrimEnd ( char value )
126126 {
127127 var end = bufferPosition - 1 ;
128- while ( end >= 0 && buffer [ end ] == c )
128+ while ( end >= 0 && buffer [ end ] == value )
129129 {
130130 end -- ;
131131 }
132132
133133 bufferPosition = end + 1 ;
134134 }
135+
136+ /// <summary>
137+ /// Removes the specified sequence of characters from the start of this builder.
138+ /// </summary>
139+ /// <param name="value">The sequence of characters to remove.</param>
140+ /// <param name="comparisonType">The way to compare the sequences of characters.</param>
141+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
142+ public void TrimPrefix ( ReadOnlySpan < char > value , StringComparison comparisonType = StringComparison . Ordinal )
143+ {
144+ if ( AsSpan ( ) . StartsWith ( value , comparisonType ) )
145+ {
146+ Remove ( 0 , value . Length ) ;
147+ }
148+ }
149+
150+ /// <summary>
151+ /// Removes the specified sequence of characters from the end of this builder.
152+ /// </summary>
153+ /// <param name="value">The sequence of characters to remove.</param>
154+ /// <param name="comparisonType">The way to compare the sequences of characters.</param>
155+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
156+ public void TrimSuffix ( ReadOnlySpan < char > value , StringComparison comparisonType = StringComparison . Ordinal )
157+ {
158+ if ( AsSpan ( ) . EndsWith ( value , comparisonType ) )
159+ {
160+ Remove ( Length - value . Length , value . Length ) ;
161+ }
162+ }
135163}
0 commit comments