@Test public void tokenizeQuotedNonClosedTokens() { List<String> list = StringUtils.tokenize("\"foo bar baz"); Assert.assertEquals("List is not empty", 3, list.size()); Assert.assertEquals("Expecting \"foo", "\"foo", list.get(0)); Assert.assertEquals("Expecting bar", "bar", list.get(1)); Assert.assertEquals("Expecting baz", "baz", list.get(2)); }
public static List<String> tokenize(String stringToBeParsed) { final String TOKEN = "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|\\S+"; final String QUOTED_TOKEN = "^\"(.*)\"$"; List<String> options = new ArrayList<String>(); if (stringToBeParsed != null && stringToBeParsed.length() != 0) { Pattern p = Pattern.compile(TOKEN, Pattern.DOTALL); Matcher m = p.matcher(stringToBeParsed); while (m.find()) { if (!(m.group().trim().equals(""))) { options.add(Pattern.compile(QUOTED_TOKEN, Pattern.DOTALL).matcher(m.group().trim()).replaceAll("$1")); } } } return options; }
StringUtils { public static List<String> tokenize(String stringToBeParsed) { final String TOKEN = "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|\\S+"; final String QUOTED_TOKEN = "^\"(.*)\"$"; List<String> options = new ArrayList<String>(); if (stringToBeParsed != null && stringToBeParsed.length() != 0) { Pattern p = Pattern.compile(TOKEN, Pattern.DOTALL); Matcher m = p.matcher(stringToBeParsed); while (m.find()) { if (!(m.group().trim().equals(""))) { options.add(Pattern.compile(QUOTED_TOKEN, Pattern.DOTALL).matcher(m.group().trim()).replaceAll("$1")); } } } return options; } }
StringUtils { public static List<String> tokenize(String stringToBeParsed) { final String TOKEN = "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|\\S+"; final String QUOTED_TOKEN = "^\"(.*)\"$"; List<String> options = new ArrayList<String>(); if (stringToBeParsed != null && stringToBeParsed.length() != 0) { Pattern p = Pattern.compile(TOKEN, Pattern.DOTALL); Matcher m = p.matcher(stringToBeParsed); while (m.find()) { if (!(m.group().trim().equals(""))) { options.add(Pattern.compile(QUOTED_TOKEN, Pattern.DOTALL).matcher(m.group().trim()).replaceAll("$1")); } } } return options; }  }
StringUtils { public static List<String> tokenize(String stringToBeParsed) { final String TOKEN = "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|\\S+"; final String QUOTED_TOKEN = "^\"(.*)\"$"; List<String> options = new ArrayList<String>(); if (stringToBeParsed != null && stringToBeParsed.length() != 0) { Pattern p = Pattern.compile(TOKEN, Pattern.DOTALL); Matcher m = p.matcher(stringToBeParsed); while (m.find()) { if (!(m.group().trim().equals(""))) { options.add(Pattern.compile(QUOTED_TOKEN, Pattern.DOTALL).matcher(m.group().trim()).replaceAll("$1")); } } } return options; }  static List<String> tokenize(String stringToBeParsed); static String trimMultiline(String toTrim); }
StringUtils { public static List<String> tokenize(String stringToBeParsed) { final String TOKEN = "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|\\S+"; final String QUOTED_TOKEN = "^\"(.*)\"$"; List<String> options = new ArrayList<String>(); if (stringToBeParsed != null && stringToBeParsed.length() != 0) { Pattern p = Pattern.compile(TOKEN, Pattern.DOTALL); Matcher m = p.matcher(stringToBeParsed); while (m.find()) { if (!(m.group().trim().equals(""))) { options.add(Pattern.compile(QUOTED_TOKEN, Pattern.DOTALL).matcher(m.group().trim()).replaceAll("$1")); } } } return options; }  static List<String> tokenize(String stringToBeParsed); static String trimMultiline(String toTrim);  }