CharacterReader { String consumeToAny(final char... chars) { int start = pos; OUTER: while (pos < length) { for (int i = 0; i < chars.length; i++) { if (input[pos] == chars[i]) break OUTER; } pos++; } return pos > start ? new String(input, start, pos-start) : ""; } CharacterReader(String input); @Override String toString();  }
@Test public void consumeToAny() { CharacterReader r = new CharacterReader("One &bar; qux"); assertEquals("One ", r.consumeToAny('&', ';')); assertTrue(r.matches('&')); assertTrue(r.matches("&bar;")); assertEquals('&', r.consume()); assertEquals("bar", r.consumeToAny('&', ';')); assertEquals(';', r.consume()); assertEquals(" qux", r.consumeToAny('&', ';')); }