code: public static Slice substring(Slice utf8, int codePointStart, int codePointLength)
      {
          checkArgument(codePointStart >= 0, "codePointStart is negative");
          checkArgument(codePointLength >= 0, "codePointLength is negative");
  
          int indexStart = offsetOfCodePoint(utf8, codePointStart);
          if (indexStart < 0) {
              throw new IllegalArgumentException("UTF-8 does not contain " + codePointStart + " code points");
          }
          if (codePointLength == 0) {
              return Slices.EMPTY_SLICE;
          }
          int indexEnd = offsetOfCodePoint(utf8, indexStart, codePointLength - 1);
          if (indexEnd < 0) {
              throw new IllegalArgumentException("UTF-8 does not contain " + (codePointStart + codePointLength) + " code points");
          }
          indexEnd += lengthOfCodePoint(utf8, indexEnd);
          if (indexEnd > utf8.length()) {
              throw new InvalidUtf8Exception("UTF-8 is not well formed");
          }
          return utf8.slice(indexStart, indexEnd - indexStart);
      }
docs: Gets the substring starting at {@code codePointStart} and extending for
  {@code codePointLength} code points.
  <p>
  Note: This method does not explicitly check for valid UTF-8, and may
  return incorrect results or throw an exception for invalid UTF-8.