utf16_offset

Function utf16_offset 

Source
pub fn utf16_offset(text: &str, byte: u32) -> u32
Expand description

A byte offset as a UTF-16 offset from the start of the text.

The flat version of utf16_position, for an editor that works in offsets rather than in lines: a browser’s <textarea> counts its value in UTF-16 code units, so a span the compiler gave in bytes lands in the wrong place the first time somebody writes an emoji in a string. Neither side guesses — the module that has the text does the conversion.