public static int moveCodePointOffset(char source[], int start, int limit, int offset16,
            int shift32) {
        int size = source.length;
        int count;
        char ch;
        int result = offset16 + start;
        if (start < 0 || limit < start) {
            throw new StringIndexOutOfBoundsException(start);
        }
        if (limit > size) {
            throw new StringIndexOutOfBoundsException(limit);
        }
        if (offset16 < 0 || result > limit) {
            throw new StringIndexOutOfBoundsException(offset16);
        }
        if (shift32 > 0) {
            if (shift32 + result > size) {
                throw new StringIndexOutOfBoundsException(result);
            }
            count = shift32;
            while (result < limit && count > 0) {
                ch = source[result];
                if (isLeadSurrogate(ch) && (result + 1 < limit)
                        && isTrailSurrogate(source[result + 1])) {
                    result++;
                }
                count--;
                result++;
            }
        } else {
            if (result + shift32 < start) {
                throw new StringIndexOutOfBoundsException(result);
            }
            for (count = -shift32; count > 0; count--) {
                result--;
                if (result < start) {
                    break;
                }
                ch = source[result];
                if (isTrailSurrogate(ch) && result > start && isLeadSurrogate(source[result - 1])) {
                    result--;
                }
            }
        }
        if (count != 0) {
            throw new StringIndexOutOfBoundsException(shift32);
        }
        result -= start;
        return result;
    }
public static int moveCodePointOffset ( char source [ ] , int start , int limit , int offset16 , int shift32 ) { int size = source . length ; int count ; char ch ; int result = offset16 + start ; if ( start < 0 || limit < start ) { throw new StringIndexOutOfBoundsException ( start ) ; } if ( limit > size ) { throw new StringIndexOutOfBoundsException ( limit ) ; } if ( offset16 < 0 || result > limit ) { throw new StringIndexOutOfBoundsException ( offset16 ) ; } if ( shift32 > 0 ) { if ( shift32 + result > size ) { throw new StringIndexOutOfBoundsException ( result ) ; } count = shift32 ; while ( result < limit && count > 0 ) { ch = source [ result ] ; if ( isLeadSurrogate ( ch ) && ( result + 1 < limit ) && isTrailSurrogate ( source [ result + 1 ] ) ) { result ++ ; } count -- ; result ++ ; } } else { if ( result + shift32 < start ) { throw new StringIndexOutOfBoundsException ( result ) ; } for ( count = - shift32 ; count > 0 ; count -- ) { result -- ; if ( result < start ) { break ; } ch = source [ result ] ; if ( isTrailSurrogate ( ch ) && result > start && isLeadSurrogate ( source [ result - 1 ] ) ) { result -- ; } } } if ( count != 0 ) { throw new StringIndexOutOfBoundsException ( shift32 ) ; } result -= start ; return result ; }
Shifts offset16 by the argument number of codepoints within a subarray.

@param source Char array
@param start Position of the subarray to be performed on
@param limit Position of the subarray to be performed on
@param offset16 UTF16 position to shift relative to start
@param shift32 Number of codepoints to shift
@return new shifted offset16 relative to start
@exception IndexOutOfBoundsException If the new offset16 is out of bounds with respect to the subarray or the
subarray bounds are out of range.