pub struct Utf16OffsetConverter { /* private fields */ }Expand description
UTF-8 byte offset to UTF-16 code unit offset converter
CodeMirror 6 uses absolute UTF-16 code unit offsets for positions. This converter provides O(1) lookups after O(n) preprocessing.
Implementations§
Source§impl Utf16OffsetConverter
impl Utf16OffsetConverter
Sourcepub fn new(input: &str) -> Self
pub fn new(input: &str) -> Self
Creates a new converter with O(n) preprocessing
Builds a lookup table mapping each byte position to its corresponding UTF-16 code unit position.
Sourcepub fn convert(&self, byte_offset: usize) -> u32
pub fn convert(&self, byte_offset: usize) -> u32
Converts a byte offset to UTF-16 code unit offset in O(1)
Sourcepub fn convert_span(&self, span: &Span) -> Utf16Position
pub fn convert_span(&self, span: &Span) -> Utf16Position
Converts a Span to UTF-16 position
Sourcepub fn convert_elements(&self, elements: &[Element]) -> Value
pub fn convert_elements(&self, elements: &[Element]) -> Value
Converts SevenMark AST elements to JSON with UTF-16 positions
Auto Trait Implementations§
impl Freeze for Utf16OffsetConverter
impl RefUnwindSafe for Utf16OffsetConverter
impl Send for Utf16OffsetConverter
impl Sync for Utf16OffsetConverter
impl Unpin for Utf16OffsetConverter
impl UnwindSafe for Utf16OffsetConverter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more