All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.buildCsv.kt Maven / Gradle / Ivy

There is a newer version: 0.15
Show newest version
/** 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 - 2025 Weber Informatics LLC | Privacy Policy