CharacterReader { boolean matchesIgnoreCase(String seq) { int scanLength = seq.length(); if (scanLength > length - pos) return false; for (int offset = 0; offset < scanLength; offset++) { char upScan = Character.toUpperCase(seq.charAt(offset)); char upTarget = Character.toUpperCase(input[pos + offset]); if (upScan != upTarget) return false; } return true; } CharacterReader(String input); @Override String toString();  }
@Test public void matchesIgnoreCase() { CharacterReader r = new CharacterReader("One Two Three"); assertTrue(r.matchesIgnoreCase("O")); assertTrue(r.matchesIgnoreCase("o")); assertTrue(r.matches('O')); assertFalse(r.matches('o')); assertTrue(r.matchesIgnoreCase("One Two Three")); assertTrue(r.matchesIgnoreCase("ONE two THREE")); assertTrue(r.matchesIgnoreCase("One")); assertTrue(r.matchesIgnoreCase("one")); assertEquals('O', r.consume()); assertFalse(r.matchesIgnoreCase("One")); assertTrue(r.matchesIgnoreCase("NE Two Three")); assertFalse(r.matchesIgnoreCase("ne Two Three Four")); assertEquals("ne Two Three", r.consumeToEnd()); assertFalse(r.matchesIgnoreCase("ne")); }