### Question:
StringUtil { public static List<Object> parseCSVLine(String line, String separatorRegex) { List<Object> matches = new ArrayList<>(); int currentPosition = 0; Matcher separatorMatcher = Pattern.compile("^" + separatorRegex).matcher(line); Matcher stringMatcher = Pattern.compile("^" + QUOTED_STRING_REGEX).matcher(line); Matcher doubleMatcher = Pattern.compile("^" + DOUBLE_REGEX).matcher(line); while (currentPosition < line.length()) { if (stringMatcher.region(currentPosition, line.length()).useAnchoringBounds(true).find()) { String token = line.substring(currentPosition + 1, stringMatcher.end() - 1); matches.add(unescapeString(token)); currentPosition = stringMatcher.end(); } else if (doubleMatcher.region(currentPosition, line.length()).useAnchoringBounds(true).find()) { Double token = Double.parseDouble(line.substring(currentPosition, doubleMatcher.end())); matches.add(token); currentPosition = doubleMatcher.end(); } else { throw new IllegalArgumentException("Can't parse line: expected token at " + currentPosition + " (" + line + ")"); } if (currentPosition < line.length()) { if (!separatorMatcher.region(currentPosition, line.length()).useAnchoringBounds(true).find()) { throw new IllegalArgumentException("Can't parse line: expected separator at " + currentPosition + " (" + line + ")"); } currentPosition = separatorMatcher.end(); } } return matches; } private  StringUtil(); static String unquote(String quotedString); static String unescapeString(String escapedString); static List<Object> parseCSVLine(String line, String separatorRegex); static final String STRING_ESCAPE_SEQUENCE_REGEX; static final String QUOTED_STRING_REGEX; static final String SINGLEQUOTED_STRING_REGEX; static final String DOUBLE_REGEX; static final String DOUBLE_REGEX_WITH_NAN; }### Answer:
@Test public void parseCSVLine1() { String line = "\"a\" 1 2.3 \"b\""; List<Object> tokens = StringUtil.parseCSVLine(line, "\\s*"); assertThat(tokens, equalTo(Arrays.<Object>asList("a", 1.0, 2.3, "b"))); }
@Test public void parseCSVLine2() { String line = "\"This is a test\" \"Another test\" \"No spaces\"\"Between these two\""; List<Object> tokens = StringUtil.parseCSVLine(line, "\\s*"); assertThat(tokens, equalTo(Arrays.<Object>asList("This is a test", "Another test", "No spaces", "Between these two"))); }
@Test public void parseCSVLine3() { String line = "\"And he asked:\\\"Does quoting works?\\\"\""; List<Object> tokens = StringUtil.parseCSVLine(line, "\\s*"); assertThat(tokens, equalTo(Arrays.<Object>asList("And he asked:\"Does quoting works?\""))); }