StringUtil { public static String[] parseCSV(String csvString) { if (csvString == null) { return new String[0]; } if ("".equals(csvString)) { return new String[] { csvString }; } Collection<String> result = new ArrayList<String>(); char[] chars = csvString.toCharArray(); int prevCommaIndex = -1; for (int i = 0; i < chars.length; i++) { if (chars[i] == ',') { if (i == prevCommaIndex + 1) { result.add(""); } else { result.add(new String(chars, prevCommaIndex + 1, i - (prevCommaIndex + 1))); } if (i == chars.length - 1) { result.add(""); } prevCommaIndex = i; } else if (i == chars.length - 1) { result.add(new String(chars, prevCommaIndex + 1, i - (prevCommaIndex + 1) + 1)); } } return result.toArray(new String[0]); }  static boolean isWhitespace(char c); static boolean isZenHankakuSpace(char c); static String rtrim(String str); static String ltrim(String str); static String trim(String str); static String rtrimZ(String str); static String ltrimZ(String str); static String trimZ(String str); static String toShortClassName(String longClassName); static String getExtension(String name); static String toHexString(byte[] byteArray, String delim); static String capitalizeInitial(String str); static String[] parseCSV(String csvString); static String[] parseCSV(String csvString, String escapeString); static String dump(Map<?, ?> map); static String getArraysStr(Object[] arrayObj); static String hankakuToZenkaku(String value); static String zenkakuToHankaku(String value); static String filter(String str); static String toLikeCondition(String condition); static int getByteLength(String value, String encoding); static final String LINE_SEP; static final String LIKE_ESC_CHAR; }
@Test public void testParseCSVString01() throws Exception { String input = "abcde"; String[] result = StringUtil.parseCSV(input); String[] hope = { "abcde" }; assertEquals(hope.length, result.length); assertEquals(hope[0], result[0]); }
@Test public void testParseCSVString02() throws Exception { String input = null; String[] result = StringUtil.parseCSV(input); assertEquals(0, result.length); }
@Test public void testParseCSVString03() throws Exception { String input = ",abcde,,あいうえお,"; String[] result = StringUtil.parseCSV(input); String[] hope = { "", "abcde", "", "あいうえお", "" }; assertEquals(hope.length, result.length); for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVString04() throws Exception { String input = ""; String[] result = StringUtil.parseCSV(input); String[] hope = { "" }; assertEquals(hope.length, result.length); assertEquals(hope[0], result[0]); }
@Test public void testParseCSVStringString01() throws Exception { String[] result = StringUtil.parseCSV("", "\\"); assertEquals(1, result.length); assertEquals("", result[0]); }
@Test public void testParseCSVStringString02() throws Exception { String[] result = StringUtil.parseCSV(null, "\\"); assertEquals(0, result.length); }
@Test public void testParseCSVStringString03() throws Exception { String[] result = StringUtil.parseCSV("a,b", "\\"); assertEquals(2, result.length); String[] hope = new String[] { "a", "b" }; for (int i = 0; i < result.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString04() throws Exception { String[] result = StringUtil.parseCSV(",a,b", "\\"); assertEquals(3, result.length); String[] hope = new String[] { "", "a", "b" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString05() throws Exception { String[] result = StringUtil.parseCSV("a,b,", "\\"); assertEquals(3, result.length); String[] hope = new String[] { "a", "b", "" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString06() throws Exception { String[] result = StringUtil.parseCSV("a\\,b,c", "\\"); assertEquals(2, result.length); String[] hope = new String[] { "a,b", "c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString07() throws Exception { String[] result = StringUtil.parseCSV("a\\b,c", "\\"); assertEquals(2, result.length); String[] hope = new String[] { "ab", "c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString08() throws Exception { String[] result = StringUtil.parseCSV("\\,ab,c", "\\"); assertEquals(2, result.length); String[] hope = new String[] { ",ab", "c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString09() throws Exception { String[] result = StringUtil.parseCSV("ab,c\\,", "\\"); assertEquals(2, result.length); String[] hope = new String[] { "ab", "c," }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString10() throws Exception { String[] result = StringUtil.parseCSV("ab,,,c", "\\"); assertEquals(4, result.length); String[] hope = new String[] { "ab", "", "", "c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString11() throws Exception { String[] result = StringUtil.parseCSV("ab!,#,,c", "#!"); assertEquals(2, result.length); String[] hope = new String[] { "ab,,", "c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString12() throws Exception { String[] result = StringUtil.parseCSV("ab#!@,c", "!@#"); assertEquals(1, result.length); String[] hope = new String[] { "ab!,c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString13() throws Exception { String[] result = StringUtil.parseCSV("ab,c", ""); assertEquals(2, result.length); String[] hope = new String[] { "ab", "c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }
@Test public void testParseCSVStringString14() throws Exception { String[] result = StringUtil.parseCSV("ab,c", null); assertEquals(2, result.length); String[] hope = new String[] { "ab", "c" }; for (int i = 0; i < hope.length; i++) { assertEquals(hope[i], result[i]); } }