private void flushBuffer() throws IOException { for (Text t : buffer) { if (t instanceof Comment) { listener.onComment(t.getText()); } else if (t instanceof Whitespace) { listener.onWhitespace(t.getText()); } } buffer.clear(); }
@Override public void onSection(String section, String text) throws IOException { if (currentSection != null) { listener.onSectionEnd(currentSection); } flushBuffer(); currentSection = section; listener.onSection(section, text); skipToNewline = true; }
@Override public void cleanup() throws IOException { if (currentSection != null) { listener.onSectionEnd(currentSection); } flushBuffer(); }
@Override public void onWhitespace(String text) throws IOException { if (skipToNewline) { listener.onWhitespace(text); skipToNewline = !text.contains("\n"); } else { buffer.add(new Whitespace(text)); } }
@Override public void onOption(String name, String value, String text) throws IOException { flushBuffer(); listener.onOption(name, value, text); skipToNewline = true; }