public int matches()

in spectator-api/src/main/java/com/netflix/spectator/impl/matcher/ZeroOrMoreMatcher.java [62:99]


  public int matches(String str, int start, int length) {
    final int end = start + length;
    if (repeated instanceof AnyMatcher) {
      final int stop = end - next.minLength();
      for (int pos = start; pos >= 0 && pos <= stop; ++pos) {
        int p = next.matches(str, pos, end - pos);
        if (p >= start) {
          return p;
        }
      }
      return Constants.NO_MATCH;
    } else if (next != TrueMatcher.INSTANCE) {
      final int stop = end - next.minLength();
      int pos = start;
      while (pos >= start && pos <= stop) {
        int p = next.matches(str, pos, end - pos);
        if (p >= start) {
          return p;
        }
        // The repeated portion could potentially be an empty string matcher, to avoid an
        // endless loop we need to ensure that the position has moved forward
        int tmp = repeated.matches(str, pos, end - pos);
        if (tmp == pos) {
          return Constants.NO_MATCH;
        }
        pos = tmp;
      }
      return Constants.NO_MATCH;
    } else {
      int matchPos = Constants.NO_MATCH;
      int pos = start;
      while (pos > matchPos) {
        matchPos = pos;
        pos = repeated.matches(str, pos, end - pos);
      }
      return matchPos;
    }
  }