Skip to content

Commit e31d44f

Browse files
committed
Allow for escaping the delimiter
1 parent 40ea4c4 commit e31d44f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

csv-core/src/reader.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,15 @@ enum NfaState {
428428
InQuotedField = 3,
429429
InEscapedQuote = 4,
430430
InDoubleEscapedQuote = 5,
431-
InComment = 6,
431+
InEscapeSequence = 6,
432+
InComment = 7,
432433
// All states below are "final field" states.
433434
// Namely, they indicate that a field has been parsed.
434-
EndFieldDelim = 7,
435+
EndFieldDelim = 8,
435436
// All states below are "final record" states.
436437
// Namely, they indicate that a record has been parsed.
437-
EndRecord = 8,
438-
CRLF = 9,
438+
EndRecord = 9,
439+
CRLF = 10,
439440
}
440441

441442
/// A list of NFA states that have an explicit representation in the DFA.
@@ -970,7 +971,7 @@ impl Reader {
970971
match state {
971972
End | StartRecord | EndRecord | InComment | CRLF => End,
972973
StartField | EndFieldDelim | EndFieldTerm | InField
973-
| InQuotedField | InEscapedQuote | InDoubleEscapedQuote
974+
| InQuotedField | InEscapedQuote | InDoubleEscapedQuote | InEscapeSequence
974975
| InRecordTerm => EndRecord,
975976
}
976977
}
@@ -1018,6 +1019,8 @@ impl Reader {
10181019
(EndFieldDelim, NfaInputAction::Discard)
10191020
} else if self.term.equals(c) {
10201021
(EndFieldTerm, NfaInputAction::Epsilon)
1022+
} else if !self.quoting && self.escape == Some(c) {
1023+
(InEscapeSequence, NfaInputAction::Discard)
10211024
} else {
10221025
(InField, NfaInputAction::CopyToOutput)
10231026
}
@@ -1043,6 +1046,9 @@ impl Reader {
10431046
(InField, NfaInputAction::CopyToOutput)
10441047
}
10451048
}
1049+
InEscapeSequence => {
1050+
(InField, NfaInputAction::CopyToOutput)
1051+
},
10461052
InComment => {
10471053
if b'\n' == c {
10481054
(StartRecord, NfaInputAction::Discard)

0 commit comments

Comments
 (0)