Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public SearchResult Search(string input)
        {
            string searchInput = _caseSensitive ? input : input.ToLowerInvariant();
            var    matches     = _map.GetCommands(searchInput).OrderByDescending(x => x.Command.Priority).ToImmutableArray();

            if (matches.Length > 0)
            {
                return(SearchResult.FromSuccess(input, matches));
            }
            else
            {
                return(SearchResult.FromError(CommandError.UnknownCommand, "Unknown command."));
            }
        }
Exemplo n.º 3
0
        public SearchResult Search(IUserMessage message, string input)
        {
            string lowerInput = input.ToLowerInvariant();
            var    matches    = _map.GetCommands(input).OrderByDescending(x => x.Priority).ToImmutableArray();

            if (matches.Length > 0)
            {
                return(SearchResult.FromSuccess(input, matches));
            }
            else
            {
                return(SearchResult.FromError(CommandError.UnknownCommand, "Unknown command."));
            }
        }
Exemplo n.º 4
0
 public IEnumerable <Command> GetCommands()
 {
     if (_commands.Count > 0)
     {
         return(_commands);
     }
     else if (_parent != null)
     {
         return(_parent.GetCommands());
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 5
0
		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;
		}