code: private static int matchRest (Replaceable text, int start, int limit, String s) {
          int maxLen;
          int slen = s.length();
          if (start < limit) {
              maxLen = limit - start;
              if (maxLen > slen) maxLen = slen;
              for (int i = 1; i < maxLen; ++i) {
                  if (text.charAt(start + i) != s.charAt(i)) return 0;
              }
          } else {
              maxLen = start - limit;
              if (maxLen > slen) maxLen = slen;
              --slen; // <=> slen = s.length() - 1;
              for (int i = 1; i < maxLen; ++i) {
                  if (text.charAt(start - i) != s.charAt(slen - i)) return 0;
              }
          }
          return maxLen;
      }
docs: Returns the longest match for s in text at the given position.
  If limit > start then match forward from start+1 to limit
  matching all characters except s.charAt(0).  If limit < start,
  go backward starting from start-1 matching all characters
  except s.charAt(s.length()-1).  This method assumes that the
  first character, text.charAt(start), matches s, so it does not
  check it.
  @param text the text to match
  @param start the first character to match.  In the forward
  direction, text.charAt(start) is matched against s.charAt(0).
  In the reverse direction, it is matched against
  s.charAt(s.length()-1).
  @param limit the limit offset for matching, either last+1 in
  the forward direction, or last-1 in the reverse direction,
  where last is the index of the last character to match.
  @return If part of s matches up to the limit, return |limit -
  start|.  If all of s matches before reaching the limit, return
  s.length().  If there is a mismatch between s and text, return
  0