@@ -327,9 +327,10 @@ internal struct GetWordsResult
327
327
/// </summary>
328
328
internal sealed class StringManipulationHelper
329
329
{
330
- private static readonly char s_softHyphen = '\u00AD ' ;
331
- private static readonly char s_hardHyphen = '\u2011 ' ;
332
- private static readonly char s_nonBreakingSpace = '\u00A0 ' ;
330
+ private const char SoftHyphen = '\u00AD ' ;
331
+ private const char HardHyphen = '\u2011 ' ;
332
+ private const char NonBreakingSpace = '\u00A0 ' ;
333
+
333
334
private static readonly Collection < string > s_cultureCollection = new Collection < string > ( ) ;
334
335
335
336
static StringManipulationHelper ( )
@@ -377,13 +378,13 @@ private static IEnumerable<GetWordsResult> GetWords(string s)
377
378
}
378
379
379
380
string delimiter = null ;
380
- if ( s [ i ] == ' ' || s [ i ] == '\t ' || s [ i ] == s_softHyphen )
381
+ if ( s [ i ] is ' ' or '\t ' or SoftHyphen )
381
382
{
382
383
// Soft hyphen = \u00AD - Should break, and add a hyphen if needed.
383
384
// If not needed for a break, hyphen should be absent.
384
385
delimiter = new string ( s [ i ] , 1 ) ;
385
386
}
386
- else if ( s [ i ] == s_hardHyphen || s [ i ] == s_nonBreakingSpace )
387
+ else if ( s [ i ] is HardHyphen or NonBreakingSpace )
387
388
{
388
389
// Non-breaking space = \u00A0 - ideally shouldn't wrap.
389
390
// Hard hyphen = \u2011 - Should not break.
@@ -596,9 +597,9 @@ private static StringCollection GenerateLinesWithWordWrap(DisplayCells displayCe
596
597
string suffix = null ;
597
598
598
599
// Handle soft hyphen
599
- if ( word . Delim . Length == 1 && word . Delim [ 0 ] == s_softHyphen )
600
+ if ( word . Delim . Length == 1 && word . Delim [ 0 ] is SoftHyphen )
600
601
{
601
- int wordWidthWithHyphen = displayCells . Length ( wordToAdd ) + displayCells . Length ( s_softHyphen ) ;
602
+ int wordWidthWithHyphen = displayCells . Length ( wordToAdd ) + displayCells . Length ( SoftHyphen ) ;
602
603
603
604
// Add hyphen only if necessary
604
605
if ( wordWidthWithHyphen == spacesLeft )
@@ -813,7 +814,7 @@ internal static string TruncateAtNewLine(string s)
813
814
return string . Empty ;
814
815
}
815
816
816
- int lineBreak = s . IndexOfAny ( s_lineBreakChars ) ;
817
+ int lineBreak = s . AsSpan ( ) . IndexOfAny ( ' \n ' , ' \r ' ) ;
817
818
818
819
if ( lineBreak < 0 )
819
820
{
@@ -827,8 +828,5 @@ internal static string PadLeft(string val, int count)
827
828
{
828
829
return StringUtil . Padding ( count ) + val ;
829
830
}
830
-
831
- private static readonly char [ ] s_newLineChar = new char [ ] { '\n ' } ;
832
- private static readonly char [ ] s_lineBreakChars = new char [ ] { '\n ' , '\r ' } ;
833
831
}
834
832
}
0 commit comments