in rust-csv/csv-core/src/reader.rs [985:1068]
fn transition_nfa(
&self,
state: NfaState,
c: u8,
) -> (NfaState, NfaInputAction) {
use self::NfaState::*;
match state {
End => (End, NfaInputAction::Epsilon),
StartRecord => {
if self.term.equals(c) {
(StartRecord, NfaInputAction::Discard)
} else if self.comment == Some(c) {
(InComment, NfaInputAction::Discard)
} else {
(StartField, NfaInputAction::Epsilon)
}
}
EndRecord => (StartRecord, NfaInputAction::Epsilon),
StartField => {
if self.quoting && self.quote == c {
(InQuotedField, NfaInputAction::Discard)
} else if self.delimiter == c {
(EndFieldDelim, NfaInputAction::Discard)
} else if self.term.equals(c) {
(EndFieldTerm, NfaInputAction::Epsilon)
} else {
(InField, NfaInputAction::CopyToOutput)
}
}
EndFieldDelim => (StartField, NfaInputAction::Epsilon),
EndFieldTerm => (InRecordTerm, NfaInputAction::Epsilon),
InField => {
if self.delimiter == c {
(EndFieldDelim, NfaInputAction::Discard)
} else if self.term.equals(c) {
(EndFieldTerm, NfaInputAction::Epsilon)
} else {
(InField, NfaInputAction::CopyToOutput)
}
}
InQuotedField => {
if self.quoting && self.quote == c {
(InDoubleEscapedQuote, NfaInputAction::Discard)
} else if self.quoting && self.escape == Some(c) {
(InEscapedQuote, NfaInputAction::Discard)
} else {
(InQuotedField, NfaInputAction::CopyToOutput)
}
}
InEscapedQuote => (InQuotedField, NfaInputAction::CopyToOutput),
InDoubleEscapedQuote => {
if self.quoting && self.double_quote && self.quote == c {
(InQuotedField, NfaInputAction::CopyToOutput)
} else if self.delimiter == c {
(EndFieldDelim, NfaInputAction::Discard)
} else if self.term.equals(c) {
(EndFieldTerm, NfaInputAction::Epsilon)
} else {
(InField, NfaInputAction::CopyToOutput)
}
}
InComment => {
if b'\n' == c {
(StartRecord, NfaInputAction::Discard)
} else {
(InComment, NfaInputAction::Discard)
}
}
InRecordTerm => {
if self.term.is_crlf() && b'\r' == c {
(CRLF, NfaInputAction::Discard)
} else {
(EndRecord, NfaInputAction::Discard)
}
}
CRLF => {
if b'\n' == c {
(StartRecord, NfaInputAction::Discard)
} else {
(StartRecord, NfaInputAction::Epsilon)
}
}
}
}