Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/commonMain/kotlin/parseCsv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ internal fun parseCsv(
completeValue()
BeforeValue
}
'\r' -> {
if (nextChar() == '\n') {
pos++
}
if (row.isNotEmpty()) {
completeRow()
}
BeforeValue
}
'\n' -> {
if (row.isNotEmpty()) {
completeRow()
Expand Down
33 changes: 33 additions & 0 deletions src/commonTest/kotlin/CsvTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@ class CsvTest {
println(csv.toCsvText())
assertEquals(3, csv.allRows.size)

val columnCount = header.size
assertEquals(3, columnCount)

val nameIndex = header.indexOf("NAME")
assertEquals(0, nameIndex)

val codeIndex = header.indexOf("CODE")
assertEquals(1, codeIndex)

val descriptionIndex = header.indexOf("DESCRIPTION")
assertEquals(2, descriptionIndex)
}

@Test
fun parseQuotedHeaderWhenNewLineIsRN() {

val givenCsvString =
"""
"NAME","CODE","DESCRIPTION"
"BURGUNDY PINK","4PK.GD-S7","Pink burgundy"
"HILLS PINK","BVH.5-NAR.S8","Pink hills"
""".trimIndent()
.replace("\n", "\r\n")

val csv = CsvWithHeader.fromCsvText(givenCsvString) as CsvWithHeader
val header = csv.allRows[0]

println(csv.toCsvText())
assertEquals(3, csv.allRows.size)

val columnCount = header.size
assertEquals(3, columnCount)

val nameIndex = header.indexOf("NAME")
assertEquals(0, nameIndex)

Expand Down
Loading