Skip to main content

char_at

Function char_at 

Source
fn char_at(text: &str, i: usize) -> char
Expand description

The character at byte offset i of text. i must be a char boundary (every offset scan advances to is one, by construction).

This exists because text.as_bytes()[i] as char — the shape this scanner used to have, and the same bug once present in core_model::parser::tokenize — casts a single BYTE, which is wrong for any multi-byte UTF-8 sequence and walks the cursor onto a non-boundary offset, panicking on the eventual &text[start..i] slice.