public static void reverse(final char[] buffer,final int start,final int len){
  if (len < 2)   return;
  int end=(start + len) - 1;
  char frontHigh=buffer[start];
  char endLow=buffer[end];
  boolean allowFrontSur=true, allowEndSur=true;
  final int mid=start + (len >> 1);
  for (int i=start; i < mid; ++i, --end) {
    final char frontLow=buffer[i + 1];
    final char endHigh=buffer[end - 1];
    final boolean surAtFront=allowFrontSur && Character.isSurrogatePair(frontHigh,frontLow);
    if (surAtFront && (len < 3)) {
      return;
    }
    final boolean surAtEnd=allowEndSur && Character.isSurrogatePair(endHigh,endLow);
    allowFrontSur=allowEndSur=true;
    if (surAtFront == surAtEnd) {
      if (surAtFront) {
        buffer[end]=frontLow;
        buffer[--end]=frontHigh;
        buffer[i]=endHigh;
        buffer[++i]=endLow;
        frontHigh=buffer[i + 1];
        endLow=buffer[end - 1];
      }
 else {
        buffer[end]=frontHigh;
        buffer[i]=endLow;
        frontHigh=frontLow;
        endLow=endHigh;
      }
    }
 else {
      if (surAtFront) {
        buffer[end]=frontLow;
        buffer[i]=endLow;
        endLow=endHigh;
        allowFrontSur=false;
      }
 else {
        buffer[end]=frontHigh;
        buffer[i]=endHigh;
        frontHigh=frontLow;
        allowEndSur=false;
      }
    }
  }
  if ((len & 0x01) == 1 && !(allowFrontSur && allowEndSur)) {
    buffer[end]=allowFrontSur ? endLow : frontHigh;
  }
}

public static void reverse ( final char [ ] buffer , final int start , final int len ) { if ( len < 2 ) return ; int end = ( start + len ) - 1 ; char frontHigh = buffer [ start ] ; char endLow = buffer [ end ] ; boolean allowFrontSur = true , allowEndSur = true ; final int mid = start + ( len > > 1 ) ; for ( int i = start ; i < mid ; ++ i , -- end ) { final char frontLow = buffer [ i + 1 ] ; final char endHigh = buffer [ end - 1 ] ; final boolean surAtFront = allowFrontSur && Character . isSurrogatePair ( frontHigh , frontLow ) ; if ( surAtFront && ( len < 3 ) ) { return ; } final boolean surAtEnd = allowEndSur && Character . isSurrogatePair ( endHigh , endLow ) ; allowFrontSur = allowEndSur = true ; if ( surAtFront == surAtEnd ) { if ( surAtFront ) { buffer [ end ] = frontLow ; buffer [ -- end ] = frontHigh ; buffer [ i ] = endHigh ; buffer [ ++ i ] = endLow ; frontHigh = buffer [ i + 1 ] ; endLow = buffer [ end - 1 ] ; } else { buffer [ end ] = frontHigh ; buffer [ i ] = endLow ; frontHigh = frontLow ; endLow = endHigh ; } } else { if ( surAtFront ) { buffer [ end ] = frontLow ; buffer [ i ] = endLow ; endLow = endHigh ; allowFrontSur = false ; } else { buffer [ end ] = frontHigh ; buffer [ i ] = endHigh ; frontHigh = frontLow ; allowEndSur = false ; } } } if ( ( len & 0x01 ) == 1 && ! ( allowFrontSur && allowEndSur ) ) { buffer [ end ] = allowFrontSur ? endLow : frontHigh ; } }
partially reverses the given input buffer in - place from the given offset up to the given length , keeping surrogate pairs in the correct ( non - reversed ) order .
