提交 2d0b585f 编写于 作者: C Cyrus Najmabadi

Remove duplication.

上级 49fdeb4d
......@@ -27,22 +27,35 @@ public static RegexTrivia CreateTrivia(RegexKind kind, ImmutableArray<VirtualCha
public static RegexTrivia CreateTrivia(RegexKind kind, ImmutableArray<VirtualChar> virtualChars, ImmutableArray<EmbeddedDiagnostic> diagnostics)
=> new RegexTrivia(kind, virtualChars, diagnostics);
/// <summary>
/// Maps an escaped character to the actual character it was escaping. For something like
/// 'a' this will map to actual '\a' char (the bell character). However, for something like
/// '(' this will just map to '(' as that's all that \( does in a regex.
///
public static char MapEscapeChar(char ch)
{
switch (ch)
{
default:
return ch;
case 'a': return '\u0007'; // bell
case 'b': return '\b'; // backspace
case 'e': return '\u001B'; // escape
case 'f': return '\f'; // form feed
case 'n': return '\n'; // new line
case 'r': return '\r'; // carriage return
case 't': return '\t'; // tab
case 'v': return '\u000B'; // vertical tab
}
}
public static bool IsSelfEscape(this RegexSimpleEscapeNode node)
{
if (node.TypeToken.VirtualChars.Length > 0)
{
switch (node.TypeToken.VirtualChars[0].Char)
{
case 'a':
case 'b':
case 'e':
case 'f':
case 'n':
case 'r':
case 't':
case 'v':
return false;
}
var ch = node.TypeToken.VirtualChars[0].Char;
return MapEscapeChar(ch) == ch;
}
return true;
......
......@@ -1289,18 +1289,8 @@ private bool TryGetRangeComponentValueWorker(RegexNode component, out char ch)
switch (component.Kind)
{
case RegexKind.SimpleEscape:
ch = ((RegexSimpleEscapeNode)component).TypeToken.VirtualChars[0];
switch (ch)
{
case 'a': ch = '\u0007'; break; // bell
case 'b': ch = '\b'; break; // backspace
case 'e': ch = '\u001B'; break; // escape
case 'f': ch = '\f'; break; // form feed
case 'n': ch = '\n'; break; // new line
case 'r': ch = '\r'; break; // carriage return
case 't': ch = '\t'; break; // tab
case 'v': ch = '\u000B'; break; // vertical tab
}
var escapeNode = (RegexSimpleEscapeNode)component;
ch = MapEscapeChar(escapeNode.TypeToken.VirtualChars[0]);
return true;
case RegexKind.ControlEscape:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册