code: public static int findCodePointOffset(String source, int offset16) {
          if (offset16 < 0 || offset16 > source.length()) {
              throw new StringIndexOutOfBoundsException(offset16);
          }
  
          int result = 0;
          char ch;
          boolean hadLeadSurrogate = false;
  
          for (int i = 0; i < offset16; ++i) {
              ch = source.charAt(i);
              if (hadLeadSurrogate && isTrailSurrogate(ch)) {
                  hadLeadSurrogate = false; // count valid trail as zero
              } else {
                  hadLeadSurrogate = isLeadSurrogate(ch);
                  ++result; // count others as 1
              }
          }
  
          if (offset16 == source.length()) {
              return result;
          }
  
          // end of source being the less significant surrogate character
          // shift result back to the start of the supplementary character
          if (hadLeadSurrogate && (isTrailSurrogate(source.charAt(offset16)))) {
              result--;
          }
  
          return result;
      }
docs: Returns the UTF-32 offset corresponding to the first UTF-32 boundary at or after the given
  UTF-16 offset. Used for random access. See the {@link UTF16 class description} for
  notes on roundtripping.<br>
  <i>Note: If the UTF-16 offset is into the middle of a surrogate pair, then the UTF-32 offset
  of the <strong>lead</strong> of the pair is returned. </i>
  <p>
  To find the UTF-32 length of a string, use:
  
  <pre>
  len32 = countCodePoint(source, source.length());
  </pre>
  
  @param source Text to analyse
  @param offset16 UTF-16 offset &lt; source text length.
  @return UTF-32 offset
  @exception IndexOutOfBoundsException If offset16 is out of bounds.