From ca47896204482bf4a6979e3838bf7f09f61cebeb Mon Sep 17 00:00:00 2001 From: giy <giy@omp-system.ru> Date: Fri, 02 Sep 2022 14:16:56 +0300 Subject: [PATCH] Обновление до версии 2.9.0 --- QtVsTools.Core/CommandLineParser.cs | 35 ++++++++++++++--------------------- 1 files changed, 14 insertions(+), 21 deletions(-) diff --git a/QtVsTools.Core/CommandLineParser.cs b/QtVsTools.Core/CommandLineParser.cs index 7380cc8..995d064 100644 --- a/QtVsTools.Core/CommandLineParser.cs +++ b/QtVsTools.Core/CommandLineParser.cs @@ -29,10 +29,10 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using System.IO; namespace QtVsTools.Core.CommandLine { @@ -40,13 +40,12 @@ public class Parser { - - List<Option> commandLineOptionList = new List<Option>(); - Dictionary<string, int> nameHash = new Dictionary<string, int>(); - Dictionary<int, List<string>> optionValuesHash = new Dictionary<int, List<string>>(); - List<string> optionNames = new List<string>(); - List<string> positionalArgumentList = new List<string>(); - List<string> unknownOptionNames = new List<string>(); + readonly List<Option> commandLineOptionList = new List<Option>(); + readonly Dictionary<string, int> nameHash = new Dictionary<string, int>(); + readonly Dictionary<int, List<string>> optionValuesHash = new Dictionary<int, List<string>>(); + readonly List<string> optionNames = new List<string>(); + readonly List<string> positionalArgumentList = new List<string>(); + readonly List<string> unknownOptionNames = new List<string>(); bool needsParsing = true; public enum SingleDashWordOptionMode @@ -118,8 +117,7 @@ IEnumerable<string> Aliases(string optionName) { - int optionIndex; - if (!nameHash.TryGetValue(optionName, out optionIndex)) { + if (!nameHash.TryGetValue(optionName, out int optionIndex)) { return new List<string>(); } return commandLineOptionList[optionIndex].Names; @@ -204,8 +202,7 @@ IEnumerator<string> argumentEnumerator, ref bool atEnd) { const char assignChar = '='; - int optionOffset; - if (nameHash.TryGetValue(optionName, out optionOffset)) { + if (nameHash.TryGetValue(optionName, out int optionOffset)) { int assignPos = argument.IndexOf(assignChar); bool withValue = !string.IsNullOrEmpty( commandLineOptionList[optionOffset].ValueName); @@ -267,7 +264,7 @@ var optFilePath = macros.ExpandString(argData.Substring(1)); string[] additionalArgs = File.ReadAllLines( Path.Combine(workingDir, optFilePath)); - if (additionalArgs != null) { + if (additionalArgs.Length != 0) { var additionalArgsString = string.Join(" ", additionalArgs .Select(x => "\"" + x.Replace("\"", "\\\"") + "\"")); arguments.AddRange(TokenizeArgs(additionalArgsString, macros)); @@ -356,10 +353,9 @@ if (!RegisterFoundOption(optionName)) { error = true; } else { - int optionOffset; Trace.Assert(nameHash.TryGetValue( optionName, - out optionOffset)); + out int optionOffset)); bool withValue = !string.IsNullOrEmpty( commandLineOptionList[optionOffset].ValueName); if (withValue) { @@ -397,10 +393,9 @@ if (argument.Length > 2) { string possibleShortOptionStyleName = argument.Substring(1, 1); - int shortOptionIdx; if (nameHash.TryGetValue( possibleShortOptionStyleName, - out shortOptionIdx)) { + out int shortOptionIdx)) { var arg = commandLineOptionList[shortOptionIdx]; if ((arg.Flags & Option.Flag.ShortOptionStyle) != 0) { RegisterFoundOption(possibleShortOptionStyleName); @@ -466,8 +461,7 @@ public IEnumerable<string> Values(string optionName) { CheckParsed("Values"); - int optionOffset; - if (nameHash.TryGetValue(optionName, out optionOffset)) { + if (nameHash.TryGetValue(optionName, out int optionOffset)) { var values = optionValuesHash[optionOffset]; return values; } @@ -525,7 +519,6 @@ public IEnumerable<string> Names { get; - private set; } public string ValueName @@ -558,7 +551,7 @@ static class Lexer { - static Regex lexer = new Regex( + static readonly Regex lexer = new Regex( /* Newline */ @"(\n)" + /* Unquoted */ @"|((?:(?:[^\s\""])|(?:(?<=\\)\""))+)" + /* Quoted */ @"|(?:\""((?:(?:[^\""])|(?:(?<=\\)\""))+)\"")" + -- Gitblit v1.9.1