@Test public void testUnicodeFields() { String csv = "{\"µ½æƺɑɣʘ\", \"ʬʗɮɆ\"}"; String[] tokens = ParserUtil.parseListRecord(csv); assertThat(tokens, notNullValue()); assertThat(tokens.length, is(2)); assertThat(tokens[0], is("µ½æƺɑɣʘ")); assertThat(tokens[1], is("ʬʗɮɆ")); csv = "{\"\u039A\u03A0\", \"\u03BA\u03BF\"}"; tokens = ParserUtil.parseListRecord(csv); assertThat(tokens, notNullValue()); assertThat(tokens.length, is(2)); assertThat(tokens[0], is("ΚΠ")); assertThat(tokens[1], is("κο")); }
public static String[] parseListRecord(String line) { if (noLength(line)) { return null; } line = line.trim(); if (line.startsWith("{")) { line = line.substring(1); } if (line.endsWith("}")) { line = line.substring(0, line.length() - 1); } if (line.trim().length() == 0) { return new String[0]; } final CharacterIterator chit = new StringCharacterIterator(line); final List<String> fields = new ArrayList<String>(); final StringBuilder fb = new StringBuilder(); boolean inField = false; for (char c = chit.first(); c != CharacterIterator.DONE; c = chit .next()) { if (!inField && c == FIELD_BOUNDARY) { inField = true; fb.setLength(0); } else if (inField && c == FIELD_BOUNDARY) { int mark = chit.getIndex(); char previousChar = chit.previous(); if (previousChar == ESCAPE) { fb.deleteCharAt(fb.length() - 1); fb.append(c); } else { inField = false; } chit.setIndex(mark); } else if (!inField && c == FIELD_SEPARATOR) { fields.add(fb.toString()); } else if (inField) { fb.append(c); } } if (!line.endsWith(",")) { fields.add(fb.toString()); } return fields.toArray(new String[fields.size()]); }
ParserUtil { public static String[] parseListRecord(String line) { if (noLength(line)) { return null; } line = line.trim(); if (line.startsWith("{")) { line = line.substring(1); } if (line.endsWith("}")) { line = line.substring(0, line.length() - 1); } if (line.trim().length() == 0) { return new String[0]; } final CharacterIterator chit = new StringCharacterIterator(line); final List<String> fields = new ArrayList<String>(); final StringBuilder fb = new StringBuilder(); boolean inField = false; for (char c = chit.first(); c != CharacterIterator.DONE; c = chit .next()) { if (!inField && c == FIELD_BOUNDARY) { inField = true; fb.setLength(0); } else if (inField && c == FIELD_BOUNDARY) { int mark = chit.getIndex(); char previousChar = chit.previous(); if (previousChar == ESCAPE) { fb.deleteCharAt(fb.length() - 1); fb.append(c); } else { inField = false; } chit.setIndex(mark); } else if (!inField && c == FIELD_SEPARATOR) { fields.add(fb.toString()); } else if (inField) { fb.append(c); } } if (!line.endsWith(",")) { fields.add(fb.toString()); } return fields.toArray(new String[fields.size()]); } }
ParserUtil { public static String[] parseListRecord(String line) { if (noLength(line)) { return null; } line = line.trim(); if (line.startsWith("{")) { line = line.substring(1); } if (line.endsWith("}")) { line = line.substring(0, line.length() - 1); } if (line.trim().length() == 0) { return new String[0]; } final CharacterIterator chit = new StringCharacterIterator(line); final List<String> fields = new ArrayList<String>(); final StringBuilder fb = new StringBuilder(); boolean inField = false; for (char c = chit.first(); c != CharacterIterator.DONE; c = chit .next()) { if (!inField && c == FIELD_BOUNDARY) { inField = true; fb.setLength(0); } else if (inField && c == FIELD_BOUNDARY) { int mark = chit.getIndex(); char previousChar = chit.previous(); if (previousChar == ESCAPE) { fb.deleteCharAt(fb.length() - 1); fb.append(c); } else { inField = false; } chit.setIndex(mark); } else if (!inField && c == FIELD_SEPARATOR) { fields.add(fb.toString()); } else if (inField) { fb.append(c); } } if (!line.endsWith(",")) { fields.add(fb.toString()); } return fields.toArray(new String[fields.size()]); } private  ParserUtil(); }
ParserUtil { public static String[] parseListRecord(String line) { if (noLength(line)) { return null; } line = line.trim(); if (line.startsWith("{")) { line = line.substring(1); } if (line.endsWith("}")) { line = line.substring(0, line.length() - 1); } if (line.trim().length() == 0) { return new String[0]; } final CharacterIterator chit = new StringCharacterIterator(line); final List<String> fields = new ArrayList<String>(); final StringBuilder fb = new StringBuilder(); boolean inField = false; for (char c = chit.first(); c != CharacterIterator.DONE; c = chit .next()) { if (!inField && c == FIELD_BOUNDARY) { inField = true; fb.setLength(0); } else if (inField && c == FIELD_BOUNDARY) { int mark = chit.getIndex(); char previousChar = chit.previous(); if (previousChar == ESCAPE) { fb.deleteCharAt(fb.length() - 1); fb.append(c); } else { inField = false; } chit.setIndex(mark); } else if (!inField && c == FIELD_SEPARATOR) { fields.add(fb.toString()); } else if (inField) { fb.append(c); } } if (!line.endsWith(",")) { fields.add(fb.toString()); } return fields.toArray(new String[fields.size()]); } private  ParserUtil(); static String[] parseListRecord(String line); static String[] parseValueSeparated(String value); }
ParserUtil { public static String[] parseListRecord(String line) { if (noLength(line)) { return null; } line = line.trim(); if (line.startsWith("{")) { line = line.substring(1); } if (line.endsWith("}")) { line = line.substring(0, line.length() - 1); } if (line.trim().length() == 0) { return new String[0]; } final CharacterIterator chit = new StringCharacterIterator(line); final List<String> fields = new ArrayList<String>(); final StringBuilder fb = new StringBuilder(); boolean inField = false; for (char c = chit.first(); c != CharacterIterator.DONE; c = chit .next()) { if (!inField && c == FIELD_BOUNDARY) { inField = true; fb.setLength(0); } else if (inField && c == FIELD_BOUNDARY) { int mark = chit.getIndex(); char previousChar = chit.previous(); if (previousChar == ESCAPE) { fb.deleteCharAt(fb.length() - 1); fb.append(c); } else { inField = false; } chit.setIndex(mark); } else if (!inField && c == FIELD_SEPARATOR) { fields.add(fb.toString()); } else if (inField) { fb.append(c); } } if (!line.endsWith(",")) { fields.add(fb.toString()); } return fields.toArray(new String[fields.size()]); } private  ParserUtil(); static String[] parseListRecord(String line); static String[] parseValueSeparated(String value);  }