fn find_unclosed_quote(s: &str) -> Option<(usize, Quote)> {
    let char_indices = s.char_indices();
    let mut mode = ScanMode::Normal;
    let mut quote_index = 0;
    for (index, char) in char_indices {
        match mode {
            ScanMode::DoubleQuote => {
                if char == '"' {
                    mode = ScanMode::Normal;
                } else if char == '\\' {
                    mode = ScanMode::EscapeInDoubleQuote;
                }
            }
            ScanMode::Escape => {
                mode = ScanMode::Normal;
            }
            ScanMode::EscapeInDoubleQuote => {
                mode = ScanMode::DoubleQuote;
            }
            ScanMode::Normal => {
                if char == '"' {
                    mode = ScanMode::DoubleQuote;
                    quote_index = index;
                } else if char == '\\' {
                    mode = ScanMode::Escape;
                } else if char == '\'' {
                    mode = ScanMode::SingleQuote;
                    quote_index = index;
                }
            }
            ScanMode::SingleQuote => {
                if char == '\'' {
                    mode = ScanMode::Normal;
                } // no escape in single quotes
            }
        };
    }
    if ScanMode::DoubleQuote == mode || ScanMode::EscapeInDoubleQuote == mode {
        return Some((quote_index, Quote::Double));
    } else if ScanMode::SingleQuote == mode {
        return Some((quote_index, Quote::Single));
    }
    None
}
/// try to find an unclosed single/double quote in `s`.
/// Return `None` if no unclosed quote is found.
/// Return the unclosed quote position and if it is a double quote.
try to find an unclosed single/double quote in `s`.
Return `None` if no unclosed quote is found.
Return the unclosed quote position and if it is a double quote.
try to find an unclosed single / double quote in ` s ` . Return ` None ` if no unclosed quote is found . Return the unclosed quote position and if it is a double quote .
fn find_unclosed_quote(s: &str) -> Option<(usize, Quote)> {
    let char_indices = s.char_indices();
    let mut mode = ScanMode::Normal;
    let mut quote_index = 0;
    for (index, char) in char_indices {
        match mode {
            ScanMode::DoubleQuote => {
                if char == '"' {
                    mode = ScanMode::Normal;
                } else if char == '\\' {
                    mode = ScanMode::EscapeInDoubleQuote;
                }
            }
            ScanMode::Escape => {
                mode = ScanMode::Normal;
            }
            ScanMode::EscapeInDoubleQuote => {
                mode = ScanMode::DoubleQuote;
            }
            ScanMode::Normal => {
                if char == '"' {
                    mode = ScanMode::DoubleQuote;
                    quote_index = index;
                } else if char == '\\' {
                    mode = ScanMode::Escape;
                } else if char == '\'' {
                    mode = ScanMode::SingleQuote;
                    quote_index = index;
                }
            }
            ScanMode::SingleQuote => {
                if char == '\'' {
                    mode = ScanMode::Normal;
                } // no escape in single quotes
            }
        };
    }
    if ScanMode::DoubleQuote == mode || ScanMode::EscapeInDoubleQuote == mode {
        return Some((quote_index, Quote::Double));
    } else if ScanMode::SingleQuote == mode {
        return Some((quote_index, Quote::Single));
    }
    None
}
fn find_unclosed_quote ( s : & str ) -> Option < ( usize , Quote ) > { let char_indices = s . char_indices ( ) ; let mut mode = ScanMode :: Normal ; let mut quote_index = 0 ; for ( index , char ) in char_indices { match mode { ScanMode :: DoubleQuote => { if char == '"' { mode = ScanMode :: Normal ; } else if char == '\\' { mode = ScanMode :: EscapeInDoubleQuote ; } } ScanMode :: Escape => { mode = ScanMode :: Normal ; } ScanMode :: EscapeInDoubleQuote => { mode = ScanMode :: DoubleQuote ; } ScanMode :: Normal => { if char == '"' { mode = ScanMode :: DoubleQuote ; quote_index = index ; } else if char == '\\' { mode = ScanMode :: Escape ; } else if char == '\'' { mode = ScanMode :: SingleQuote ; quote_index = index ; } } ScanMode :: SingleQuote => { if char == '\'' { mode = ScanMode :: Normal ; } // no escape in single quotes } } ; } if ScanMode :: DoubleQuote == mode || ScanMode :: EscapeInDoubleQuote == mode { return Some ( ( quote_index , Quote :: Double ) ) ; } else if ScanMode :: SingleQuote == mode { return Some ( ( quote_index , Quote :: Single ) ) ; } None }
try to find an unclosed single/double quote in `s`.
try to find an unclosed single / double quote in ` s ` .
s
&str