pub struct Cursor { /* private fields */ }Expand description
A raw-pointer scan cursor over a NUL-terminated source buffer.
Implementations§
Source§impl Cursor
impl Cursor
Sourcepub fn new(buffer: Rc<SourceBuffer>) -> Cursor
pub fn new(buffer: Rc<SourceBuffer>) -> Cursor
Create a cursor positioned at the start of buffer.
Sourcepub fn peek_at(&self, n: usize) -> u8
pub fn peek_at(&self, n: usize) -> u8
Byte n ahead of the cursor. Only valid while the bytes in between were
non-NUL (the C++ lookahead invariant); reading the terminating NUL is
always in-bounds.
Sourcepub fn slice_from(&self, from_offset: u32) -> &[u8] ⓘ
pub fn slice_from(&self, from_offset: u32) -> &[u8] ⓘ
Bytes in [from_offset, current offset).
Sourcepub fn slice(&self, from_offset: u32, to_offset: u32) -> &[u8] ⓘ
pub fn slice(&self, from_offset: u32, to_offset: u32) -> &[u8] ⓘ
Bytes in [from_offset, to_offset).
Sourcepub fn peek_utf8(&self) -> (u32, u32)
pub fn peek_utf8(&self) -> (u32, u32)
Decode the (non-ASCII) UTF-8 char at the cursor WITHOUT advancing.
Port of JSLexer::_peekUTF8 (JSLexer.h:1159-1167): it decodes with
surrogates disallowed and swallows any errors. Returns
(code_point, offset_after), where offset_after is the byte offset of
the next character.
This stays in cursor.rs to keep the raw-pointer parity confined here,
but it actually drives the safe utf8::decode_utf8 over raw() at a
copied byte offset (no new unsafe).
Sourcepub fn buffer(&self) -> &Rc<SourceBuffer>
pub fn buffer(&self) -> &Rc<SourceBuffer>
The underlying buffer (cloning the Rc is cheap).