SectionString { public List<String> split(char separator) { int index = content.getIndex(); List<String> selected = new ArrayList<>(); StringBuilder content = new StringBuilder(); Stack<Character> sequences = new Stack<>(); while (this.content.hasNext()) { char current = this.content.next(); if (current == separator && sequences.size() == 0) { selected.add(content.toString()); content.setLength(0); continue; } SectionStack.verifySequences(sequences, escapeCharacters, openingCharacters, closingCharacters, this.content.getPrevious(), current); content.append(current); } if (content.length() > 0) { selected.add(content.toString()); } this.content.setIndex(index); return selected; } private  SectionString(SectionStringConfiguration configuration); List<String> split(char separator); static SectionStringConfiguration of(String content);  }
@Test void split() { SectionString sectionString = SectionString.of(CONTENT).build(); List<String> selected = sectionString.split(SEPARATOR); Assertions.assertNotNull(selected); Assertions.assertEquals(4, selected.size()); Assertions.assertAll( () -> Assertions.assertEquals("Test", selected.get(0)), () -> Assertions.assertEquals("Bracket(|)", selected.get(1)), () -> Assertions.assertEquals("String'|'", selected.get(2)), () -> Assertions.assertEquals("Test", selected.get(3)) ); }