public static bool ParseCommand(string input, CommandMap map, out IEnumerable <Command> commands, out int endPos) { int startPosition = 0; int endPosition = 0; int inputLength = input.Length; bool isEscaped = false; commands = null; endPos = 0; if (input == "") { return(false); } while (endPosition < inputLength) { char currentChar = input[endPosition++]; if (isEscaped) { isEscaped = false; } else if (currentChar == '\\') { isEscaped = true; } bool isWhitespace = IsWhiteSpace(currentChar); if ((!isEscaped && isWhitespace) || endPosition >= inputLength) { int length = (isWhitespace ? endPosition - 1 : endPosition) - startPosition; string temp = input.Substring(startPosition, length); if (temp == "") { startPosition = endPosition; } else { var newMap = map.GetItem(temp); if (newMap != null) { map = newMap; endPos = endPosition; } else { break; } startPosition = endPosition; } } } commands = map.GetCommands(); //Work our way backwards to find a command that matches our input return(commands != null); }
public IEnumerable <Command> GetCommands() { if (_commands.Count > 0) { return(_commands); } else if (_parent != null) { return(_parent.GetCommands()); } else { return(null); } }
public static bool ParseCommand(string input, CommandMap map, out IEnumerable<Command> commands, out int endPos) { int startPosition = 0; int endPosition = 0; int inputLength = input.Length; bool isEscaped = false; commands = null; endPos = 0; if (input == "") return false; while (endPosition < inputLength) { char currentChar = input[endPosition++]; if (isEscaped) isEscaped = false; else if (currentChar == '\\') isEscaped = true; bool isWhitespace = IsWhiteSpace(currentChar); if ((!isEscaped && isWhitespace) || endPosition >= inputLength) { int length = (isWhitespace ? endPosition - 1 : endPosition) - startPosition; string temp = input.Substring(startPosition, length); if (temp == "") startPosition = endPosition; else { var newMap = map.GetItem(temp); if (newMap != null) { map = newMap; endPos = endPosition; } else break; startPosition = endPosition; } } } commands = map.GetCommands(); //Work our way backwards to find a command that matches our input return commands != null; }