diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index 6d0c0ff250f..a3df2a6c390 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -85,7 +85,7 @@ internal ConsoleHostUserInterface(ConsoleHost parent) if (Environment.GetEnvironmentVariable("NO_COLOR") != null) { PSStyle.Instance.OutputRendering = OutputRendering.PlainText; - } + } } if (SupportsVirtualTerminal) @@ -961,7 +961,7 @@ internal List WrapText(string text, int maxWidthInBufferCells) int w = maxWidthInBufferCells - cellCounter; Dbg.Assert(w < e.Current.CellCount, "width remaining should be less than size of word"); - line.Append(e.Current.Text.Substring(0, w)); + line.Append(e.Current.Text.AsSpan(0, w)); l = line.ToString(); Dbg.Assert(RawUI.LengthInBufferCells(l) == maxWidthInBufferCells, "line should exactly fit"); @@ -2019,8 +2019,7 @@ internal string ReadLineWithTabCompletion(Executor exec) var completionResult = commandCompletion.GetNextResult(rlResult == ReadLineResult.endedOnTab); if (completionResult != null) { - completedInput = completionInput.Substring(0, commandCompletion.ReplacementIndex) - + completionResult.CompletionText; + completedInput = string.Concat(completionInput.AsSpan(0, commandCompletion.ReplacementIndex), completionResult.CompletionText); } else { diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressNode.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressNode.cs index 84f2f0355f2..17d852f952e 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressNode.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressNode.cs @@ -408,7 +408,7 @@ internal static bool IsMinimalProgressRenderingEnabled() int maxStatusLength = barWidth - secRemainLength - 1; if (maxStatusLength > 0 && StatusDescription.Length > barWidth - secRemainLength) { - sb.Append(StatusDescription.Substring(0, barWidth - secRemainLength - 1)); + sb.Append(StatusDescription.AsSpan(0, barWidth - secRemainLength - 1)); sb.Append(PSObjectHelper.Ellipsis); } else diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 35a7398454a..669c4c2a783 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -1209,7 +1209,7 @@ internal static List CompleteCommandArgument(CompletionContext if (ret != null && ret.Count > 0) { - var prefix = TokenKind.LParen.Text() + input.Substring(0, fakeReplacementIndex); + string prefix = string.Concat(TokenKind.LParen.Text(), input.AsSpan(0, fakeReplacementIndex)); foreach (CompletionResult entry in ret) { string completionText = prefix + entry.CompletionText; @@ -5394,11 +5394,11 @@ private static FunctionDefinitionAst GetCommentHelpFunctionTarget(CompletionCont return null; } - + private static List CompleteCommentParameterValue(CompletionContext context, string wordToComplete) { FunctionDefinitionAst foundFunction = GetCommentHelpFunctionTarget(context); - + ReadOnlyCollection foundParameters = null; if (foundFunction is not null) { @@ -5409,7 +5409,7 @@ private static List CompleteCommentParameterValue(CompletionCo // The helpblock is for a script file foundParameters = scriptAst.ParamBlock?.Parameters; } - + if (foundParameters is null || foundParameters.Count == 0) { return null; @@ -6531,7 +6531,7 @@ internal static List CompleteHelpTopics(CompletionContext cont //search for help files for the current culture + en-US as fallback var searchPaths = new string[] - { + { Path.Combine(userHelpDir, currentCulture), Path.Combine(appHelpDir, currentCulture), Path.Combine(userHelpDir, "en-US"), diff --git a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs index fa9781b682d..462eee91e6d 100644 --- a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs +++ b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs @@ -466,7 +466,7 @@ internal static string ResolvePath(string path, ExecutionContext context) { ProviderInfo fileSystemProvider = context.EngineSessionState.GetSingleProvider(FileSystemProvider.ProviderName); return new StringBuilder(fileSystemProvider.Home) - .Append(path.Substring(1)) + .Append(path.AsSpan(1)) .Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar) .ToString(); } diff --git a/src/System.Management.Automation/engine/debugger/debugger.cs b/src/System.Management.Automation/engine/debugger/debugger.cs index 30e83c38f90..2d049fe7602 100644 --- a/src/System.Management.Automation/engine/debugger/debugger.cs +++ b/src/System.Management.Automation/engine/debugger/debugger.cs @@ -1807,7 +1807,8 @@ private void OnDebuggerStop(InvocationInfo invocationInfo, List brea { // Fix up prompt. ++index; - string debugPrompt = "\"[DBG]: " + originalPromptString.Substring(index, originalPromptString.Length - index); + string debugPrompt = string.Concat("\"[DBG]: ", originalPromptString.AsSpan(index, originalPromptString.Length - index)); + defaultPromptInfo.Update( ScriptBlock.Create(debugPrompt), true, ScopedItemOptions.Unspecified); } diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs index ab34c0c6715..df30439f344 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs @@ -1262,7 +1262,7 @@ internal static void BuildHotkeysAndPlainLabels(Collection ch Text.StringBuilder splitLabel = new Text.StringBuilder(choices[i].Label.Substring(0, andPos), choices[i].Label.Length); if (andPos + 1 < choices[i].Label.Length) { - splitLabel.Append(choices[i].Label.Substring(andPos + 1)); + splitLabel.Append(choices[i].Label.AsSpan(andPos + 1)); hotkeysAndPlainLabels[0, i] = CultureInfo.CurrentCulture.TextInfo.ToUpper(choices[i].Label.AsSpan(andPos + 1, 1).Trim().ToString()); } diff --git a/src/System.Management.Automation/help/HelpCommentsParser.cs b/src/System.Management.Automation/help/HelpCommentsParser.cs index 7fad99a09c9..36d0cb6450e 100644 --- a/src/System.Management.Automation/help/HelpCommentsParser.cs +++ b/src/System.Management.Automation/help/HelpCommentsParser.cs @@ -628,7 +628,7 @@ private static string GetSection(List commentLines, ref int i) start++; } - sb.Append(line.Substring(start)); + sb.Append(line.AsSpan(start)); sb.Append('\n'); }