File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,15 @@ public static void TrimNullTerminators(ref Span<char> chars)
39
39
chars = chars . Slice ( 0 , i ) ;
40
40
}
41
41
}
42
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining | MethodImplOptions . AggressiveOptimization ) ]
43
+ public static void TrimNullTerminators ( ref ReadOnlySpan < char > chars )
44
+ {
45
+ int i = chars . IndexOf ( '\0 ' ) ;
46
+ if ( i != - 1 )
47
+ {
48
+ chars = chars . Slice ( 0 , i ) ;
49
+ }
50
+ }
42
51
43
52
#region Read
44
53
Original file line number Diff line number Diff line change @@ -201,4 +201,13 @@ public void SpanIsProperlyTrimmed()
201
201
202
202
Assert . True ( test . SequenceEqual ( "Kermalis" ) ) ;
203
203
}
204
+
205
+ [ Fact ]
206
+ public void ReadOnlySpanIsProperlyTrimmed ( )
207
+ {
208
+ ReadOnlySpan < char > test = "Kermalis\0 \0 " ;
209
+ EndianBinaryPrimitives . TrimNullTerminators ( ref test ) ;
210
+
211
+ Assert . True ( test . SequenceEqual ( "Kermalis" ) ) ;
212
+ }
204
213
}
You can’t perform that action at this time.
0 commit comments