AbstractCharStreamScanner implements CharStreamScanner { @Override public String readUntil(CharFilter filter, boolean acceptEof, String stop) { return readUntil(filter, acceptEof, stop, false); } AbstractCharStreamScanner(); @Override int readDigit(); @Override double readDouble(); @Override float readFloat(); @Override int skipWhile(CharFilter filter); @Override char skipWhileAndPeek(CharFilter filter); @Override char skipWhileAndPeek(CharFilter filter, int max); @Override String readWhile(CharFilter filter); @Override String readUntil(CharFilter filter, boolean acceptEof, String stop); @Override String readUntil(CharFilter filter, boolean acceptEot, String stop, boolean ignoreCase); @Override boolean skipOver(String substring); @Override boolean skipOver(String substring, boolean ignoreCase); @Override String readLine(); @Override boolean expect(String expected); @Override boolean expectStrict(String expected); @Override Character readJavaCharLiteral(); @Override String readJavaStringLiteral();  }
@Test public void testReadUntil() { String string = "string"; CharStreamScanner scanner; scanner = scanner(string); assertThat(scanner.readUntil('n', false)).isEqualTo("stri"); assertThat(scanner.next()).isEqualTo('g'); assertThat(scanner.hasNext()).isFalse(); scanner = scanner(string); assertThat(scanner.readUntil('x', false)).isNull(); assertThat(scanner.hasNext()).isFalse(); scanner = scanner(string); assertThat(scanner.readUntil('x', true)).isEqualTo(string); assertThat(scanner.hasNext()).isFalse(); }
@Test public void testReadUntilWithEscape() { CharStreamScanner scanner; scanner = scanner("bla\"Quotet text with \\\" and \\\\ inside!\"bla"); assertThat(scanner.readUntil('"', false)).isEqualTo("bla"); assertThat(scanner.readUntil('"', false, '\\')).isEqualTo("Quotet text with \" and \\ inside!"); assertThat(scanner.readUntil('\0', true)).isEqualTo("bla"); scanner = scanner("bla\"Quotet text with \"\" and \\ inside!\"bla"); assertThat(scanner.readUntil('"', false)).isEqualTo("bla"); assertThat(scanner.readUntil('"', false, '"')).isEqualTo("Quotet text with \" and \\ inside!"); assertThat(scanner.readUntil('\0', true)).isEqualTo("bla"); }
@Test public void testReadUntilWithCharFilterAndStopString() { String string = " blabla_$\n"; CharStreamScanner scanner; scanner = scanner(string); assertThat(scanner.readUntil(CharFilter.NEWLINE_FILTER, true, "$", false, true)).isEqualTo("blabla_"); scanner = scanner(string, true); assertThat(scanner.readUntil(CharFilter.NEWLINE_FILTER, true, "_$", false, true)).isEqualTo("blabla"); }
@Test public void testReadUntilWithSyntaxFull() { SimpleCharScannerSyntax syntax = new SimpleCharScannerSyntax() { @Override public String resolveEntity(String entity) { if ("lt".equals(entity)) { return "<"; } else if ("gt".equals(entity)) { return ">"; } return super.resolveEntity(entity); } }; syntax.setEscape('\\'); syntax.setQuote('"'); syntax.setQuoteEscape('$'); syntax.setAltQuote('\''); syntax.setAltQuoteStart('\''); syntax.setAltQuoteEnd('\''); syntax.setAltQuoteEscape('\''); syntax.setEntityStart('&'); syntax.setEntityEnd(';'); CharStreamScanner scanner = scanner("Hi \"$\"quote$\"\", 'a''l\\t' and \\\"esc\\'&lt;&gt;&lt;x&gt;!"); String result = scanner.readUntil('!', false, syntax); assertThat(result).isEqualTo("Hi \"quote\", a'l\\t and \"esc'<><x>"); assertThat(scanner.hasNext()).isFalse(); scanner = scanner("Hi 'qu''ote'"); result = scanner.readUntil('\0', true, syntax); assertThat(result).isEqualTo("Hi qu'ote"); assertThat(scanner.hasNext()).isFalse(); }