From c1e6b41f98baddee63debc800eca3588db820a25 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 19 Oct 2022 22:18:09 +0100 Subject: [PATCH] Use `MemoryExtensions.IndexOfAny` in `PSv2CompletionCompleter`` (#18245) --- .../engine/CommandCompletion/CommandCompletion.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs index 409cb902f7..7c700317e8 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs @@ -691,8 +691,9 @@ namespace System.Management.Automation /// private static class PSv2CompletionCompleter { + private const string CharsRequiringQuotedString = "`&@'#{}()$,;|<> \t"; + private static readonly Regex s_cmdletTabRegex = new Regex(@"^[\w\*\?]+-[\w\*\?]*"); - private static readonly char[] s_charsRequiringQuotedString = "`&@'#{}()$,;|<> \t".ToCharArray(); #region "Handle Command" @@ -939,7 +940,7 @@ namespace System.Management.Automation private static string AddQuoteIfNecessary(string completionText, string quote, bool completingAtStartOfLine) { - if (completionText.IndexOfAny(s_charsRequiringQuotedString) != -1) + if (completionText.AsSpan().IndexOfAny(CharsRequiringQuotedString) >= 0) { bool needAmpersand = quote.Length == 0 && completingAtStartOfLine; string quoteInUse = quote.Length == 0 ? "'" : quote;