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 .