public CommandInfo Parse(string text) { int indexOfLeftParenthesis = text.IndexOf('('); if (indexOfLeftParenthesis == -1) { throw new ArgumentException("Invalid user command"); } if (!text.EndsWith(")")) { throw new ArgumentException("Invalid user command"); } string commandString = text.Substring(0, indexOfLeftParenthesis); string argumentsAsString = text.Substring(indexOfLeftParenthesis + 1, text.Length - indexOfLeftParenthesis - 2); string[] arguments = argumentsAsString.Split(','); for (int j = 0; j < arguments.Length; j++) { arguments[j] = arguments[j].Trim(); } CommandInfo info = new CommandInfo(); info.CommandString = commandString; info.Arguments = arguments.ToList<string>(); return info; }
public CommandInfo Parse(string text) { // TODO: Extract command parsing -> Interpreter or just new Class int indexOfTheParentesis = text.IndexOf('('); if (indexOfTheParentesis == -1) { throw new ArgumentException("Invalid command format"); } string commandName = text.Substring(0, indexOfTheParentesis); if (!text.EndsWith(")")) { throw new ArgumentException("Invalid command format"); } string listOfArgumentsAsString = text.Substring(indexOfTheParentesis + 1, text.Length - indexOfTheParentesis - 2); var arguments = listOfArgumentsAsString.Split(','); for (int j = 0; j < arguments.Length; j++) { arguments[j] = arguments[j].Trim(); } var commandInfo = new CommandInfo(); commandInfo.Arguments = arguments; commandInfo.CommandName = commandName; return commandInfo; }