refactor(specctra/read): put read_quoted into a separate function again

This commit is contained in:
Alain Emilia Anna Zscheile 2024-12-02 22:44:46 +01:00
parent e493c16053
commit 5aae676fb8
1 changed files with 23 additions and 16 deletions

View File

@ -254,24 +254,31 @@ impl<R: std::io::BufRead> ListTokenizer<R> {
} }
fn read_string(&mut self) -> Result<String, ParseErrorContext> { fn read_string(&mut self) -> Result<String, ParseErrorContext> {
fn read_quoted<R: std::io::BufRead>(
this: &mut ListTokenizer<R>,
quote_chr: char,
) -> Result<String, ParseErrorContext> {
let mut string = String::new();
this.reset_char();
loop {
let ctx = this.context();
let chr = this.next_char()?;
if chr == ' ' && !this.space_in_quoted {
return Err(ParseError::UnexpectedSpaceInQuotedStr.add_context(ctx));
} else if chr == quote_chr {
break;
} else {
string.push(chr);
}
}
Ok(string)
}
if let Some(quote_chr) = self.quote_char { if let Some(quote_chr) = self.quote_char {
if quote_chr == self.peek_char()? { if quote_chr == self.peek_char()? {
let mut string = String::new(); return read_quoted(self, quote_chr);
self.reset_char();
loop {
let ctx = self.context();
let chr = self.next_char()?;
if chr == ' ' && !self.space_in_quoted {
return Err(ParseError::UnexpectedSpaceInQuotedStr.add_context(ctx));
} else if chr == quote_chr {
break;
} else {
string.push(chr);
}
}
return Ok(string);
} }
} }
self.read_unquoted() self.read_unquoted()