length_of_last_scalar

Function length_of_last_scalar 

Source
pub open spec fn length_of_last_scalar(bytes: Seq<u8>) -> int
Expand description
recommends
valid_utf8(bytes),
bytes.len() > 0,
{
    let n = bytes.len() as int;
    if !is_continuation_byte(bytes[n - 1]) {
        1
    } else if !is_continuation_byte(bytes[n - 2]) {
        2
    } else if !is_continuation_byte(bytes[n - 3]) {
        3
    } else {
        4
    }
}

The length in bytes of the last scalar encoded in UTF-8 in the given byte sequence, assuming that the bytes form a valid UTF-8 encoding.