From 45a452e230e61e05289b33c17099adcd8790f514 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Wed, 22 Jul 2015 16:45:33 +0200 Subject: Thinking about refactoring the way the count is done --- src/eu/equalparts/cardbase/cli/CardbaseCLI.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/eu/equalparts/cardbase/cli') 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(); -- cgit v1.2.3