kotlinx.serialization.hocon.NamingConvention.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-serialization-hocon Show documentation
Show all versions of kotlinx-serialization-hocon Show documentation
Kotlin multiplatform serialization runtime library
The newest version!
package kotlinx.serialization.hocon
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
private val NAMING_CONVENTION_REGEX by lazy { "[A-Z]".toRegex() }
@OptIn(ExperimentalSerializationApi::class)
internal fun SerialDescriptor.getConventionElementName(index: Int, useConfigNamingConvention: Boolean): String {
val originalName = getElementName(index)
return if (!useConfigNamingConvention) originalName
else originalName.replace(NAMING_CONVENTION_REGEX) { "-${it.value.lowercase()}" }
}