diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index f5d9a1112c..4e7733bef2 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -11,10 +11,10 @@ using System.Management.Automation; using System.Management.Automation.Configuration; using System.Management.Automation.Host; using System.Management.Automation.Internal; +using System.Management.Automation.Language; using System.Management.Automation.Runspaces; using System.Security; using System.Text; -using System.Text.RegularExpressions; using Dbg = System.Management.Automation.Diagnostics; @@ -573,7 +573,7 @@ namespace Microsoft.PowerShell return (SwitchKey: null, ShouldBreak: false); } - if (!SpecialCharacters.IsDash(switchKey[0]) && switchKey[0] != '/') + if (!CharExtensions.IsDash(switchKey[0]) && switchKey[0] != '/') { // then its a file if (parser != null) @@ -590,7 +590,7 @@ namespace Microsoft.PowerShell switchKey = switchKey.Substring(1); // chop off the second dash so we're agnostic wrt specifying - or -- - if (!string.IsNullOrEmpty(switchKey) && SpecialCharacters.IsDash(switchKey[0])) + if (!string.IsNullOrEmpty(switchKey) && CharExtensions.IsDash(switchKey[0])) { switchKey = switchKey.Substring(1); } @@ -889,7 +889,7 @@ namespace Microsoft.PowerShell { string arg = args[i]; - if (!string.IsNullOrEmpty(arg) && SpecialCharacters.IsDash(arg[0])) + if (!string.IsNullOrEmpty(arg) && CharExtensions.IsDash(arg[0])) { break; } @@ -1205,7 +1205,7 @@ namespace Microsoft.PowerShell _collectedArgs.Add(new CommandParameter(pendingParameter, arg)); pendingParameter = null; } - else if (!string.IsNullOrEmpty(arg) && SpecialCharacters.IsDash(arg[0]) && arg.Length > 1) + else if (!string.IsNullOrEmpty(arg) && CharExtensions.IsDash(arg[0]) && arg.Length > 1) { int offset = arg.IndexOf(':'); if (offset >= 0) diff --git a/src/System.Management.Automation/engine/CmdletInfo.cs b/src/System.Management.Automation/engine/CmdletInfo.cs index b392a8dae2..8cfec82613 100644 --- a/src/System.Management.Automation/engine/CmdletInfo.cs +++ b/src/System.Management.Automation/engine/CmdletInfo.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Reflection; +using System.Management.Automation.Language; using System.Text; namespace System.Management.Automation @@ -173,7 +173,7 @@ namespace System.Management.Automation int index = 0; for (int i = 0; i < name.Length; i++) { - if (SpecialCharacters.IsDash(name[i])) + if (CharExtensions.IsDash(name[i])) { index = i; break; diff --git a/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs b/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs index e74ddb42ff..a1c945e387 100644 --- a/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs +++ b/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; +using System.Management.Automation.Language; using System.Text; namespace System.Management.Automation @@ -449,7 +450,7 @@ namespace System.Management.Automation new Collection(); // Skip the leading '-' if present - if (name.Length > 0 && SpecialCharacters.IsDash(name[0])) + if (name.Length > 0 && CharExtensions.IsDash(name[0])) { name = name.Substring(1); } diff --git a/src/System.Management.Automation/engine/lang/codegen.cs b/src/System.Management.Automation/engine/lang/codegen.cs index 09d66ce644..d94adf00cc 100644 --- a/src/System.Management.Automation/engine/lang/codegen.cs +++ b/src/System.Management.Automation/engine/lang/codegen.cs @@ -29,7 +29,7 @@ namespace System.Management.Automation.Language foreach (char c in value) { sb.Append(c); - if (SpecialCharacters.IsSingleQuote(c)) + if (CharExtensions.IsSingleQuote(c)) { // double-up quotes to escape them sb.Append(c); @@ -76,7 +76,7 @@ namespace System.Management.Automation.Language foreach (char c in value) { sb.Append(c); - if (SpecialCharacters.IsCurlyBracket(c)) + if (CharExtensions.IsCurlyBracket(c)) { // double-up curly brackets to escape them sb.Append(c); diff --git a/src/System.Management.Automation/engine/lang/parserutils.cs b/src/System.Management.Automation/engine/lang/parserutils.cs index 2cf6f2b383..60d4711da3 100644 --- a/src/System.Management.Automation/engine/lang/parserutils.cs +++ b/src/System.Management.Automation/engine/lang/parserutils.cs @@ -21,73 +21,6 @@ using Dbg = System.Management.Automation.Diagnostics; namespace System.Management.Automation { - #region SpecialCharacters - /// - /// Define the various unicode special characters that - /// the parser has to deal with. - /// - internal static class SpecialCharacters - { - public const char enDash = (char)0x2013; - public const char emDash = (char)0x2014; - public const char horizontalBar = (char)0x2015; - - public const char quoteSingleLeft = (char)0x2018; // left single quotation mark - public const char quoteSingleRight = (char)0x2019; // right single quotation mark - public const char quoteSingleBase = (char)0x201a; // single low-9 quotation mark - public const char quoteReversed = (char)0x201b; // single high-reversed-9 quotation mark - public const char quoteDoubleLeft = (char)0x201c; // left double quotation mark - public const char quoteDoubleRight = (char)0x201d; // right double quotation mark - public const char quoteLowDoubleLeft = (char)0x201E;// low double left quote used in german. - - public static bool IsDash(char c) - { - return (c == enDash || c == emDash || c == horizontalBar || c == '-'); - } - - public static bool IsSingleQuote(char c) - { - return (c == quoteSingleLeft || c == quoteSingleRight || c == quoteSingleBase || - c == quoteReversed || c == '\''); - } - - public static bool IsDoubleQuote(char c) - { - return (c == '"' || c == quoteDoubleLeft || c == quoteDoubleRight || c == quoteLowDoubleLeft); - } - - public static bool IsQuote(char c) - { - return (IsSingleQuote(c) || IsDoubleQuote(c)); - } - - public static bool IsDelimiter(char c, char delimiter) - { - if (delimiter == '"') return IsDoubleQuote(c); - if (delimiter == '\'') return IsSingleQuote(c); - return (c == delimiter); - } - - public static bool IsCurlyBracket(char c) - { - return (c == '{' || c == '}'); - } - /// - /// Canonicalize the quote character - map all of the aliases for " or ' - /// into their ascii equivalent. - /// - /// The character to map. - /// The mapped character. - public static char AsQuote(char c) - { - if (IsSingleQuote(c)) return '\''; - if (IsDoubleQuote(c)) return '"'; - return (c); - } - }; - - #endregion SpecialChars - #region Flow Control Exceptions /// diff --git a/src/System.Management.Automation/engine/parser/CharTraits.cs b/src/System.Management.Automation/engine/parser/CharTraits.cs index 76a7ed542d..058ffac981 100644 --- a/src/System.Management.Automation/engine/parser/CharTraits.cs +++ b/src/System.Management.Automation/engine/parser/CharTraits.cs @@ -227,6 +227,11 @@ namespace System.Management.Automation.Language /* 0x7F */ CharTraits.None, }; + public static bool IsCurlyBracket(char c) + { + return (c == '{' || c == '}'); + } + // Return true if the character is a whitespace character. // Newlines are not whitespace. internal static bool IsWhitespace(this char c)