@@ -459,13 +459,15 @@ public static ReadOnlySpan<char> ParentDirectory(this ReadOnlySpan<char> filePat
459
459
460
460
public static ReadOnlySpan < char > TrimEnd ( this ReadOnlySpan < char > value , params char [ ] trimChars )
461
461
{
462
+ if ( value . IsEmpty ) return TypeConstants . NullStringSpan ;
462
463
if ( trimChars == null || trimChars . Length == 0 )
463
464
return value . TrimHelper ( 1 ) ;
464
465
return value . TrimHelper ( trimChars , 1 ) ;
465
466
}
466
467
467
468
private static ReadOnlySpan < char > TrimHelper ( this ReadOnlySpan < char > value , int trimType )
468
469
{
470
+ if ( value . IsEmpty ) return TypeConstants . NullStringSpan ;
469
471
int end = value . Length - 1 ;
470
472
int start = 0 ;
471
473
if ( trimType != 1 )
@@ -485,6 +487,7 @@ private static ReadOnlySpan<char> TrimHelper(this ReadOnlySpan<char> value, int
485
487
486
488
private static ReadOnlySpan < char > TrimHelper ( this ReadOnlySpan < char > value , char [ ] trimChars , int trimType )
487
489
{
490
+ if ( value . IsEmpty ) return TypeConstants . NullStringSpan ;
488
491
int end = value . Length - 1 ;
489
492
int start = 0 ;
490
493
if ( trimType != 1 )
@@ -516,6 +519,7 @@ private static ReadOnlySpan<char> TrimHelper(this ReadOnlySpan<char> value, char
516
519
517
520
private static ReadOnlySpan < char > CreateTrimmedString ( this ReadOnlySpan < char > value , int start , int end )
518
521
{
522
+ if ( value . IsEmpty ) return TypeConstants . NullStringSpan ;
519
523
int length = end - start + 1 ;
520
524
if ( length == value . Length )
521
525
return value ;
@@ -539,6 +543,7 @@ public static ReadOnlySpan<char> SafeSlice(this ReadOnlySpan<char> value, int st
539
543
540
544
public static string SubstringWithEllipsis ( this ReadOnlySpan < char > value , int startIndex , int length )
541
545
{
546
+ if ( value . IsEmpty ) return string . Empty ;
542
547
var str = value . Slice ( startIndex , length ) ;
543
548
return str . Length == length
544
549
? str . ToString ( ) + "..."
@@ -656,6 +661,5 @@ public static int CountOccurrencesOf(this ReadOnlySpan<char> value, char needle)
656
661
}
657
662
return count ;
658
663
}
659
-
660
664
}
661
665
}
0 commit comments