@Test public void testTwoEmptySegments() { String text = ","; final String[] split = StringUtil.split(text); assertEquals(0, split.length); }
public static String[] split(String text) { if (text == null || text.isEmpty()) { return NO_STRINGS; } final Matcher matcher = ITEM_PATTERN.matcher(text); String item = null; StringBuilder b = null; ArrayList<String> list = new ArrayList<>(4); while (matcher.find()) { if (matcher.group(1) != null) { if (item != null) { list.add(item); item = null; } } else if (matcher.group(2) != null) { assert item == null : "Regular expression matching malfunctioned"; item = matcher.group(2); } else if (matcher.group(3) != null) { if (b == null) { b = new StringBuilder(); } if (item != null) { b.append(item); item = null; } b.append(matcher.group(3)); while (matcher.find()) { if (matcher.group(1) != null) { break; } else if (matcher.group(2) != null) { b.append(matcher.group(2)); } else if (matcher.group(3) != null) { b.append(matcher.group(3)); } else { throw new IllegalStateException(); } } list.add(b.toString()); b.setLength(0); } else { throw new IllegalStateException(); } } if (item != null) { list.add(item); } return list.toArray(NO_STRINGS); }
StringUtil { public static String[] split(String text) { if (text == null || text.isEmpty()) { return NO_STRINGS; } final Matcher matcher = ITEM_PATTERN.matcher(text); String item = null; StringBuilder b = null; ArrayList<String> list = new ArrayList<>(4); while (matcher.find()) { if (matcher.group(1) != null) { if (item != null) { list.add(item); item = null; } } else if (matcher.group(2) != null) { assert item == null : "Regular expression matching malfunctioned"; item = matcher.group(2); } else if (matcher.group(3) != null) { if (b == null) { b = new StringBuilder(); } if (item != null) { b.append(item); item = null; } b.append(matcher.group(3)); while (matcher.find()) { if (matcher.group(1) != null) { break; } else if (matcher.group(2) != null) { b.append(matcher.group(2)); } else if (matcher.group(3) != null) { b.append(matcher.group(3)); } else { throw new IllegalStateException(); } } list.add(b.toString()); b.setLength(0); } else { throw new IllegalStateException(); } } if (item != null) { list.add(item); } return list.toArray(NO_STRINGS); } }
StringUtil { public static String[] split(String text) { if (text == null || text.isEmpty()) { return NO_STRINGS; } final Matcher matcher = ITEM_PATTERN.matcher(text); String item = null; StringBuilder b = null; ArrayList<String> list = new ArrayList<>(4); while (matcher.find()) { if (matcher.group(1) != null) { if (item != null) { list.add(item); item = null; } } else if (matcher.group(2) != null) { assert item == null : "Regular expression matching malfunctioned"; item = matcher.group(2); } else if (matcher.group(3) != null) { if (b == null) { b = new StringBuilder(); } if (item != null) { b.append(item); item = null; } b.append(matcher.group(3)); while (matcher.find()) { if (matcher.group(1) != null) { break; } else if (matcher.group(2) != null) { b.append(matcher.group(2)); } else if (matcher.group(3) != null) { b.append(matcher.group(3)); } else { throw new IllegalStateException(); } } list.add(b.toString()); b.setLength(0); } else { throw new IllegalStateException(); } } if (item != null) { list.add(item); } return list.toArray(NO_STRINGS); } private  StringUtil(); }
StringUtil { public static String[] split(String text) { if (text == null || text.isEmpty()) { return NO_STRINGS; } final Matcher matcher = ITEM_PATTERN.matcher(text); String item = null; StringBuilder b = null; ArrayList<String> list = new ArrayList<>(4); while (matcher.find()) { if (matcher.group(1) != null) { if (item != null) { list.add(item); item = null; } } else if (matcher.group(2) != null) { assert item == null : "Regular expression matching malfunctioned"; item = matcher.group(2); } else if (matcher.group(3) != null) { if (b == null) { b = new StringBuilder(); } if (item != null) { b.append(item); item = null; } b.append(matcher.group(3)); while (matcher.find()) { if (matcher.group(1) != null) { break; } else if (matcher.group(2) != null) { b.append(matcher.group(2)); } else if (matcher.group(3) != null) { b.append(matcher.group(3)); } else { throw new IllegalStateException(); } } list.add(b.toString()); b.setLength(0); } else { throw new IllegalStateException(); } } if (item != null) { list.add(item); } return list.toArray(NO_STRINGS); } private  StringUtil(); static String[] split(String text); }
StringUtil { public static String[] split(String text) { if (text == null || text.isEmpty()) { return NO_STRINGS; } final Matcher matcher = ITEM_PATTERN.matcher(text); String item = null; StringBuilder b = null; ArrayList<String> list = new ArrayList<>(4); while (matcher.find()) { if (matcher.group(1) != null) { if (item != null) { list.add(item); item = null; } } else if (matcher.group(2) != null) { assert item == null : "Regular expression matching malfunctioned"; item = matcher.group(2); } else if (matcher.group(3) != null) { if (b == null) { b = new StringBuilder(); } if (item != null) { b.append(item); item = null; } b.append(matcher.group(3)); while (matcher.find()) { if (matcher.group(1) != null) { break; } else if (matcher.group(2) != null) { b.append(matcher.group(2)); } else if (matcher.group(3) != null) { b.append(matcher.group(3)); } else { throw new IllegalStateException(); } } list.add(b.toString()); b.setLength(0); } else { throw new IllegalStateException(); } } if (item != null) { list.add(item); } return list.toArray(NO_STRINGS); } private  StringUtil(); static String[] split(String text);  }