diff options
Diffstat (limited to 'src/parse/scanner.rs')
| -rw-r--r-- | src/parse/scanner.rs | 34 |
1 files changed, 1 insertions, 33 deletions
diff --git a/src/parse/scanner.rs b/src/parse/scanner.rs index 15060c7b..e4cf56e9 100644 --- a/src/parse/scanner.rs +++ b/src/parse/scanner.rs @@ -10,21 +10,13 @@ pub struct Scanner<'s> { /// The index at which the peekable character starts. Must be in bounds and /// at a codepoint boundary to guarantee safety. index: usize, - /// Offsets the indentation on the first line of the source. - column_offset: usize, } impl<'s> Scanner<'s> { /// Create a new char scanner. #[inline] pub fn new(src: &'s str) -> Self { - Self { src, index: 0, column_offset: 0 } - } - - /// Create a new char scanner with an offset for the first line indent. - #[inline] - pub fn with_indent_offset(src: &'s str, column_offset: usize) -> Self { - Self { src, index: 0, column_offset } + Self { src, index: 0 } } /// Whether the end of the string is reached. @@ -177,30 +169,6 @@ impl<'s> Scanner<'s> { // optimized away in some cases. self.src.get(start .. self.index).unwrap_or_default() } - - /// The column index of a given index in the source string. - #[inline] - pub fn column(&self, index: usize) -> usize { - let mut apply_offset = false; - let res = self.src[.. index] - .char_indices() - .rev() - .take_while(|&(_, c)| !is_newline(c)) - .inspect(|&(i, _)| { - if i == 0 { - apply_offset = true - } - }) - .count(); - - // The loop is never executed if the slice is empty, but we are of - // course still at the start of the first line. - if self.src[.. index].len() == 0 { - apply_offset = true; - } - - if apply_offset { res + self.column_offset } else { res } - } } /// Whether this character denotes a newline. |
