The OpenD Programming Language

strideBack

Calculate the length of the UTF sequence ending one code unit before index in str.

Parameters

str S

bidirectional range of UTF code units. Must be random access if index is passed

index size_t

index one past end of UTF sequence (default: str.length)

Return Value

Type: uint

The number of code units in the UTF sequence. For UTF-8, this is a value between 1 and 4 (as per RFC 3629, section 3). For UTF-16, it is either 1 or 2. For UTF-32, it is always 1.

Throws

May throw a UTFException if str[index] is not one past the end of a valid UTF sequence.

Note: strideBack will only analyze the element at str[index - 1] element. It will not fully verify the validity of the UTF sequence, nor even verify the presence of the sequence: it will not actually guarantee that strideBack(str, index) <= index.

Examples

assert("a".strideBack == 1);
assert("λ".strideBack == 2);
assert("aλ".strideBack == 2);
assert("aλ".strideBack(1) == 1);
assert("𐐷".strideBack == 4);

Meta