EscapeUtil { public static List<String> split(String pArg, String pEscape, String pDelimiter) { if (pArg != null) { ArrayList<String> ret = new ArrayList<String>(); Pattern[] pattern = SPLIT_PATTERNS.get(pEscape + pDelimiter); if (pattern == null) { pattern = createSplitPatterns(pEscape, pDelimiter); SPLIT_PATTERNS.put(pEscape + pDelimiter,pattern); } final Matcher m = pattern[0].matcher(pArg); while (m.find() && m.start(1) != pArg.length()) { String trailingEscapes = m.group(2); ret.add(pattern[1].matcher(m.group(1) + (trailingEscapes != null ? trailingEscapes : "")).replaceAll("$1")); } return ret; } else { return null; } } private  EscapeUtil(); static String combineToPath(List<String> pParts); static List<String> parsePath(String pPath); static Stack<String> extractElementsFromPath(String pPath); static Stack<String> reversePath(List<String> pathParts); static List<String> split(String pArg, String pEscape, String pDelimiter); static String[] splitAsArray(String pArg, String pEscape, String pDelimiter); static String escape(String pArg, String pEscape, String pDelimiter); static final String PATH_ESCAPE; static final String CSV_ESCAPE; }
@Test public void commaSplitting() { for (int i = 0; i< COMMA_SPLIT_TEST_DATA.length; i +=2) { List got = EscapeUtil.split((String) COMMA_SPLIT_TEST_DATA[i], CSV_ESCAPE, ","); assertEquals(got, (List<String>) COMMA_SPLIT_TEST_DATA[i+1]); } }