/** * Walks forward with the caret until it points at the given character. Then advances the * position by one. Case-Sensitive comparison is used. * * @param c * the character to walk to * @return true if the character was found, false if the end of the string was reached while * searching */ public boolean walkAfterCharCheckCase(char c) { boolean found = walkToCharCheckCase(c); if (found) { offset++; } return found; }
@Test public void test() { String test = " ABCDEFGH\t\r\nabcdefg"; Caret c = new Caret(test); assertThat(c.walkToCharCheckCase('C'), equalTo(true)); assertThat(c.get(0), equalTo('C')); c.goTo(0); assertThat(c.walkToCharCheckCase('c'), equalTo(true)); assertThat(c.get(0), equalTo('c')); c.goTo(0); assertThat(c.walkToCharCheckCase('z'), equalTo(false)); assertThat(c.endReached(), equalTo(true)); } }
@Test public void test() { String test = " ABCDEFGH\t\r \nabcdefg"; Caret c = new Caret(test); c.walkToCharCheckCase('A'); c.walkBackBeforeWhitespaces(); assertThat(c.get(0), equalTo('A')); c.goN(-1); c.walkBackBeforeWhitespaces(); assertThat(c.getOffset(), equalTo(0)); c.walkToCharCheckCase('a'); c.goN(-1); c.walkBackBeforeWhitespaces(); assertThat(c.get(0), equalTo('H')); } }