CharacterReader { String consumeToAny(final char... chars) { final int start = pos; final int remaining = length; final char[] val = input; OUTER: while (pos < remaining) { for (char c : chars) { if (val[pos] == c) break OUTER; } pos++; } return pos > start ? cacheString(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('&', ';')); }