public static int findOffsetFromCodePoint(StringBuffer source, int offset32) {
        char ch;
        int size = source.length(), result = 0, count = offset32;
        if (offset32 < 0 || offset32 > size) {
            throw new StringIndexOutOfBoundsException(offset32);
        }
        while (result < size && count > 0) {
            ch = source.charAt(result);
            if (isLeadSurrogate(ch) && ((result + 1) < size)
                    && isTrailSurrogate(source.charAt(result + 1))) {
                result++;
            }

            count--;
            result++;
        }
        if (count != 0) {
            throw new StringIndexOutOfBoundsException(offset32);
        }
        return result;
    }
public static int findOffsetFromCodePoint ( StringBuffer source , int offset32 ) { char ch ; int size = source . length ( ) , result = 0 , count = offset32 ; if ( offset32 < 0 || offset32 > size ) { throw new StringIndexOutOfBoundsException ( offset32 ) ; } while ( result < size && count > 0 ) { ch = source . charAt ( result ) ; if ( isLeadSurrogate ( ch ) && ( ( result + 1 ) < size ) && isTrailSurrogate ( source . charAt ( result + 1 ) ) ) { result ++ ; } count -- ; result ++ ; } if ( count != 0 ) { throw new StringIndexOutOfBoundsException ( offset32 ) ; } return result ; }
Returns the UTF-16 offset that corresponds to a UTF-32 offset. Used for random access. See
the {@link UTF16 class description} for notes on roundtripping.

@param source The UTF-16 string buffer
@param offset32 UTF-32 offset
@return UTF-16 offset
@exception IndexOutOfBoundsException If offset32 is out of bounds.