From c70442b15ed178485feb37a7e1e6fbc4cb54d847 Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Sat, 11 Feb 2017 23:42:22 -0600 Subject: [PATCH] Use switch statement for operator tokenization. --- OpenRA.Game/Support/ConditionExpression.cs | 66 ++++++++++++---------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/OpenRA.Game/Support/ConditionExpression.cs b/OpenRA.Game/Support/ConditionExpression.cs index 90cbc52a0b..2a95507f07 100644 --- a/OpenRA.Game/Support/ConditionExpression.cs +++ b/OpenRA.Game/Support/ConditionExpression.cs @@ -166,53 +166,57 @@ namespace OpenRA.Support static Token ParseSymbol(string expression, ref int i) { var start = i; - var c = expression[start]; // Parse operators - if (c == '!') + switch (expression[start]) { - if (i < expression.Length - 1 && expression[start + 1] == '=') + case '!': { - i++; - return new NotEqualsToken(start); + if (i < expression.Length - 1 && expression[start + 1] == '=') + { + i++; + return new NotEqualsToken(start); + } + + return new NotToken(start); } - return new NotToken(start); - } - - if (c == '=') - { - if (i < expression.Length - 1 && expression[start + 1] == '=') + case '=': { - i++; - return new EqualsToken(start); + if (i < expression.Length - 1 && expression[start + 1] == '=') + { + i++; + return new EqualsToken(start); + } + + throw new InvalidDataException("Unexpected character '=' at index {0}".F(start)); } - throw new InvalidDataException("Unexpected character '=' at index {0}".F(start)); - } - - if (c == '&') - { - if (i < expression.Length - 1 && expression[start + 1] == '&') + case '&': { - i++; - return new AndToken(start); + if (i < expression.Length - 1 && expression[start + 1] == '&') + { + i++; + return new AndToken(start); + } + + throw new InvalidDataException("Unexpected character '&' at index {0}".F(start)); } - throw new InvalidDataException("Unexpected character '&' at index {0}".F(start)); - } - - if (c == '|') - { - if (i < expression.Length - 1 && expression[start + 1] == '|') + case '|': { - i++; - return new OrToken(start); - } + if (i < expression.Length - 1 && expression[start + 1] == '|') + { + i++; + return new OrToken(start); + } - 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 if (c == '-' || char.IsDigit(expression[i])) {