Skip to content

Commit

Permalink
Make CsvConfig public
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Obser committed Dec 13, 2024
1 parent 8ebc30e commit 3bb6e98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '"',
Expand All @@ -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
)
}
}

0 comments on commit 3bb6e98

Please sign in to comment.