From 3bb6e983699363838dbdbbc3c549555ad8e81fec Mon Sep 17 00:00:00 2001 From: Sven Obser Date: Fri, 13 Dec 2024 15:14:46 +0100 Subject: [PATCH] Make `CsvConfig` public --- .../main/kotlin/kotlinx/serialization/csv/Csv.kt | 16 ++++++++-------- .../serialization/csv/config/CsvConfig.kt | 14 ++++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt b/library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt index 5ae2289..178fea6 100644 --- a/library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt +++ b/library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt @@ -25,7 +25,7 @@ import kotlinx.serialization.modules.SerializersModule * Then constructed instance can be used either as regular [SerialFormat] or [StringFormat]. */ @ExperimentalSerializationApi -sealed class Csv(internal val config: CsvConfig) : SerialFormat, StringFormat { +sealed class Csv(val config: CsvConfig) : SerialFormat, StringFormat { override val serializersModule: SerializersModule get() = config.serializersModule @@ -89,10 +89,10 @@ sealed class Csv(internal val config: CsvConfig) : SerialFormat, StringFormat { * adjusted with [action]. */ @ExperimentalSerializationApi -fun Csv(from: Csv = Csv.Default, action: CsvBuilder.() -> Unit): Csv { - val conf = CsvBuilder(from.config).run { - action() - build() - } - return Csv.Impl(conf) -} +fun Csv(from: Csv = Csv.Default, action: CsvBuilder.() -> Unit): Csv = + Csv.Impl( + config = CsvBuilder(from.config).run { + action() + build() + }, + ) diff --git a/library/src/main/kotlin/kotlinx/serialization/csv/config/CsvConfig.kt b/library/src/main/kotlin/kotlinx/serialization/csv/config/CsvConfig.kt index d0bcc8f..5192b24 100644 --- a/library/src/main/kotlin/kotlinx/serialization/csv/config/CsvConfig.kt +++ b/library/src/main/kotlin/kotlinx/serialization/csv/config/CsvConfig.kt @@ -18,7 +18,7 @@ import kotlinx.serialization.modules.SerializersModule * @param ignoreUnknownColumns Ignore unknown columns when `hasHeaderRecord` is enabled (default: `false`). * @param hasTrailingDelimiter If records end with a trailing [delimiter] (default: `false`). */ -internal data class CsvConfig( +data class CsvConfig( val delimiter: Char = ',', val recordSeparator: String = "\n", val quoteChar: Char = '"', @@ -37,14 +37,16 @@ internal data class CsvConfig( /** * Standard *Comma Separated Value* format. */ - val Default = CsvConfig() + val Default + get() = CsvConfig() /** * [RFC 4180](http://tools.ietf.org/html/rfc4180) *Comma Separated Value* format. */ - val Rfc4180 = CsvConfig( - recordSeparator = "\r\n", - ignoreEmptyLines = false - ) + val Rfc4180 + get() = CsvConfig( + recordSeparator = "\r\n", + ignoreEmptyLines = false + ) } }