
commonMain.buildCsv.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of csv-jvm Show documentation
Show all versions of csv-jvm Show documentation
Tiny KMP library for parsing, building and generating CSV files
/** Copyright 2023 Halfbit GmbH, Sergej Shafarenka */
package de.halfbit.csv
@DslMarker
public annotation class CsvDsl
public fun buildCsv(
block: CsvBuilder.() -> Unit
): Csv {
val rows = mutableListOf>()
block(CsvBuilder(rows))
return Csv(rows)
}
@CsvDsl
public class CsvBuilder internal constructor(
private val rows: MutableList>,
) {
public fun row(block: CsvRowBuilder.() -> Unit) {
val row = mutableListOf()
val scope = CsvRowBuilder(row)
block(scope)
rows.add(row)
}
}
@CsvDsl
public class CsvRowBuilder internal constructor(
private val row: MutableList,
) {
public fun value(value: String) {
row.add(value)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy