Merge pull request #84 from InsanusMokrassar/0.5.19

0.5.19
This commit is contained in:
InsanusMokrassar 2021-08-08 22:52:09 +06:00 committed by GitHub
commit 57b7797ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 220 additions and 211 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 0.5.19
* `LanguageCode`:
* `IetfLanguageCode` became as sealed class
* `IetfLanguageCode` now override `toString` and returns its code
## 0.5.18 ## 0.5.18
* `LanguageCode`: * `LanguageCode`:

View File

@ -45,5 +45,5 @@ dokka_version=1.4.32
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.5.18 version=0.5.19
android_code_version=59 android_code_version=60

View File

@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import java.io.File import java.io.File
import java.text.Normalizer
private val json = Json { private val json = Json {
ignoreUnknownKeys = true ignoreUnknownKeys = true
@ -29,6 +30,8 @@ fun String.adaptAsTitle() = if (first().isDigit()) {
this this
} }
fun String.normalized() = Normalizer.normalize(this, Normalizer.Form.NFD).replace(Regex("[^\\p{ASCII}]"), "")
@Serializable @Serializable
private data class LanguageCodeWithTag( private data class LanguageCodeWithTag(
@SerialName("langType") @SerialName("langType")
@ -74,11 +77,11 @@ private fun printLanguageCodeAndTags(
indents: String = " " indents: String = " "
): String = if (tag.subtags.isEmpty()) { ): String = if (tag.subtags.isEmpty()) {
"""${indents}${baseClassSerializerAnnotationName} """${indents}${baseClassSerializerAnnotationName}
${indents}object ${tag.title} : ${parent ?.title ?.let { "$it()" } ?: baseClassName} { override val code: String = "${tag.tag}" }""" ${indents}object ${tag.title} : ${parent ?.title ?: baseClassName}() { override val code: String = "${tag.tag}" }"""
} else { } else {
""" """
${indents}${baseClassSerializerAnnotationName} ${indents}${baseClassSerializerAnnotationName}
${indents}sealed class ${tag.title} : ${parent ?.title ?.let { "$it()" } ?: baseClassName} { ${indents}sealed class ${tag.title} : ${parent ?.title ?: baseClassName}() {
${indents} override val code: String = "${tag.tag}" ${indents} override val code: String = "${tag.tag}"
${tag.subtags.joinToString("\n") { printLanguageCodeAndTags(it, tag, "${indents} ") }} ${tag.subtags.joinToString("\n") { printLanguageCodeAndTags(it, tag, "${indents} ") }}
@ -98,13 +101,15 @@ import kotlinx.serialization.Serializable
* https://datahub.io/core/language-codes/ files (base and tags) and create the whole hierarchy using it. * https://datahub.io/core/language-codes/ files (base and tags) and create the whole hierarchy using it.
*/ */
${baseClassSerializerAnnotationName} ${baseClassSerializerAnnotationName}
sealed interface $baseClassName { sealed class $baseClassName {
val code: String abstract val code: String
${tags.joinToString("\n") { printLanguageCodeAndTags(it, indents = " ") } } ${tags.joinToString("\n") { printLanguageCodeAndTags(it, indents = " ") } }
$baseClassSerializerAnnotationName $baseClassSerializerAnnotationName
data class $unknownBaseClassName (override val code: String) : $baseClassName data class $unknownBaseClassName (override val code: String) : $baseClassName()
override fun toString() = code
} }
""".trimIndent() """.trimIndent()
@ -179,18 +184,14 @@ suspend fun main(vararg args: String) {
val subtags = unformattedSubtags.mapNotNull { val subtags = unformattedSubtags.mapNotNull {
if (it.endTag == null) { if (it.endTag == null) {
val currentSubtags = (threeLevelTags[it.subtag] ?: emptyList()).map { val currentSubtags = (threeLevelTags[it.subtag] ?: emptyList()).map {
Tag(it.endTagAsTitle!!, it.withSubtag, emptyList()) Tag(it.endTagAsTitle!!.normalized(), it.withSubtag, emptyList())
} }
Tag(it.middleTagTitle, it.withSubtag, currentSubtags) Tag(it.middleTagTitle.normalized(), it.withSubtag, currentSubtags)
} else { } else {
null null
} }
} }
Tag( Tag(it.title.normalized(), it.tag, subtags)
it.title,
it.tag,
subtags
)
} }
File(outputFolder, "LanguageCodes.kt").apply { File(outputFolder, "LanguageCodes.kt").apply {

View File

@ -461,9 +461,9 @@ fun String.asIetfLanguageCode(): IetfLanguageCode {
IetfLanguageCode.Burmese.code -> IetfLanguageCode.Burmese IetfLanguageCode.Burmese.code -> IetfLanguageCode.Burmese
IetfLanguageCode.Burmese.MM.code -> IetfLanguageCode.Burmese.MM IetfLanguageCode.Burmese.MM.code -> IetfLanguageCode.Burmese.MM
IetfLanguageCode.Nauru.code -> IetfLanguageCode.Nauru IetfLanguageCode.Nauru.code -> IetfLanguageCode.Nauru
IetfLanguageCode.BokmålNorwegianNorwegianBokmål.code -> IetfLanguageCode.BokmålNorwegianNorwegianBokmål IetfLanguageCode.BokmalNorwegianNorwegianBokmal.code -> IetfLanguageCode.BokmalNorwegianNorwegianBokmal
IetfLanguageCode.BokmålNorwegianNorwegianBokmål.NO.code -> IetfLanguageCode.BokmålNorwegianNorwegianBokmål.NO IetfLanguageCode.BokmalNorwegianNorwegianBokmal.NO.code -> IetfLanguageCode.BokmalNorwegianNorwegianBokmal.NO
IetfLanguageCode.BokmålNorwegianNorwegianBokmål.SJ.code -> IetfLanguageCode.BokmålNorwegianNorwegianBokmål.SJ IetfLanguageCode.BokmalNorwegianNorwegianBokmal.SJ.code -> IetfLanguageCode.BokmalNorwegianNorwegianBokmal.SJ
IetfLanguageCode.NdebeleNorthNorthNdebele.code -> IetfLanguageCode.NdebeleNorthNorthNdebele IetfLanguageCode.NdebeleNorthNorthNdebele.code -> IetfLanguageCode.NdebeleNorthNorthNdebele
IetfLanguageCode.NdebeleNorthNorthNdebele.ZW.code -> IetfLanguageCode.NdebeleNorthNorthNdebele.ZW IetfLanguageCode.NdebeleNorthNorthNdebele.ZW.code -> IetfLanguageCode.NdebeleNorthNorthNdebele.ZW
IetfLanguageCode.Nepali.code -> IetfLanguageCode.Nepali IetfLanguageCode.Nepali.code -> IetfLanguageCode.Nepali
@ -639,8 +639,8 @@ fun String.asIetfLanguageCode(): IetfLanguageCode {
IetfLanguageCode.Venda.code -> IetfLanguageCode.Venda IetfLanguageCode.Venda.code -> IetfLanguageCode.Venda
IetfLanguageCode.Vietnamese.code -> IetfLanguageCode.Vietnamese IetfLanguageCode.Vietnamese.code -> IetfLanguageCode.Vietnamese
IetfLanguageCode.Vietnamese.VN.code -> IetfLanguageCode.Vietnamese.VN IetfLanguageCode.Vietnamese.VN.code -> IetfLanguageCode.Vietnamese.VN
IetfLanguageCode.Volapük.code -> IetfLanguageCode.Volapük IetfLanguageCode.Volapuk.code -> IetfLanguageCode.Volapuk
IetfLanguageCode.Volapük.L001.code -> IetfLanguageCode.Volapük.L001 IetfLanguageCode.Volapuk.L001.code -> IetfLanguageCode.Volapuk.L001
IetfLanguageCode.Walloon.code -> IetfLanguageCode.Walloon IetfLanguageCode.Walloon.code -> IetfLanguageCode.Walloon
IetfLanguageCode.Wolof.code -> IetfLanguageCode.Wolof IetfLanguageCode.Wolof.code -> IetfLanguageCode.Wolof
IetfLanguageCode.Wolof.SN.code -> IetfLanguageCode.Wolof.SN IetfLanguageCode.Wolof.SN.code -> IetfLanguageCode.Wolof.SN