diff --git a/README.md b/README.md index 07a544b..ea58eff 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ val row2 = listOf("d", "e", "f") csvWriter().open("test.csv") { writeRow(row1) writeRow(row2) + writeRow("g", "h", "i") writeRows(listOf(row1, row2)) } ``` diff --git a/src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/ICsvFileWriter.kt b/src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/ICsvFileWriter.kt index 8fc265c..18e2537 100644 --- a/src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/ICsvFileWriter.kt +++ b/src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/ICsvFileWriter.kt @@ -3,6 +3,8 @@ package com.github.doyaaaaaken.kotlincsv.client interface ICsvFileWriter { fun writeRow(row: List) + fun writeRow(vararg entry: Any?) + fun writeRows(rows: List>) fun writeRows(rows: Sequence>) diff --git a/src/jvmMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriter.kt b/src/jvmMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriter.kt index d10f2d1..da557f6 100644 --- a/src/jvmMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriter.kt +++ b/src/jvmMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriter.kt @@ -36,6 +36,13 @@ class CsvFileWriter internal constructor( } } + /** + * write one row + */ + override fun writeRow(vararg entry: Any?) { + writeRow(entry.toList()) + } + /** * write rows */ diff --git a/src/jvmTest/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriterTest.kt b/src/jvmTest/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriterTest.kt index 51897bc..4c00d17 100644 --- a/src/jvmTest/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriterTest.kt +++ b/src/jvmTest/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileWriterTest.kt @@ -51,6 +51,24 @@ class CsvFileWriterTest : WordSpec() { val actual = readTestFile() actual shouldBe expected } + "write row from variable arguments" { + + val date1 = LocalDate.of(2019, 8, 19) + val date2 = LocalDateTime.of(2020, 9, 20, 14, 32, 21) + + val expected = "a,b,c\r\n"+ + "d,e,f\r\n"+ + "1,2,3\r\n"+ + "2019-08-19,2020-09-20T14:32:21\r\n" + csvWriter().open(testFileName) { + writeRow("a", "b", "c") + writeRow("d", "e", "f") + writeRow(1,2,3) + writeRow(date1, date2) + } + val actual = readTestFile() + actual shouldBe expected + } } "writeAll method" should { "write Sequence data" {