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 remaining = start + first.len_utf8();
let mut end = remaining;
let mut escaped = false;
let mut chars = self.input[end..].chars();
while let Some(c) = chars.next() {
end += c.len_utf8();
if escaped {
escaped = false;
continue;
}
if c == '\\' {
escaped = true;
continue;
}
if c == '"' {
break;
}
}
let end = self.input[remaining..]
.char_indices()
.find(|&(_, c)| match (escaped, c) {
(true, _) => {
escaped = false;
false
}
(false, '\\') => {
escaped = true;
false
}
(false, '"') => true,
(false, _) => false,
})
.map(|(idx, c)| remaining + idx + c.len_utf8())
.unwrap_or(self.input.len());
Some(&self.input[start..end])
}