Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected override void ProcessRecord()
// representation, then parse it into its components.
byte[] inputBytes = Convert.FromBase64String(remainingData);
string dataPackage = System.Text.Encoding.Unicode.GetString(inputBytes);
string[] dataElements = dataPackage.Split(Utils.Separators.Pipe);
string[] dataElements = dataPackage.Split('|');

if (dataElements.Length == 3)
{
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/DscSupport/CimDSCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ private static CimClass MyClassCallback(string serverName, string namespaceName,
{
foreach (KeyValuePair<string, DscClassCacheEntry> cimClass in ClassCache)
{
string cachedClassName = cimClass.Key.Split(Utils.Separators.Backslash)[IndexClassName];
string cachedClassName = cimClass.Key.Split('\\')[IndexClassName];
if (string.Equals(cachedClassName, className, StringComparison.OrdinalIgnoreCase))
{
return cimClass.Value.CimClassInstance;
Expand Down Expand Up @@ -1099,7 +1099,7 @@ private static string GetModuleQualifiedResourceName(string moduleName, string m
private static List<KeyValuePair<string, DscClassCacheEntry>> FindResourceInCache(string moduleName, string className, string resourceName)
{
return (from cacheEntry in ClassCache
let splittedName = cacheEntry.Key.Split(Utils.Separators.Backslash)
let splittedName = cacheEntry.Key.Split('\\')
let cachedClassName = splittedName[IndexClassName]
let cachedModuleName = splittedName[IndexModuleName]
let cachedResourceName = splittedName[IndexFriendlyName]
Expand Down Expand Up @@ -1295,7 +1295,7 @@ public static Collection<DynamicKeyword> GetCachedKeywords()

foreach (KeyValuePair<string, DscClassCacheEntry> cachedClass in ClassCache)
{
string[] splittedName = cachedClass.Key.Split(Utils.Separators.Backslash);
string[] splittedName = cachedClass.Key.Split('\\');
string moduleName = splittedName[IndexModuleName];
string moduleVersion = splittedName[IndexModuleVersion];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ private string GetObjectDisplayName(PSObject so)
if (_complexSpecificParameters.classDisplay == ComplexSpecificParameters.ClassInfoDisplay.shortName)
{
// get the last token in the full name
string[] arr = typeNames[0].Split(Utils.Separators.Dot);
string[] arr = typeNames[0].Split('.');
if (arr.Length > 0)
return arr[arr.Length - 1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ private static bool PSv2IsCommandLikeCmdlet(string lastWord, out bool isSnapinSp
{
isSnapinSpecified = false;

string[] cmdletParts = lastWord.Split(Utils.Separators.Backslash);
string[] cmdletParts = lastWord.Split('\\');
if (cmdletParts.Length == 1)
{
return s_cmdletTabRegex.IsMatch(lastWord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ internal static AstAnalysisContext ExtractAstContext(Ast inputAst, Token[] input
searchNestedScriptBlocks: true).ToList();

// If the last ast is an unnamed block that starts with "param" the cursor is inside a param block.
// To avoid adding special handling to all the completers that look at the last ast, we remove it here because it's not useful for completion.
// To avoid adding special handling to all the completers that look at the last ast, we remove it here because it's not useful for completion.
if (relatedAsts[^1].Extent.Text.StartsWith("param", StringComparison.OrdinalIgnoreCase)
&& relatedAsts[^1] is NamedBlockAst namedBlock && namedBlock.Unnamed)
{
Expand Down Expand Up @@ -905,7 +905,7 @@ internal List<CompletionResult> GetResultHelper(CompletionContext completionCont
{
switch (completionContext.TokenBeforeCursor.Kind)
{

case TokenKind.Dot:
case TokenKind.ColonColon:
case TokenKind.QuestionDot:
Expand Down Expand Up @@ -940,7 +940,7 @@ internal List<CompletionResult> GetResultHelper(CompletionContext completionCont
result = CompletionCompleters.CompleteComparisonOperatorValues(completionContext, binaryExpression.Left);
}
break;

case TokenKind.LBracket:
if (lastAst.Parent is IndexExpressionAst indexExpression)
{
Expand All @@ -949,7 +949,7 @@ internal List<CompletionResult> GetResultHelper(CompletionContext completionCont
result = CompletionCompleters.CompleteIndexExpression(completionContext, indexExpression.Target);
}
break;

default:
break;
}
Expand Down Expand Up @@ -1102,7 +1102,7 @@ internal List<CompletionResult> GetResultHelper(CompletionContext completionCont
typeNameToComplete = FindTypeNameToComplete(typeConstraintAst.TypeName, _cursorPosition);
}
}

if (typeNameToComplete is null && tokenAtCursor?.TokenFlags.HasFlag(TokenFlags.TypeName) == true)
{
typeNameToComplete = new TypeName(tokenAtCursor.Extent, tokenAtCursor.Text);
Expand Down Expand Up @@ -1263,7 +1263,7 @@ private static string GetFirstLineSubString(string stringToComplete, out bool ha
hasNewLine = false;
if (!string.IsNullOrEmpty(stringToComplete))
{
var index = stringToComplete.IndexOfAny(Utils.Separators.CrLf);
var index = stringToComplete.AsSpan().IndexOfAny('\r', '\n');
if (index >= 0)
{
stringToComplete = stringToComplete.Substring(0, index);
Expand Down Expand Up @@ -2042,7 +2042,7 @@ private static List<CompletionResult> GetResultForIdentifier(CompletionContext c
{
if (cursorAst.Extent.EndOffset == tokenAtCursor.Extent.StartOffset)
{
if (tokenAtCursorText.IndexOfAny(Utils.Separators.Directory) == 0)
if (tokenAtCursorText.AsSpan().IndexOfAny('\\', '/') == 0)
{
string wordToComplete =
CompletionCompleters.ConcatenateStringPathArguments(cursorAst as CommandElementAst, tokenAtCursorText, completionContext);
Expand Down Expand Up @@ -2292,7 +2292,7 @@ private static List<CompletionResult> GetResultForIdentifier(CompletionContext c
completionContext.WordToComplete = wordToComplete;
}
}
else if (tokenAtCursorText.IndexOfAny(Utils.Separators.Directory) == 0)
else if (tokenAtCursorText.AsSpan().IndexOfAny('\\', '/') == 0)
{
var command = lastAst.Parent as CommandBaseAst;
if (command != null && command.Redirections.Count > 0)
Expand Down Expand Up @@ -2384,7 +2384,7 @@ private static List<CompletionResult> GetResultForAttributeArgument(CompletionCo
// Ignore getter-only properties and properties that have already been set.
if (!property.CanWrite || existingArguments.Contains(property.Name))
{
continue;
continue;
}

if (property.Name.StartsWith(argName, StringComparison.OrdinalIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ internal static List<CompletionResult> CompleteCommandArgument(CompletionContext
partialPathAst.StringConstantType == StringConstantType.BareWord &&
secondToLastAst.Extent.EndLineNumber == partialPathAst.Extent.StartLineNumber &&
secondToLastAst.Extent.EndColumnNumber == partialPathAst.Extent.StartColumnNumber &&
partialPathAst.Value.IndexOfAny(Utils.Separators.Directory) == 0)
partialPathAst.Value.AsSpan().IndexOfAny('\\', '/') == 0)
{
var secondToLastStringConstantAst = secondToLastAst as StringConstantExpressionAst;
var secondToLastExpandableStringAst = secondToLastAst as ExpandableStringExpressionAst;
Expand Down Expand Up @@ -1270,7 +1270,7 @@ internal static List<CompletionResult> CompleteCommandArgument(CompletionContext
// Treat it as the file name completion
// Handle this scenario: & 'c:\a b'\<tab>
string fileName = pathAst.Value;
if (commandAst.InvocationOperator != TokenKind.Unknown && fileName.IndexOfAny(Utils.Separators.Directory) == 0 &&
if (commandAst.InvocationOperator != TokenKind.Unknown && fileName.AsSpan().IndexOfAny('\\', '/') == 0 &&
commandAst.CommandElements.Count == 2 && commandAst.CommandElements[0] is StringConstantExpressionAst &&
commandAst.CommandElements[0].Extent.EndLineNumber == expressionAst.Extent.StartLineNumber &&
commandAst.CommandElements[0].Extent.EndColumnNumber == expressionAst.Extent.StartColumnNumber)
Expand Down Expand Up @@ -2924,7 +2924,7 @@ private static void NativeCompletionCimNamespace(
string prefixOfChildNamespace = string.Empty;
if (!string.IsNullOrEmpty(context.WordToComplete))
{
int lastSlashOrBackslash = context.WordToComplete.LastIndexOfAny(Utils.Separators.Directory);
int lastSlashOrBackslash = context.WordToComplete.AsSpan().LastIndexOfAny('\\', '/');
if (lastSlashOrBackslash != (-1))
{
containerNamespace = context.WordToComplete.Substring(0, lastSlashOrBackslash);
Expand Down Expand Up @@ -4395,7 +4395,7 @@ internal static IEnumerable<CompletionResult> CompleteFilename(CompletionContext
// specified a drive or portion of the path.
var executionContext = context.ExecutionContext;
var defaultRelative = string.IsNullOrWhiteSpace(wordToComplete)
|| (wordToComplete.IndexOfAny(Utils.Separators.Directory) != 0 &&
|| (wordToComplete.AsSpan().IndexOfAny('\\', '/') != 0 &&
!Regex.Match(wordToComplete, @"^~[\\/]+.*").Success &&
!executionContext.LocationGlobber.IsAbsolutePath(wordToComplete, out _));
var relativePaths = context.GetOption("RelativePaths", @default: defaultRelative);
Expand Down Expand Up @@ -6137,7 +6137,7 @@ internal static void CompleteMemberByInferredType(
string memberName,
Func<object, bool> filter,
bool isStatic,
HashSet<string> excludedMembers = null,
HashSet<string> excludedMembers = null,
bool addMethodParenthesis = true)
{
bool extensionMethodsAdded = false;
Expand Down
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/CommandDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ private static CommandInfo TryModuleAutoDiscovery(string commandName,
// If commandName had a slash, it was module-qualified or path-qualified.
// In that case, we should not return anything (module-qualified is handled
// by the previous call to TryModuleAutoLoading().
int colonOrBackslash = commandName.IndexOfAny(Utils.Separators.ColonOrBackslash);
int colonOrBackslash = commandName.AsSpan().IndexOfAny('\\', ':');
if (colonOrBackslash != -1)
return null;

Expand Down Expand Up @@ -1139,7 +1139,7 @@ private static CommandInfo TryModuleAutoLoading(string commandName, ExecutionCon
CommandInfo result = null;

// If commandName was module-qualified. In that case, we should load the module.
var colonOrBackslash = commandName.IndexOfAny(Utils.Separators.ColonOrBackslash);
var colonOrBackslash = commandName.AsSpan().IndexOfAny('\\', ':');

// If we don't see '\', there is no module specified, so no module to load.
// If we see ':' before '\', then we probably have a drive qualified path, not a module name
Expand All @@ -1150,7 +1150,7 @@ private static CommandInfo TryModuleAutoLoading(string commandName, ExecutionCon
string moduleName;

// Now we check if there exists the second '\'
var secondBackslash = moduleCommandName.IndexOfAny(Utils.Separators.Backslash);
var secondBackslash = moduleCommandName.IndexOf('\\');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var secondBackslash = moduleCommandName.IndexOf('\\');
int secondBackslash = moduleCommandName.IndexOf('\\');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR already touches this line so we can fix code style too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an enormous number of var. It is better to fix in another PR if we would want.

if (secondBackslash == -1)
{
moduleName = commandName.Substring(0, colonOrBackslash);
Expand Down Expand Up @@ -1306,7 +1306,7 @@ internal LookupPathCollection GetLookupDirectoryPaths()

if (_pathCacheKey != null)
{
string[] tokenizedPath = _pathCacheKey.Split(Utils.Separators.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
string[] tokenizedPath = _pathCacheKey.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
_cachedPath = new Collection<string>();

foreach (string directory in tokenizedPath)
Expand Down Expand Up @@ -1398,7 +1398,7 @@ private static void InitPathExtCache(string pathExt)
lock (s_lockObject)
{
s_cachedPathExtCollection = pathExt != null
? pathExt.ToLower().Split(Utils.Separators.PathSeparator, StringSplitOptions.RemoveEmptyEntries)
? pathExt.ToLower().Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries)
: Array.Empty<string>();
s_cachedPathExtCollectionWithPs1 = new string[s_cachedPathExtCollection.Length + 1];
s_cachedPathExtCollectionWithPs1[0] = StringLiterals.PowerShellScriptFileExtension;
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/CommandSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ private static CanDoPathLookupResult CanDoPathLookup(string possiblePath)

// If the command contains any path separators, we can't
// do the path lookup
if (possiblePath.IndexOfAny(Utils.Separators.Directory) != -1)
if (possiblePath.AsSpan().IndexOfAny('\\', '/') != -1)
{
result = CanDoPathLookupResult.DirectorySeparator;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,7 @@ protected static object BaseConvertFrom(object sourceValue, Type destinationType
}
else
{
sourceValueEntries = sourceValueString.Split(Utils.Separators.Comma);
sourceValueEntries = sourceValueString.Split(',');
fromValuePatterns = new WildcardPattern[sourceValueEntries.Length];
for (int i = 0; i < sourceValueEntries.Length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ internal bool LoadUsingModulePath(
module = LoadUsingMultiVersionModuleBase(qualifiedPath, manifestProcessingFlags, options, out found);
if (!found)
{
if (name.IndexOfAny(Utils.Separators.Directory) == -1)
if (name.AsSpan().IndexOfAny('\\', '/') == -1)
{
qualifiedPath = Path.Combine(qualifiedPath, fileBaseName);
}
Expand Down Expand Up @@ -1014,7 +1014,7 @@ private IEnumerable<PSModuleInfo> GetModuleForRootedPaths(List<string> modulePat
{
bool containsWildCards = false;

string modulePath = mp.TrimEnd(Utils.Separators.Backslash);
string modulePath = mp.TrimEnd('\\');

// If the given path contains wildcards, we won't throw error if no match module path is found.
if (WildcardPattern.ContainsWildcardCharacters(modulePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ private static int PathContainsSubstring(string pathToScan, string pathToLookFor
Diagnostics.Assert(pathToLookFor != null, "pathToLookFor should not be null according to contract of the function");

int pos = 0; // position of the current substring in pathToScan
string[] substrings = pathToScan.Split(Utils.Separators.PathSeparator, StringSplitOptions.None); // we want to process empty entries
string[] substrings = pathToScan.Split(Path.PathSeparator, StringSplitOptions.None); // we want to process empty entries
string goodPathToLookFor = pathToLookFor.Trim().TrimEnd(Path.DirectorySeparatorChar); // trailing backslashes and white-spaces will mess up equality comparison
foreach (string substring in substrings)
{
Expand Down Expand Up @@ -1131,7 +1131,7 @@ private static string AddToPath(string basePath, string pathToAdd, int insertPos

if (!string.IsNullOrEmpty(pathToAdd)) // we don't want to append empty paths
{
foreach (string subPathToAdd in pathToAdd.Split(Utils.Separators.PathSeparator, StringSplitOptions.RemoveEmptyEntries)) // in case pathToAdd is a 'combined path' (semicolon-separated)
foreach (string subPathToAdd in pathToAdd.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries)) // in case pathToAdd is a 'combined path' (semicolon-separated)
{
int position = PathContainsSubstring(result.ToString(), subPathToAdd); // searching in effective 'result' value ensures that possible duplicates in pathsToAdd are handled correctly
if (position == -1) // subPathToAdd not found - add it
Expand Down Expand Up @@ -1351,7 +1351,7 @@ internal static IEnumerable<string> GetModulePath(bool includeSystemModulePath,

if (!string.IsNullOrWhiteSpace(modulePathString))
{
foreach (string envPath in modulePathString.Split(Utils.Separators.PathSeparator, StringSplitOptions.RemoveEmptyEntries))
foreach (string envPath in modulePathString.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries))
{
var processedPath = ProcessOneModulePath(context, envPath, processedPathSet);
if (processedPath != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private PSSnapinQualifiedName(string[] splitName)
{
if (name == null)
return null;
string[] splitName = name.Split(Utils.Separators.Backslash);
string[] splitName = name.Split('\\');
if (splitName.Length == 0 || splitName.Length > 2)
return null;
var result = new PSSnapinQualifiedName(splitName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ private bool IsExecutable(string path)
}
else
{
extensionList = pathext.Split(Utils.Separators.Semicolon);
extensionList = pathext.Split(';');
}

foreach (string extension in extensionList)
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ public override string ToString()
{
StringBuilder result = new StringBuilder();

result.Append(Major).Append(Utils.Separators.Dot).Append(Minor).Append(Utils.Separators.Dot).Append(Patch);
result.Append(Major).Append('.').Append(Minor).Append('.').Append(Patch);

if (!string.IsNullOrEmpty(PreReleaseLabel))
{
Expand Down
Loading