CharacterReader { String consumeLetterSequence() { int start = pos; while (pos < length) { char c = input[pos]; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || Character.isLetter(c)) pos++; else break; } return cacheString(start, pos - start); } CharacterReader(String input); @Override String toString();  }
@Test public void consumeLetterSequence() { CharacterReader r = new CharacterReader("One &bar; qux"); assertEquals("One", r.consumeLetterSequence()); assertEquals(" &", r.consumeTo("bar;")); assertEquals("bar", r.consumeLetterSequence()); assertEquals("; qux", r.consumeToEnd()); }