File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
src/LinkDotNet.StringBuilder
tests/LinkDotNet.StringBuilder.UnitTests Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
88
99### Added
1010
11- - New overload for ` Append ` that accepts a ` ReadOnlyMemory ` object
11+ - New overload for ` Append ` that accepts a ` ReadOnlyMemory ` object
12+ - New ` ToString ` overload that accepts a ` Range ` object
1213
1314### Changed
1415
Original file line number Diff line number Diff line change @@ -109,6 +109,17 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
109109 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
110110 public readonly string ToString ( int startIndex , int length ) => new ( buffer [ startIndex ..( startIndex + length ) ] ) ;
111111
112+ /// <summary>
113+ /// Creates a <see cref="string"/> instance from that builder in the given range.
114+ /// </summary>
115+ /// <param name="range">The range that will be retrieved.</param>
116+ /// <returns>The <see cref="string"/> instance.</returns>
117+ public readonly string ToString ( Range range )
118+ {
119+ var ( offset , length ) = range . GetOffsetAndLength ( bufferPosition ) ;
120+ return new string ( buffer . Slice ( offset , length ) ) ;
121+ }
122+
112123 /// <summary>
113124 /// Returns the string as an <see cref="ReadOnlySpan{T}"/>.
114125 /// </summary>
Original file line number Diff line number Diff line change @@ -481,4 +481,12 @@ public void ShouldReverseString()
481481
482482 builder . ToString ( ) . Should ( ) . Be ( "olleH" ) ;
483483 }
484+
485+ [ Fact ]
486+ public void GivenAString_WhenCallingToStringWithRange_ThenShouldReturnSubstring ( )
487+ {
488+ using var builder = new ValueStringBuilder ( "Hello World" ) ;
489+
490+ builder . ToString ( 1 ..4 ) . Should ( ) . Be ( "ell" ) ;
491+ }
484492}
You can’t perform that action at this time.
0 commit comments