compress

fun compress(src: CharArray, off: Int, count: Int): ByteArray

{@return Compress the char array (containing UTF16) into a compact strings byte array} If all the chars are LATIN1, it returns an array with len == count, otherwise, it contains UTF16 characters.

A UTF16 array is returned only if at least 1 non-latin1 character is present. This must be true even if the input array is modified while this method is executing. This is assured by copying the characters while checking for latin1. If all characters are latin1, a byte array with length equals count is returned, indicating all latin1 chars. The scan may be implemented as an intrinsic, which returns the index of the first non-latin1 character. When the first non-latin1 character is found, it switches to creating a new buffer; the saved prefix of latin1 characters is copied to the new buffer; and the remaining input characters are copied to the buffer. The index of the known non-latin1 character is checked, if it is latin1, the input has been changed. In this case, a second attempt is made to compress to latin1 from the copy made in the first pass to the originally allocated latin1 buffer. If it succeeds the return value is latin1, otherwise, the utf16 value is returned. In this unusual case, the result is correct for the snapshot of the value. The resulting string contents are unspecified if the input array is modified during this operation, but it is ensured that at least 1 non-latin1 character is present in the non-latin1 buffer.

Parameters

src

a char array

off

starting offset

count

count of chars to be compressed, count> 0


fun compress(val: ByteArray, off: Int, count: Int): ByteArray

{@return Compress the internal byte array (containing UTF16) into a compact strings byte array} If all the chars are LATIN1, it returns an array with len == count, otherwise, it contains UTF16 characters.

Refer to the description of the algorithm in .compress.

Parameters

val

a byte array with UTF16 coding

off

starting offset

count

count of chars to be compressed, count> 0


fun compress(src: ByteArray, srcOff: Int, dst: ByteArray, dstOff: Int, len: Int): Int