mutf8Length

@JvmName(name = "of")
fun CharSequence.mutf8Length(startIndex: Int = 0, endIndex: Int = length): Long(source)

The summed mutf8Length for the characters in a subsequence of this one.

If that sum exceeds 65535, or UShort.MAX_VALUE, then it will still be returned, but note that the selected range is too long to encode as a single Modified UTF-8 sequence; it must be split up, compressed, or encoded differently.

Assuming the startIndex and endIndex form a valid range in a sequence, charSequence, then this will yield the same sum as:

charSequence.subSequence(startIndex, endIndex).mutf8Length

This can be used from Java sources as follows:

import me.nullicorn.mewteaf8.Mutf8Length;
/* ... */
Mutf8Length.of(charSequence, startIndex, endIndex)

Receiver

The characters to determine the collective length of, in bytes.

Return

the number of bytes needed to represent the range of characters as a Modified UTF-8 sequence.

Parameters

startIndex

The index in the sequence to start counting from.

If the sequence is empty, this must be 0. Otherwise, it should be a valid index in the sequence, such that it appears in the sequence's indices. This can never be less than 0.

endIndex

The index in the sequence to stop counting at.

This cannot exceed the length of the sequence, and cannot be less than the startIndex.

Throws


@JvmName(name = "of")
fun CharArray.mutf8Length(startIndex: Int = 0, endIndex: Int = size): Long(source)

The summed mutf8Length for the characters in a subsection of this array.

The contract of this method is identical to that of CharSequence.mutf8Length, except...

All parameters, exceptions, constraints, and notes from CharSequence.mutf8Length apply to this function as well.

This can be used from Java sources as follows:

import me.nullicorn.mewteaf8.Mutf8Length;
/* ... */
Mutf8Length.of(charArray, startIndex, endIndex)

See also


@get:JvmName(name = "of")
val Char.mutf8Length: Int(source)

The number of bytes used to encode the character in a Modified UTF-8 sequence.

  • For characters in the range '\u0001' .. '\u007F', this is 1

  • For characters in the range '\u0080' .. '\u07FF', this is 2

  • For characters in the range '\u0800' .. '\uFFFF', this is 3

  • For the character '\u0000', this is 2

That list covers the entire range of a Char, so there are no other values to note.

This can be used from Java sources as follows:

import me.nullicorn.mewteaf8.Mutf8Length;
/* ... */
Mutf8Length.of(char)

Receiver

The character to check the Modified UTF-8 length of.


@get:JvmName(name = "of")
val CharSequence.mutf8Length: Long(source)

The summed mutf8Length for all the characters in the sequence.

This is an alias for CharSequence.mutf8Length with startIndex = 0 and endIndex = length. The selected indices are guaranteed to be valid, so all IllegalArgumentExceptions documented at CharSequence.mutf8Length are guaranteed not to occur unless also documented on this property. Other than that, the contract & documentation for CharSequence.mutf8Length applies here as well.

This can be used from Java sources as follows:

import me.nullicorn.mewteaf8.Mutf8Length;
/* ... */
Mutf8Length.of(charSequence)

See also

Throws

if the length of the CharSequence is a negative number.


@get:JvmName(name = "of")
val CharArray.mutf8Length: Long(source)

The summed mutf8Length for all the characters in the array.

This is an alias for CharArray.mutf8Length with startIndex = 0 and endIndex = size. The selected indices are guaranteed to be valid, so all IllegalArgumentExceptions documented at CharArray.mutf8Length are guaranteed not to occur. Other than that, the contract & documentation for CharArray.mutf8Length applies here as well.

This can be used from Java sources as follows:

import me.nullicorn.mewteaf8.Mutf8Length;
/* ... */
Mutf8Length.of(charArray)

See also