Browse Source

Fix up some whitespace checks

tags/docs-0.9
RogueException 9 years ago
parent
commit
7f06b9d04b
1 changed files with 17 additions and 12 deletions
  1. +17
    -12
      src/Discord.Net.Commands/CommandParser.cs

+ 17
- 12
src/Discord.Net.Commands/CommandParser.cs View File

@@ -32,9 +32,10 @@ namespace Discord.Commands
else if (currentChar == '\\') else if (currentChar == '\\')
isEscaped = true; isEscaped = true;


if ((!isEscaped && IsWhiteSpace(currentChar)) || endPosition >= inputLength)
bool isWhitespace = IsWhiteSpace(currentChar);
if ((!isEscaped && isWhitespace) || endPosition >= inputLength)
{ {
int length = (currentChar == ' ' ? endPosition - 1 : endPosition) - startPosition;
int length = (isWhitespace ? endPosition - 1 : endPosition) - startPosition;
string temp = input.Substring(startPosition, length); string temp = input.Substring(startPosition, length);
if (temp == "") if (temp == "")
startPosition = endPosition; startPosition = endPosition;
@@ -95,7 +96,7 @@ namespace Discord.Commands
else if (currentChar == '\\') else if (currentChar == '\\')
isEscaped = true; isEscaped = true;


if (endPosition == startPosition + 1 && IsWhiteSpace(currentChar)) //Has no text yet, and is another whitespace
if (endPosition == startPosition + 1 && isWhitespace) //Has no text yet, and is another whitespace
{ {
startPosition = endPosition; startPosition = endPosition;
continue; continue;
@@ -114,17 +115,21 @@ namespace Discord.Commands
currentPart = ParserPart.QuotedParameter; currentPart = ParserPart.QuotedParameter;
startPosition = endPosition; startPosition = endPosition;
} }
else if ((!isEscaped && IsWhiteSpace(currentChar)) || endPosition >= inputLength)
else
{ {
int length = (currentChar == ' ' ? endPosition - 1 : endPosition) - startPosition;
string temp = input.Substring(startPosition, length);
if (temp == "")
startPosition = endPosition;
else
bool isWhitespace = IsWhiteSpace(currentChar);
if ((!isEscaped && isWhitespace) || endPosition >= inputLength)
{ {
currentPart = ParserPart.None;
argList.Add(temp);
startPosition = endPosition;
int length = (isWhitespace ? endPosition - 1 : endPosition) - startPosition;
string temp = input.Substring(startPosition, length);
if (temp == "")
startPosition = endPosition;
else
{
currentPart = ParserPart.None;
argList.Add(temp);
startPosition = endPosition;
}
} }
} }
break; break;


Loading…
Cancel
Save