@Test void testUnQuote() { assertEquals("", QuotedCSV.unquote("")); assertEquals("", QuotedCSV.unquote("\"\"")); assertEquals("foo", QuotedCSV.unquote("foo")); assertEquals("foo", QuotedCSV.unquote("\"foo\"")); assertEquals("foo", QuotedCSV.unquote("f\"o\"o")); assertEquals("\"foo", QuotedCSV.unquote("\"\\\"foo\"")); assertEquals("\\foo", QuotedCSV.unquote("\\foo")); }
public static String unquote(String s) { if (!StringUtils.hasText(s)) { return s; } int l = s.length(); int i = 0; for (; i < l; i++) { char c = s.charAt(i); if (c == '"') break; } if (i == l) return s; boolean quoted = true; boolean sloshed = false; StringBuilder buffer = new StringBuilder(); buffer.append(s, 0, i); i++; for (; i < l; i++) { char c = s.charAt(i); if (quoted) { if (sloshed) { buffer.append(c); sloshed = false; } else if (c == '"') quoted = false; else if (c == '\\') sloshed = true; else buffer.append(c); } else if (c == '"') quoted = true; else buffer.append(c); } return buffer.toString(); }
QuotedCSV implements Iterable<String> { public static String unquote(String s) { if (!StringUtils.hasText(s)) { return s; } int l = s.length(); int i = 0; for (; i < l; i++) { char c = s.charAt(i); if (c == '"') break; } if (i == l) return s; boolean quoted = true; boolean sloshed = false; StringBuilder buffer = new StringBuilder(); buffer.append(s, 0, i); i++; for (; i < l; i++) { char c = s.charAt(i); if (quoted) { if (sloshed) { buffer.append(c); sloshed = false; } else if (c == '"') quoted = false; else if (c == '\\') sloshed = true; else buffer.append(c); } else if (c == '"') quoted = true; else buffer.append(c); } return buffer.toString(); } }
QuotedCSV implements Iterable<String> { public static String unquote(String s) { if (!StringUtils.hasText(s)) { return s; } int l = s.length(); int i = 0; for (; i < l; i++) { char c = s.charAt(i); if (c == '"') break; } if (i == l) return s; boolean quoted = true; boolean sloshed = false; StringBuilder buffer = new StringBuilder(); buffer.append(s, 0, i); i++; for (; i < l; i++) { char c = s.charAt(i); if (quoted) { if (sloshed) { buffer.append(c); sloshed = false; } else if (c == '"') quoted = false; else if (c == '\\') sloshed = true; else buffer.append(c); } else if (c == '"') quoted = true; else buffer.append(c); } return buffer.toString(); } QuotedCSV(String... values);  QuotedCSV(boolean keepQuotes, String... values); }
QuotedCSV implements Iterable<String> { public static String unquote(String s) { if (!StringUtils.hasText(s)) { return s; } int l = s.length(); int i = 0; for (; i < l; i++) { char c = s.charAt(i); if (c == '"') break; } if (i == l) return s; boolean quoted = true; boolean sloshed = false; StringBuilder buffer = new StringBuilder(); buffer.append(s, 0, i); i++; for (; i < l; i++) { char c = s.charAt(i); if (quoted) { if (sloshed) { buffer.append(c); sloshed = false; } else if (c == '"') quoted = false; else if (c == '\\') sloshed = true; else buffer.append(c); } else if (c == '"') quoted = true; else buffer.append(c); } return buffer.toString(); } QuotedCSV(String... values);  QuotedCSV(boolean keepQuotes, String... values); static String unquote(String s); void addValue(String value); int size(); boolean isEmpty(); List<String> getValues(); @Override Iterator<String> iterator(); @Override String toString(); }
QuotedCSV implements Iterable<String> { public static String unquote(String s) { if (!StringUtils.hasText(s)) { return s; } int l = s.length(); int i = 0; for (; i < l; i++) { char c = s.charAt(i); if (c == '"') break; } if (i == l) return s; boolean quoted = true; boolean sloshed = false; StringBuilder buffer = new StringBuilder(); buffer.append(s, 0, i); i++; for (; i < l; i++) { char c = s.charAt(i); if (quoted) { if (sloshed) { buffer.append(c); sloshed = false; } else if (c == '"') quoted = false; else if (c == '\\') sloshed = true; else buffer.append(c); } else if (c == '"') quoted = true; else buffer.append(c); } return buffer.toString(); } QuotedCSV(String... values);  QuotedCSV(boolean keepQuotes, String... values); static String unquote(String s); void addValue(String value); int size(); boolean isEmpty(); List<String> getValues(); @Override Iterator<String> iterator(); @Override String toString();  }