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


##########
src/tokenizer.rs:
##########
@@ -2176,35 +2206,82 @@ impl<'a> Tokenizer<'a> {
 /// Read from `chars` until `predicate` returns `false` or EOF is hit.
 /// Return the characters read as String, and keep the first non-matching
 /// char available as `chars.next()`.
-fn peeking_take_while(chars: &mut State, mut predicate: impl FnMut(char) -> 
bool) -> String {
-    let mut s = String::new();
+fn peeking_take_while(chars: &mut State, predicate: impl FnMut(char) -> bool) 
-> String {
+    borrow_slice_until(chars, predicate).to_string()
+}
+
+/// Borrow a slice from the original string until `predicate` returns `false` 
or EOF is hit.
+///
+/// # Arguments
+/// * `chars` - The character iterator state (contains reference to original 
source)
+/// * `predicate` - Function that returns true while we should continue taking 
characters
+///
+/// # Returns
+/// A borrowed slice of the source string containing the matched characters
+fn borrow_slice_until<'a>(
+    chars: &mut State<'a>,
+    mut predicate: impl FnMut(char) -> bool,
+) -> &'a str {
+    // Record the starting byte position

Review Comment:
   > and the iterator is incremented according to the characters in the buffer
   
   Yeah I think this is the part that we don't necessarily have a guarantee on, 
hence the sanity check part if we have a bug somewhere or make wrong assumption 
etc



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to