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