code: protected int nextEscapeIndex(CharSequence csq, int start, int end) {
      int index = start;
      while (index < end) {
        int cp = codePointAt(csq, index, end);
        if (cp < 0 || escape(cp) != null) {
          break;
        }
        index += Character.isSupplementaryCodePoint(cp) ? 2 : 1;
      }
      return index;
    }
docs: Scans a sub-sequence of characters from a given {@link CharSequence}, returning the index of
  the next character that requires escaping.
  
  <p><b>Note:</b> When implementing an escaper, it is a good idea to override this method for
  efficiency. The base class implementation determines successive Unicode code points and invokes
  {@link #escape(int)} for each of them. If the semantics of your escaper are such that code
  points in the supplementary range are either all escaped or all unescaped, this method can be
  implemented more efficiently using {@link CharSequence#charAt(int)}.
  
  <p>Note however that if your escaper does not escape characters in the supplementary range, you
  should either continue to validate the correctness of any surrogate characters encountered or
  provide a clear warning to users that your escaper does not validate its input.
  
  <p>See {@link com.google.common.net.PercentEscaper} for an example.
  
  @param csq a sequence of characters
  @param start the index of the first character to be scanned
  @param end the index immediately after the last character to be scanned
  @throws IllegalArgumentException if the scanned sub-sequence of {@code csq} contains invalid
  surrogate pairs