diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-07-22 16:45:33 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-07-22 16:45:33 +0200 |
commit | 45a452e230e61e05289b33c17099adcd8790f514 (patch) | |
tree | 0bfa70a575a57ef36149d1f8fe96a51c330d60b4 /src | |
parent | 2de3bf57cd21d5cf60723fca59f61d3bc69578dd (diff) |
Thinking about refactoring the way the count is done
Diffstat (limited to 'src')
-rw-r--r-- | src/eu/equalparts/cardbase/cli/CardbaseCLI.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java index e1b912d..d6e1cdd 100644 --- a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java +++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java @@ -134,6 +134,16 @@ public class CardbaseCLI { } } + + /** + * Properly sanitise user input. + * + * @param input the raw input from the user. + * @return an array of strings, where the first element is the command and subsequent elements are the arguments. + */ + public String[] sanitiseInput(String input) { + return input.trim().split("[ \t]+"); + } /** * Read stdin for user input, sanitise and interpret any commands entered. @@ -146,9 +156,9 @@ public class CardbaseCLI { // print prompt System.out.print(selectedSet == null ? "> " : selectedSet.code + " > "); // condition input and interpret - String[] raw = consoleReader.readLine().trim().split("[ \t]+"); - String command = raw[0]; - String[] args = Arrays.copyOfRange(raw, 1, raw.length); + String[] input = sanitiseInput(consoleReader.readLine()); + String command = input[0]; + String[] args = Arrays.copyOfRange(input, 1, input.length); if (command.equalsIgnoreCase("help")) { help(); |