From 288350daef1fab103d5fcace283059f2a32c5988 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 28 Aug 2023 03:15:53 -0400 Subject: [PATCH] Iterate over the bytes instead of characters when counting brackets. --- src/parser/org_source.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/parser/org_source.rs b/src/parser/org_source.rs index a9f479f..9f4c35e 100644 --- a/src/parser/org_source.rs +++ b/src/parser/org_source.rs @@ -19,8 +19,8 @@ pub struct OrgSource<'s> { start_of_line: usize, preceding_character: Option, line_number: usize, - bracket_depth: isize, // [] - brace_depth: isize, // {} + bracket_depth: isize, // [] + brace_depth: isize, // {} parenthesis_depth: isize, // () } @@ -148,28 +148,28 @@ where let mut bracket_depth = self.bracket_depth; let mut brace_depth = self.brace_depth; let mut parenthesis_depth = self.parenthesis_depth; - for (offset, character) in skipped_text.char_indices() { - match character { - '\n' => { + for (offset, byte) in skipped_text.bytes().enumerate() { + match byte { + b'\n' => { start_of_line = self.start + offset + 1; line_number += 1; } - '[' => { + b'[' => { bracket_depth += 1; } - ']' => { + b']' => { bracket_depth -= 1; } - '{' => { + b'{' => { brace_depth += 1; } - '}' => { + b'}' => { brace_depth -= 1; } - '(' => { + b'(' => { parenthesis_depth += 1; } - ')' => { + b')' => { parenthesis_depth -= 1; } _ => {}