コード例 #1
0
        private static ConsoleCommandParseFailure?InitialValidation(string commandRepr, out string trimmed)
        {
            if (string.IsNullOrWhiteSpace(commandRepr))
            {
                trimmed = "";
                return(ConsoleCommandParseFailure.Fail("Input is empty."));
            }

            trimmed = commandRepr.Trim();
            return(trimmed.Length == 0 ? ConsoleCommandParseFailure.Fail("Input is whitespace.") : null);
        }
コード例 #2
0
        private static IConsoleCommandParseResult?ParameterListValidation(string commandRepr, out int parametersStart)
        {
            parametersStart = commandRepr.IndexOf("(", StringComparison.Ordinal);
            if (parametersStart < 0)
            {
                return(new ConsoleCommandParseSuccess(commandRepr));
            }

            if (parametersStart == 0)
            {
                return(ConsoleCommandParseFailure.Fail("No command name is present."));
            }

            return(!commandRepr.EndsWith(")")
                ? ConsoleCommandParseFailure.Fail("Command with params should end with ')'.")
                : null);
        }