diff options
| author | Martin Haug <mhaug@live.de> | 2021-11-01 13:03:18 +0100 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2021-11-05 13:44:50 +0100 |
| commit | 49fb3cd4e2a5d6997ad4046d3514f154d8c866dd (patch) | |
| tree | 4fb2a245a4cb84a6ef238ac1bc71786a0996913d /src/parse/scanner.rs | |
| parent | 7d34a548ccd14debe0668e23454e1ced70e485ec (diff) | |
Code Review: Life is Like a Box of Iterators
Diffstat (limited to 'src/parse/scanner.rs')
| -rw-r--r-- | src/parse/scanner.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/parse/scanner.rs b/src/parse/scanner.rs index 8e3e4278..edf28e17 100644 --- a/src/parse/scanner.rs +++ b/src/parse/scanner.rs @@ -106,6 +106,16 @@ impl<'s> Scanner<'s> { self.index } + /// The column index of a given index in the source string. + #[inline] + pub fn column(&self, index: usize) -> usize { + self.src[.. index] + .chars() + .rev() + .take_while(|&c| !is_newline(c)) + .count() + } + /// Jump to an index in the source string. #[inline] pub fn jump(&mut self, index: usize) { |
