Skip to content

Commit 1528871

Browse files
authored
Remove some static initializations in StringManipulationHelper (PowerShell#18243)
1 parent c1e6b41 commit 1528871

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/System.Management.Automation/FormatAndOutput/common/ComplexWriter.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ internal struct GetWordsResult
327327
/// </summary>
328328
internal sealed class StringManipulationHelper
329329
{
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+
333334
private static readonly Collection<string> s_cultureCollection = new Collection<string>();
334335

335336
static StringManipulationHelper()
@@ -377,13 +378,13 @@ private static IEnumerable<GetWordsResult> GetWords(string s)
377378
}
378379

379380
string delimiter = null;
380-
if (s[i] == ' ' || s[i] == '\t' || s[i] == s_softHyphen)
381+
if (s[i] is ' ' or '\t' or SoftHyphen)
381382
{
382383
// Soft hyphen = \u00AD - Should break, and add a hyphen if needed.
383384
// If not needed for a break, hyphen should be absent.
384385
delimiter = new string(s[i], 1);
385386
}
386-
else if (s[i] == s_hardHyphen || s[i] == s_nonBreakingSpace)
387+
else if (s[i] is HardHyphen or NonBreakingSpace)
387388
{
388389
// Non-breaking space = \u00A0 - ideally shouldn't wrap.
389390
// Hard hyphen = \u2011 - Should not break.
@@ -596,9 +597,9 @@ private static StringCollection GenerateLinesWithWordWrap(DisplayCells displayCe
596597
string suffix = null;
597598

598599
// 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)
600601
{
601-
int wordWidthWithHyphen = displayCells.Length(wordToAdd) + displayCells.Length(s_softHyphen);
602+
int wordWidthWithHyphen = displayCells.Length(wordToAdd) + displayCells.Length(SoftHyphen);
602603

603604
// Add hyphen only if necessary
604605
if (wordWidthWithHyphen == spacesLeft)
@@ -813,7 +814,7 @@ internal static string TruncateAtNewLine(string s)
813814
return string.Empty;
814815
}
815816

816-
int lineBreak = s.IndexOfAny(s_lineBreakChars);
817+
int lineBreak = s.AsSpan().IndexOfAny('\n', '\r');
817818

818819
if (lineBreak < 0)
819820
{
@@ -827,8 +828,5 @@ internal static string PadLeft(string val, int count)
827828
{
828829
return StringUtil.Padding(count) + val;
829830
}
830-
831-
private static readonly char[] s_newLineChar = new char[] { '\n' };
832-
private static readonly char[] s_lineBreakChars = new char[] { '\n', '\r' };
833831
}
834832
}

0 commit comments

Comments
 (0)