Use switch statement for operator tokenization.

This commit is contained in:
atlimit8
2017-02-11 23:42:22 -06:00
parent 73895d07e2
commit c70442b15e

View File

@@ -166,10 +166,11 @@ namespace OpenRA.Support
static Token ParseSymbol(string expression, ref int i) static Token ParseSymbol(string expression, ref int i)
{ {
var start = i; var start = i;
var c = expression[start];
// Parse operators // Parse operators
if (c == '!') switch (expression[start])
{
case '!':
{ {
if (i < expression.Length - 1 && expression[start + 1] == '=') if (i < expression.Length - 1 && expression[start + 1] == '=')
{ {
@@ -180,7 +181,7 @@ namespace OpenRA.Support
return new NotToken(start); return new NotToken(start);
} }
if (c == '=') case '=':
{ {
if (i < expression.Length - 1 && expression[start + 1] == '=') if (i < expression.Length - 1 && expression[start + 1] == '=')
{ {
@@ -191,7 +192,7 @@ namespace OpenRA.Support
throw new InvalidDataException("Unexpected character '=' at index {0}".F(start)); throw new InvalidDataException("Unexpected character '=' at index {0}".F(start));
} }
if (c == '&') case '&':
{ {
if (i < expression.Length - 1 && expression[start + 1] == '&') if (i < expression.Length - 1 && expression[start + 1] == '&')
{ {
@@ -202,7 +203,7 @@ namespace OpenRA.Support
throw new InvalidDataException("Unexpected character '&' at index {0}".F(start)); throw new InvalidDataException("Unexpected character '&' at index {0}".F(start));
} }
if (c == '|') case '|':
{ {
if (i < expression.Length - 1 && expression[start + 1] == '|') if (i < expression.Length - 1 && expression[start + 1] == '|')
{ {
@@ -212,6 +213,9 @@ namespace OpenRA.Support
throw new InvalidDataException("Unexpected character '|' at index {0}".F(start)); throw new InvalidDataException("Unexpected character '|' at index {0}".F(start));
} }
}
var c = expression[start];
// Scan forwards until we find an non-digit character // Scan forwards until we find an non-digit character
if (c == '-' || char.IsDigit(expression[i])) if (c == '-' || char.IsDigit(expression[i]))