mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Move consts and methods to single CharExtensions class (#9992)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<MergedCompiledCommandParameter>();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -21,73 +21,6 @@ using Dbg = System.Management.Automation.Diagnostics;
|
||||
|
||||
namespace System.Management.Automation
|
||||
{
|
||||
#region SpecialCharacters
|
||||
/// <summary>
|
||||
/// Define the various unicode special characters that
|
||||
/// the parser has to deal with.
|
||||
/// </summary>
|
||||
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 == '}');
|
||||
}
|
||||
/// <summary>
|
||||
/// Canonicalize the quote character - map all of the aliases for " or '
|
||||
/// into their ascii equivalent.
|
||||
/// </summary>
|
||||
/// <param name="c">The character to map.</param>
|
||||
/// <returns>The mapped character.</returns>
|
||||
public static char AsQuote(char c)
|
||||
{
|
||||
if (IsSingleQuote(c)) return '\'';
|
||||
if (IsDoubleQuote(c)) return '"';
|
||||
return (c);
|
||||
}
|
||||
};
|
||||
|
||||
#endregion SpecialChars
|
||||
|
||||
#region Flow Control Exceptions
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user