Functional string parser.
This commit is contained in:
+12
-13
@@ -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 {
|
||||
let end = self.input[remaining..]
|
||||
.char_indices()
|
||||
.find(|&(_, c)| match (escaped, c) {
|
||||
(true, _) => {
|
||||
escaped = false;
|
||||
continue;
|
||||
false
|
||||
}
|
||||
if c == '\\' {
|
||||
(false, '\\') => {
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
if c == '"' {
|
||||
break;
|
||||
}
|
||||
false
|
||||
}
|
||||
(false, '"') => true,
|
||||
(false, _) => false,
|
||||
})
|
||||
.map(|(idx, c)| remaining + idx + c.len_utf8())
|
||||
.unwrap_or(self.input.len());
|
||||
|
||||
Some(&self.input[start..end])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user