private Position position() { return new Position(locator.getLineNumber(), locator.getColumnNumber()); }
public Position searchForward(final int startLine, final int startCol, final Pattern regex) { int loopStartLine = startLine; int loopStartCol = startCol; while (loopStartLine < this.lines.size()) { final String line = this.lines.get(loopStartLine); final Matcher matcher = regex.matcher(line); if (loopStartCol < line.length() && matcher.find(loopStartCol)) { // return next line, since we're zero indexed here, but 1 indexed for lines return new Position(loopStartLine + 1, matcher.start() + 1); } else { loopStartLine++; loopStartCol = 0; } } return null; }
public Position position() { return new Position(this.location.getLineNumber(), this.location.getColumnNumber()); }
public Position searchBackward(final int startLine, final int startCol, final Pattern regex) { int loopStartLine = startLine; int loopStartCol = startCol; while (loopStartLine >= 0) { final String line = this.lines.get(loopStartLine); final Matcher matcher = regex.matcher(line); if (loopStartCol >= line.length()) { loopStartCol = line.length() - 1; } if (loopStartCol >= 0 && matcher.find(loopStartCol)) { // return next line, since we're zero indexed here, but 1 indexed for lines return new Position(loopStartLine + 1, matcher.start() + 1); } else if (loopStartCol > 0) { loopStartCol--; } else { loopStartLine--; loopStartCol = Integer.MAX_VALUE; } } return null; }
private Position lastPosition = new Position(1, 2);