strideBack

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

  1. uint strideBack(S str, size_t index)
  2. uint strideBack(S str)
    uint
    strideBack
    (
    S
    )
    (
    auto ref S str
    )
    if (
    is(S : const char[]) ||
    (
    isRandomAccessRange!S &&
    hasLength!S
    &&
    is(immutable ElementType!S == immutable char)
    )
    )
  3. uint strideBack(S str)
  4. uint strideBack(S str, size_t index)
  5. uint strideBack(S str)
  6. uint strideBack(S str, size_t index)
  7. uint strideBack(S str)

Parameters

str S

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

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