public int matches(int strIndex, CharSequence testString, MatchResultImpl matchResult) {
    int rightBound =
        matchResult.hasAnchoringBounds() ? matchResult.getRightBound() : testString.length();

    if (strIndex >= rightBound) {
      matchResult.setConsumed(consCounter, 0);
      return next.matches(strIndex, testString, matchResult);
    }
    // check final line terminator;

    if ((rightBound - strIndex) == 1 && testString.charAt(strIndex) == '\n') {
      matchResult.setConsumed(consCounter, 1);
      return next.matches(strIndex + 1, testString, matchResult);
    }

    return -1;
  }
 public boolean hasConsumed(MatchResultImpl matchResult) {
   int cons;
   boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0);
   matchResult.setConsumed(consCounter, -1);
   return res;
 }