simple-cursor
A super simple #[no_std]
-compatible character cursor implementation geared towards lexers/tokenizers. The implementation is inspired by the one used in rustc
and should be performant enough to handle pretty much anything you could throw at it.
The following examples showcases the basic features of simple_cursor
. Please refer to the Cursor
docs for more info.
```rust use simple_cursor::Cursor;
// Create the input string and the cursor. let input = "123 foobar竜"; let mut cursor = Cursor::new(input);
// "123" let numberstart = cursor.bytepos(); cursor.skipwhile(|c| c.isasciidigit()); let numberend = cursor.byte_pos();
// Some(' ') let whitespace = cursor.bump();
// "foobar" let identstart = cursor.bytepos(); cursor.skipwhile(|c| c.isasciialphabetic()); let identend = cursor.byte_pos();
// "竜" let reststart = identend; let rest_end = input.len();
asserteq!("123", &input[numberstart..numberend]); asserteq!(Some(' '), whitespace); asserteq!("foobar", &input[identstart..identend]); asserteq!("竜", &input[reststart..restend]); ```