Functional string parser.

This commit is contained in:
2026-11-10 08:46:30 +01:00
parent 19181e0182
commit 6269aaf981
+16 -17
View File
@@ -139,24 +139,23 @@ impl<'a> Lexer<'a> {
let start = self.cursor.pos; let start = self.cursor.pos;
let remaining = start + first.len_utf8(); let remaining = start + first.len_utf8();
let mut end = remaining;
let mut escaped = false; let mut escaped = false;
let end = self.input[remaining..]
let mut chars = self.input[end..].chars(); .char_indices()
while let Some(c) = chars.next() { .find(|&(_, c)| match (escaped, c) {
end += c.len_utf8(); (true, _) => {
if escaped { escaped = false;
escaped = false; false
continue; }
} (false, '\\') => {
if c == '\\' { escaped = true;
escaped = true; false
continue; }
} (false, '"') => true,
if c == '"' { (false, _) => false,
break; })
} .map(|(idx, c)| remaining + idx + c.len_utf8())
} .unwrap_or(self.input.len());
Some(&self.input[start..end]) Some(&self.input[start..end])
} }