Skip to content

Commit

Permalink
Allow for escaping the delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
leaty committed May 30, 2021
1 parent 40ea4c4 commit c4547f4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions csv-core/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,15 @@ enum NfaState {
InQuotedField = 3,
InEscapedQuote = 4,
InDoubleEscapedQuote = 5,
InComment = 6,
InEscapeSequence = 6,
InComment = 7,
// All states below are "final field" states.
// Namely, they indicate that a field has been parsed.
EndFieldDelim = 7,
EndFieldDelim = 8,
// All states below are "final record" states.
// Namely, they indicate that a record has been parsed.
EndRecord = 8,
CRLF = 9,
EndRecord = 9,
CRLF = 10,
}

/// A list of NFA states that have an explicit representation in the DFA.
Expand Down Expand Up @@ -970,7 +971,7 @@ impl Reader {
match state {
End | StartRecord | EndRecord | InComment | CRLF => End,
StartField | EndFieldDelim | EndFieldTerm | InField
| InQuotedField | InEscapedQuote | InDoubleEscapedQuote
| InQuotedField | InEscapedQuote | InDoubleEscapedQuote | InEscapeSequence
| InRecordTerm => EndRecord,
}
}
Expand Down Expand Up @@ -1018,6 +1019,8 @@ impl Reader {
(EndFieldDelim, NfaInputAction::Discard)
} else if self.term.equals(c) {
(EndFieldTerm, NfaInputAction::Epsilon)
} else if !self.quoting && self.escape == Some(c) {
(InEscapeSequence, NfaInputAction::Discard)
} else {
(InField, NfaInputAction::CopyToOutput)
}
Expand All @@ -1043,6 +1046,7 @@ impl Reader {
(InField, NfaInputAction::CopyToOutput)
}
}
InEscapeSequence => (InField, NfaInputAction::CopyToOutput),
InComment => {
if b'\n' == c {
(StartRecord, NfaInputAction::Discard)
Expand Down

0 comments on commit c4547f4

Please sign in to comment.