jsonist/tokenizer/
indexed_characters.rs1#[derive(Copy, Clone, Debug)]
2pub struct IndexedCharacters<'a> {
3 characters: &'a Vec<char>,
4 index: usize,
5}
6
7impl<'a> IndexedCharacters<'a> {
8 pub fn new(characters: &'a Vec<char>) -> IndexedCharacters<'a> {
9 IndexedCharacters {
10 characters,
11 index: 0,
12 }
13 }
14
15 pub fn progress(&self) -> IndexedCharacters<'a> {
16 self.jump(1)
17 }
18
19 pub fn previous_character(self) -> Option<&'a char> {
20 self.characters.get(self.index - 1)
21 }
22
23 pub fn current_character(self) -> Option<&'a char> {
24 self.characters.get(self.index)
25 }
26
27 pub fn get_index(self) -> usize {
28 self.index
29 }
30
31 pub fn jump(&self, jump: usize) -> IndexedCharacters<'a> {
32 IndexedCharacters {
33 characters: &self.characters,
34 index: self.index + jump,
35 }
36 }
37}