@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]); }
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; }
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; } }
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; }  }
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); }
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; }