Allow escaped quotation marks in BLT parser

This commit is contained in:
RunasSudo 2022-11-20 18:57:30 +11:00
parent d068ce6137
commit f7f9727146
No known key found for this signature in database
GPG Key ID: 7234E476BF21C61A
1 changed files with 19 additions and 1 deletions

View File

@ -255,9 +255,27 @@ impl<N: Number, I: Iterator<Item=char>> BLTParser<N, I> {
if self.lookahead() == '"' { if self.lookahead() == '"' {
self.accept(); // Opening quotation mark self.accept(); // Opening quotation mark
let mut result = String::new(); let mut result = String::new();
loop {
// Read string contents
if self.lookahead() == '"' {
break;
} else if self.lookahead() == '\\' {
// Escape sequence
self.accept();
if self.lookahead() == '"' || self.lookahead() == '\\' {
result.push(self.accept());
} else {
return Err(ParseError::Unexpected(self.line_no, self.col_no, self.lookahead()));
}
} else {
result.push(self.accept());
}
}
while self.lookahead() != '"' { while self.lookahead() != '"' {
// TODO: BufRead::read_until ? // TODO: BufRead::read_until ?
result.push(self.accept());
} }
self.accept(); // Closing quotation mark self.accept(); // Closing quotation mark
if !self.eof() { if !self.eof() {