package org.wanna.jabbot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wanna.jabbot.command.parser.CommandParser;
import org.wanna.jabbot.command.parser.CommandParsingResult;

/**
 * @author vmorsiani <vmorsiani>
 * @since 2014-05-31
 */
public class DefaultCommandParser implements CommandParser {
	private Logger log = LoggerFactory.getLogger(DefaultCommandParser.class);
	private String commandPrefix = "!";

	public DefaultCommandParser(String commandPrefix) {
		this.commandPrefix = commandPrefix;
	}

	public CommandParsingResult parse(String message) {
		String command;
		if (message.matches("(.*)\\s(.*)")) {
			command = message.substring(commandPrefix.length(), message.indexOf(" "));
		} else {
			command = message.substring(commandPrefix.length());
		}
		String argString = message.substring((commandPrefix + command).length());

		return new CommandParsingResult(command,argString);
	}
}

@@ -193,16 +193,81 @@
 esult;%0A%0A
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A
 /**%0A * @
@@ -666,41 +666,123 @@
 ;%0A%09%09
-if (message.matches(%22(.*)%5C%5Cs(.*)%22
+Pattern wsPattern = Pattern.compile(%22%5C%5Cs%22);%0A%09%09Matcher wsMatcher = wsPattern.matcher(message);%0A%09%09if (wsMatcher.find(
 )) %7B
@@ -841,27 +841,24 @@
 (), 
-message.indexOf(%22 %22
+wsMatcher.start(
 ));%0A

allow any whitespace to be a delimiter after the command (2)