public void addReplace(int oldLength, int newLength) {
        if(oldLength == newLength && 0 < oldLength && oldLength <= MAX_SHORT_WIDTH) {
            // Replacement of short oldLength text units by same-length new text.
            // Merge into previous short-replacement record, if any.
            int last = lastUnit();
            if(MAX_UNCHANGED < last && last < MAX_SHORT_CHANGE &&
                    (last >> 12) == oldLength && (last & 0xfff) < MAX_SHORT_CHANGE_LENGTH) {
                setLastUnit(last + 1);
                return;
            }
            append(oldLength << 12);
            return;
        }

        if(oldLength < 0 || newLength < 0) {
            throw new IllegalArgumentException(
                    "addReplace(" + oldLength + ", " + newLength +
                    "): both lengths must be non-negative");
        }
        if (oldLength == 0 && newLength == 0) {
            return;
        }
        int newDelta = newLength - oldLength;
        if (newDelta != 0) {
            if ((newDelta > 0 && delta >= 0 && newDelta > (Integer.MAX_VALUE - delta)) ||
                    (newDelta < 0 && delta < 0 && newDelta < (Integer.MIN_VALUE - delta))) {
                // Integer overflow or underflow.
                throw new IndexOutOfBoundsException();
            }
            delta += newDelta;
        }

        int head = 0x7000;
        if (oldLength < LENGTH_IN_1TRAIL && newLength < LENGTH_IN_1TRAIL) {
            head |= oldLength << 6;
            head |= newLength;
            append(head);
        } else if ((array.length - length) >= 5 || growArray()) {
            int limit = length + 1;
            if(oldLength < LENGTH_IN_1TRAIL) {
                head |= oldLength << 6;
            } else if(oldLength <= 0x7fff) {
                head |= LENGTH_IN_1TRAIL << 6;
                array[limit++] = (char)(0x8000 | oldLength);
            } else {
                head |= (LENGTH_IN_2TRAIL + (oldLength >> 30)) << 6;
                array[limit++] = (char)(0x8000 | (oldLength >> 15));
                array[limit++] = (char)(0x8000 | oldLength);
            }
            if(newLength < LENGTH_IN_1TRAIL) {
                head |= newLength;
            } else if(newLength <= 0x7fff) {
                head |= LENGTH_IN_1TRAIL;
                array[limit++] = (char)(0x8000 | newLength);
            } else {
                head |= LENGTH_IN_2TRAIL + (newLength >> 30);
                array[limit++] = (char)(0x8000 | (newLength >> 15));
                array[limit++] = (char)(0x8000 | newLength);
            }
            array[length] = (char)head;
            length = limit;
        }
    }
public void addReplace ( int oldLength , int newLength ) { if ( oldLength == newLength && 0 < oldLength && oldLength <= MAX_SHORT_WIDTH ) { int last = lastUnit ( ) ; if ( MAX_UNCHANGED < last && last < MAX_SHORT_CHANGE && ( last > > 12 ) == oldLength && ( last & 0xfff ) < MAX_SHORT_CHANGE_LENGTH ) { setLastUnit ( last + 1 ) ; return ; } append ( oldLength << 12 ) ; return ; } if ( oldLength < 0 || newLength < 0 ) { throw new IllegalArgumentException ( "addReplace(" + oldLength + ", " + newLength + "): both lengths must be non-negative" ) ; } if ( oldLength == 0 && newLength == 0 ) { return ; } int newDelta = newLength - oldLength ; if ( newDelta != 0 ) { if ( ( newDelta > 0 && delta >= 0 && newDelta > ( Integer . MAX_VALUE - delta ) ) || ( newDelta < 0 && delta < 0 && newDelta < ( Integer . MIN_VALUE - delta ) ) ) { throw new IndexOutOfBoundsException ( ) ; } delta += newDelta ; } int head = 0x7000 ; if ( oldLength < LENGTH_IN_1TRAIL && newLength < LENGTH_IN_1TRAIL ) { head |= oldLength << 6 ; head |= newLength ; append ( head ) ; } else if ( ( array . length - length ) >= 5 || growArray ( ) ) { int limit = length + 1 ; if ( oldLength < LENGTH_IN_1TRAIL ) { head |= oldLength << 6 ; } else if ( oldLength <= 0x7fff ) { head |= LENGTH_IN_1TRAIL << 6 ; array [ limit ++ ] = ( char ) ( 0x8000 | oldLength ) ; } else { head |= ( LENGTH_IN_2TRAIL + ( oldLength > > 30 ) ) << 6 ; array [ limit ++ ] = ( char ) ( 0x8000 | ( oldLength > > 15 ) ) ; array [ limit ++ ] = ( char ) ( 0x8000 | oldLength ) ; } if ( newLength < LENGTH_IN_1TRAIL ) { head |= newLength ; } else if ( newLength <= 0x7fff ) { head |= LENGTH_IN_1TRAIL ; array [ limit ++ ] = ( char ) ( 0x8000 | newLength ) ; } else { head |= LENGTH_IN_2TRAIL + ( newLength > > 30 ) ; array [ limit ++ ] = ( char ) ( 0x8000 | ( newLength > > 15 ) ) ; array [ limit ++ ] = ( char ) ( 0x8000 | newLength ) ; } array [ length ] = ( char ) head ; length = limit ; } }
Adds a record for a text replacement/insertion/deletion.
Normally called from inside ICU string transformation functions, not user code.
@hide draft / provisional / internal are hidden on Android