code: public void setLimit(int lim) {
          if(0<=lim && lim<=rep.length()) {
              limit=lim;
          } else {
              limit=rep.length();
          }
          reachedLimit=false;
      }
docs: Set the iteration limit for nextCaseMapCP() to an index within the string.
  If the limit parameter is negative or past the string, then the
  string length is restored as the iteration limit.
  
  @param lim The iteration limit.