From 49fb3cd4e2a5d6997ad4046d3514f154d8c866dd Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Mon, 1 Nov 2021 13:03:18 +0100 Subject: Code Review: Life is Like a Box of Iterators --- src/parse/scanner.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/parse/scanner.rs') 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) { -- cgit v1.2.3