From b3693bfa63f14dff5e4c60485e85f06d37a7fb14 Mon Sep 17 00:00:00 2001 From: Nickolay Ponomarev Date: Thu, 31 Jan 2019 13:11:17 +0300 Subject: [PATCH] Simplify quoted identifier tokenization --- src/sqltokenizer.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/sqltokenizer.rs b/src/sqltokenizer.rs index 0095e505..f8e7ef8f 100644 --- a/src/sqltokenizer.rs +++ b/src/sqltokenizer.rs @@ -290,23 +290,17 @@ impl<'a> Tokenizer<'a> { } Ok(Some(Token::SingleQuotedString(s))) } - // string + // delimited (quoted) identifier '"' => { let mut s = String::new(); - chars.next(); // consume - while let Some(&ch) = chars.peek() { + let quote_start = chars.next().unwrap(); // consumes the opening quote + while let Some(ch) = chars.next() { match ch { - '"' => { - chars.next(); // consume - break; - } - _ => { - chars.next(); // consume - s.push(ch); - } + '"' => break, + _ => s.push(ch), } } - Ok(Some(Token::make_word(&s, Some('"')))) + Ok(Some(Token::make_word(&s, Some(quote_start)))) } // numbers '0'...'9' => {