iffyio commented on code in PR #1650:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1650#discussion_r1910623511


##########
src/tokenizer.rs:
##########
@@ -1554,46 +1554,29 @@ impl<'a> Tokenizer<'a> {
             if matches!(chars.peek(), Some('$')) && 
!self.dialect.supports_dollar_placeholder() {
                 chars.next();
 
-                'searching_for_end: loop {
-                    s.push_str(&peeking_take_while(chars, |ch| ch != '$'));
-                    match chars.peek() {
-                        Some('$') => {
-                            chars.next();
-                            let mut maybe_s = String::from("$");
-                            for c in value.chars() {
-                                if let Some(next_char) = chars.next() {
-                                    maybe_s.push(next_char);
-                                    if next_char != c {
-                                        // This doesn't match the dollar quote 
delimiter so this
-                                        // is not the end of the string.
-                                        s.push_str(&maybe_s);
-                                        continue 'searching_for_end;
-                                    }
-                                } else {
-                                    return self.tokenizer_error(
-                                        chars.location(),
-                                        "Unterminated dollar-quoted, expected 
$",
-                                    );
-                                }
-                            }
-                            if chars.peek() == Some(&'$') {
-                                chars.next();
-                                maybe_s.push('$');
-                                // maybe_s matches the end delimiter
-                                break 'searching_for_end;
-                            } else {
-                                // This also doesn't match the dollar quote 
delimiter as there are
-                                // more characters before the second dollar so 
this is not the end
-                                // of the string.
-                                s.push_str(&maybe_s);
-                                continue 'searching_for_end;
+                let mut temp = String::new();
+                let end_delimiter = format!("${}$", value);
+
+                loop {
+                    match chars.next() {
+                        Some(ch) => {
+                            temp.push(ch);
+
+                            if temp.ends_with(&end_delimiter) {
+                                s.push_str(&temp[..temp.len() - 
end_delimiter.len()]);

Review Comment:
   ah I think indexing based on `String::len` won't necessarily produce correct 
results on arbitrary UTF8 strings, we could something like `strip_suffix` that 
doesn't rely on the byte count? e.g
   ```rust
   if let Some(temp) = temp.strip_suffix(&end_delimiter) {
       s.push_str(temp);
       break
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to