continuation_bytes_location

Function continuation_bytes_location 

Source
pub fn continuation_bytes_location<'g>(
    ptr: *const u8,
    length: usize,
    index: usize,
) -> Option<(usize, ByteType)>
Expand description

returns the byte count until the end of that sequence the ByteType corresponding to the first byte pointed at by index when called with index that points to a sequence of bytes equivalent to either U+200D or U+FE0F.

ยงExample

use utf8_rune::continuation_bytes_location;

let bytes = "๐Ÿ‘ฉ๐Ÿปโ€๐Ÿš’".as_bytes();
let index = 8;
let length = bytes.len();
let ptr = bytes.as_ptr();
let (count, ty) = continuation_bytes_location(ptr, length, index).unwrap();
assert_eq!(count, 7);
assert_eq!(&bytes[index..(index+count)], &[0xE2, 0x80, 0x8D, 0xF0, 0x9F, 0x9A, 0x92]);
assert_eq!(std::str::from_utf8(&bytes[index..(index+count)]), Ok("\u{200d}๐Ÿš’"));
use utf8_rune::continuation_bytes_location;

let bytes = "โค๏ธโ€๐Ÿ”ฅ".as_bytes();
let index = 3;
let length = bytes.len();
let ptr = bytes.as_ptr();
let (count, ty) = continuation_bytes_location(ptr, length, index).unwrap();
assert_eq!(count, 10);
assert_eq!(&bytes[index..(index+count)], &[0xEF, 0xB8, 0x8F, 0xE2, 0x80, 0x8D,
    0xF0, 0x9F, 0x94, 0xA5
]);
assert_eq!(std::str::from_utf8(&bytes[index..(index+count)]), Ok("\u{fe0f}\u{200d}๐Ÿ”ฅ"));