CommandLineHelper { public static String[] parseArgs(String toProcess) throws Exception { if (toProcess == null || toProcess.length() == 0) { return new String[0]; } final int normal = 0; final int inQuote = 1; final int inDoubleQuote = 2; int state = normal; StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true); Vector<String> v = new Vector<>(); StringBuffer current = new StringBuffer(); boolean lastTokenHasBeenQuoted = false; while (tok.hasMoreTokens()) { String nextTok = tok.nextToken(); switch (state) { case inQuote: if ("\'".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; case inDoubleQuote: if ("\"".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; default: if ("\'".equals(nextTok)) { state = inQuote; } else if ("\"".equals(nextTok)) { state = inDoubleQuote; } else if (" ".equals(nextTok)) { if (lastTokenHasBeenQuoted || current.length() != 0) { v.addElement(current.toString()); current = new StringBuffer(); } } else { current.append(nextTok); } lastTokenHasBeenQuoted = false; break; } } if (lastTokenHasBeenQuoted || current.length() != 0) { v.addElement(current.toString()); } if (state == inQuote || state == inDoubleQuote) { throw new Exception("unbalanced quotes in " + toProcess); } String[] args = new String[v.size()]; v.copyInto(args); return args; }  static List<String> parseArgList(String toProcess); static String[] parseArgs(String toProcess); static List<String> getOptionValues(CommandLine line, String name); static String getIndexValue(CommandLine line, int index); static String getCommand(CommandLine line); static boolean hasFlagOrCommand(CommandLine line, String name); static List<String> cleanAxiomStrings(CommandLine line); static List<String> getBaseNamespaces(CommandLine line, IOHelper ioHelper); static boolean getBooleanValue(
      CommandLine line, String name, boolean defaultValue, boolean optionalArg); @Deprecated static Set<Class<? extends OWLAxiom>> getAxiomValues(CommandLine line); static boolean getBooleanValue(CommandLine line, String name, boolean defaultValue); static String getOptionalValue(CommandLine line, String name); static List<String> getOptionalValues(CommandLine line, String name); static String getDefaultValue(CommandLine line, String name, String defaultValue); static String getRequiredValue(CommandLine line, String name, String message); static IOHelper getIOHelper(CommandLine line); static OWLOntology getInputOntology(IOHelper ioHelper, CommandLine line); static OWLOntology getInputOntology(
      IOHelper ioHelper, CommandLine line, String catalogPath); static List<OWLOntology> getInputOntologies(
      IOHelper ioHelper, CommandLine line, boolean allowEmpty); static CommandState updateInputOntology(
      IOHelper ioHelper, CommandState state, CommandLine line); static CommandState updateInputOntology(
      IOHelper ioHelper, CommandState state, CommandLine line, boolean required); static File getOutputFile(CommandLine line); static IRI getOutputIRI(CommandLine line); static void maybeSaveOutput(CommandLine line, OWLOntology ontology); static IRI maybeCreateIRI(IOHelper ioHelper, String term, String field); static Map<String, String> getAddPrefixes(CommandLine line); static Set<IRI> getTerms(IOHelper ioHelper, CommandLine line); static Set<IRI> getTerms(IOHelper ioHelper, CommandLine line, boolean allowEmpty); static Set<IRI> getTerms(IOHelper ioHelper, CommandLine line, String singles, String paths); static OWLReasonerFactory getReasonerFactory(CommandLine line); static OWLReasonerFactory getReasonerFactory(CommandLine line, boolean allowEMR); static void printHelp(String usage, Options options); static void printVersion(); static Options getCommonOptions(); static CommandLine maybeGetCommandLine(
      String usage, Options options, String[] args, boolean stopAtNonOption); static CommandLine getCommandLine(String usage, Options options, String[] args); static void handleException(Exception exception); static void handleException(String usage, Options options, Exception exception); static List<OWLOntology> getInputOntologies(IOHelper ioHelper, CommandLine line); static List<OWLOntology> getInputOntologies(
      IOHelper ioHelper, CommandLine line, String catalogPath);  }
@Test public void testParseArgs() throws Exception { String arg = ""; List<String> args = new ArrayList<String>(); assertEquals("Empty arg list", CommandLineHelper.parseArgList(arg), args); arg = "command"; args.clear(); args.add("command"); assertEquals("Just a command", CommandLineHelper.parseArgList(arg), args); arg = "command -i --foo PARAM 'single quoted' \"double quoted\""; args.clear(); args.add("command"); args.add("-i"); args.add("--foo"); args.add("PARAM"); args.add("single quoted"); args.add("double quoted"); assertEquals("Basic command", CommandLineHelper.parseArgList(arg), args); arg = "command 'nested \"quotes\" with \\\" escapes and\nnewlines'"; args.clear(); args.add("command"); args.add("nested \"quotes\" with \\\" escapes and\nnewlines"); assertEquals("Nested quotations", CommandLineHelper.parseArgList(arg), args); arg = "unbalanced 'quotes"; exception.expect(Exception.class); CommandLineHelper.parseArgList(arg); }