Main { static String[] readArguments( Scanner scanner) { List<String> arguments = new ArrayList<String>(); StringBuilder current_argument = new StringBuilder(); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.isEmpty() || line.startsWith("#")) { continue; } String[] parts = line.split("\\s+"); boolean quotes = false; for (String part : parts) { part = part.trim(); if (part.startsWith(("\""))) { quotes = true; part = part.substring(1); } current_argument.append(part).append(" "); if (part.endsWith("\"")) { quotes = false; } if (!quotes) { String arg = current_argument.toString().trim(); if (arg.endsWith("\"")) { arg = arg.substring(0, arg.length() - 1); } arguments.add(arg); current_argument = new StringBuilder(); } } } scanner.close(); String[] out = new String[arguments.size()]; for (int i = 0; i < arguments.size(); i++) { out[i] = arguments.get(i); } return out; }  @SuppressWarnings({"squid:S106"}) static void main(String[] args); static int mainLoop(String[] args, InputStream in, PrintStream out, PrintStream err); static int mainLoop(String[] args, InputStream in, PrintStream out, PrintStream err, Class<?> base_class); static Map<String,RegexRule> readRules(/*@ non_null @*/ String filename); static final String REGEX_FILENAME; static final String REGEX_FILENAME_DETEX; static final String VERSION_STRING; }
@Test public void testReadArguments1() { String arg_string = "--foo --bar"; Scanner scanner = new Scanner(arg_string); String[] args = Main.readArguments(scanner); assertEquals(2, args.length); assertEquals("--foo", args[0]); assertEquals("--bar", args[1]); }
@Test public void testReadArguments2() { String arg_string = "--foo\n--bar"; Scanner scanner = new Scanner(arg_string); String[] args = Main.readArguments(scanner); assertEquals(2, args.length); assertEquals("--foo", args[0]); assertEquals("--bar", args[1]); }
@Test public void testReadArguments3() { String arg_string = "--foo \"Some\" --bar"; Scanner scanner = new Scanner(arg_string); String[] args = Main.readArguments(scanner); assertEquals(3, args.length); assertEquals("--foo", args[0]); assertEquals("Some", args[1]); assertEquals("--bar", args[2]); }
@Test public void testReadArguments4() { String arg_string = "--foo \"Some Thing\" --bar"; Scanner scanner = new Scanner(arg_string); String[] args = Main.readArguments(scanner); assertEquals(3, args.length); assertEquals("--foo", args[0]); assertEquals("Some Thing", args[1]); assertEquals("--bar", args[2]); }
@Test public void testReadArguments5() { String arg_string = "#--foo\n\n--bar"; Scanner scanner = new Scanner(arg_string); String[] args = Main.readArguments(scanner); assertEquals(1, args.length); assertEquals("--bar", args[0]); }
@Test public void testReadArguments6() { String arg_string = "--foo\n\"Some\n#\nThing\""; Scanner scanner = new Scanner(arg_string); String[] args = Main.readArguments(scanner); assertEquals(2, args.length); assertEquals("--foo", args[0]); assertEquals("Some Thing", args[1]); }