Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CR-only line breaks in CSVLikeParser #224

Merged
merged 2 commits into from
Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import cats.implicits._
* https://tools.ietf.org/html/rfc4180
*
* Deviations from the specification, here I have chosen to use a
* permissive CRLF that will accept a CRLF or a LF.
* permissive CRLF that will accept a CRLF, LF, or CR.
* Note that the CR is not directly in the initial spec, but in rare
* cases csvs can have this delimiter
*
* The important details are as follows
* 1. Each record is located on a separate line, delimited by a line
Expand Down Expand Up @@ -85,9 +87,9 @@ abstract class CSVLikeParser(val separator: Char) {
// CRLF = CR LF ;as per section 6.1 of RFC 2234 [2]
val CRLF: Parser[(Char, Char)] = CR ~ LF

// Genuine CRLF or a Line Feed which is translated to a CRLF
// Genuine CRLF, a Line Feed, or a CR which is translated to a CRLF
val PERMISSIVE_CRLF: Parser[(Char, Char)] =
(CRLF | char(lf).map((cr, _))).named("PERMISSIVE_CRLF")
(CRLF | LF.map((cr, _)) | CR.map((_, lf))).named("PERMISSIVE_CRLF")

// COMMA = %x2C
val SEPARATOR: Parser[Char] = char(separator).named("SEPARATOR")
Expand Down