Compare commits

..

9 Commits

6 changed files with 271 additions and 213 deletions

View File

@@ -1,7 +1,23 @@
# Changelog
## 0.5.20
* `Repos`:
* `Common`
* `Android`:
* `*OrNull` analogs of `Cursor.get*(String)` extensions have been added
* Extensions `Cursor.getFloat` and `Cursor.getFloatOrNull` have been added
## 0.5.19
* `LanguageCode`:
* `IetfLanguageCode` became as sealed class
* `IetfLanguageCode` now override `toString` and returns its code
## 0.5.18
* `Versions`
* `Kotlin Exposed`: `0.32.1` -> `0.33.1`
* `LanguageCode`:
* Module has been created

View File

@@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2g
kotlin_version=1.5.21
kotlin_coroutines_version=1.5.1
kotlin_serialisation_core_version=1.2.2
kotlin_exposed_version=0.32.1
kotlin_exposed_version=0.33.1
ktor_version=1.6.2
@@ -40,10 +40,10 @@ crypto_js_version=4.1.1
# Dokka
dokka_version=1.4.32
dokka_version=1.5.0
# Project data
group=dev.inmo
version=0.5.18
android_code_version=59
version=0.5.20
android_code_version=61

View File

@@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import java.io.File
import java.text.Normalizer
private val json = Json {
ignoreUnknownKeys = true
@@ -29,6 +30,8 @@ fun String.adaptAsTitle() = if (first().isDigit()) {
this
}
fun String.normalized() = Normalizer.normalize(this, Normalizer.Form.NFD).replace(Regex("[^\\p{ASCII}]"), "")
@Serializable
private data class LanguageCodeWithTag(
@SerialName("langType")
@@ -74,11 +77,11 @@ private fun printLanguageCodeAndTags(
indents: String = " "
): String = if (tag.subtags.isEmpty()) {
"""${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 {
"""
${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}"
${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.
*/
${baseClassSerializerAnnotationName}
sealed interface $baseClassName {
val code: String
sealed class $baseClassName {
abstract val code: String
${tags.joinToString("\n") { printLanguageCodeAndTags(it, indents = " ") } }
$baseClassSerializerAnnotationName
data class $unknownBaseClassName (override val code: String) : $baseClassName
data class $unknownBaseClassName (override val code: String) : $baseClassName()
override fun toString() = code
}
""".trimIndent()
@@ -179,18 +184,14 @@ suspend fun main(vararg args: String) {
val subtags = unformattedSubtags.mapNotNull {
if (it.endTag == null) {
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 {
null
}
}
Tag(
it.title,
it.tag,
subtags
)
Tag(it.title.normalized(), it.tag, subtags)
}
File(outputFolder, "LanguageCodes.kt").apply {

View File

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

View File

@@ -2,6 +2,8 @@ package dev.inmo.micro_utils.repos
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import androidx.core.database.*
import dev.inmo.micro_utils.repos.getLongOrNull
fun createTableQuery(
tableName: String,
@@ -32,6 +34,11 @@ fun SQLiteDatabase.createTable(
fun Cursor.getString(columnName: String): String = getString(
getColumnIndexOrThrow(columnName)
)
fun Cursor.getStringOrNull(columnName: String): String? {
return getStringOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/**
* @throws IllegalArgumentException
@@ -39,6 +46,11 @@ fun Cursor.getString(columnName: String): String = getString(
fun Cursor.getShort(columnName: String): Short = getShort(
getColumnIndexOrThrow(columnName)
)
fun Cursor.getShortOrNull(columnName: String): Short? {
return getShortOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/**
* @throws IllegalArgumentException
@@ -46,6 +58,11 @@ fun Cursor.getShort(columnName: String): Short = getShort(
fun Cursor.getLong(columnName: String): Long = getLong(
getColumnIndexOrThrow(columnName)
)
fun Cursor.getLongOrNull(columnName: String): Long? {
return getLongOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/**
* @throws IllegalArgumentException
@@ -53,6 +70,23 @@ fun Cursor.getLong(columnName: String): Long = getLong(
fun Cursor.getInt(columnName: String): Int = getInt(
getColumnIndexOrThrow(columnName)
)
fun Cursor.getIntOrNull(columnName: String): Int? {
return getIntOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/**
* @throws IllegalArgumentException
*/
fun Cursor.getFloat(columnName: String): Float = getFloat(
getColumnIndexOrThrow(columnName)
)
fun Cursor.getFloatOrNull(columnName: String): Float? {
return getFloatOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
/**
* @throws IllegalArgumentException
@@ -60,6 +94,11 @@ fun Cursor.getInt(columnName: String): Int = getInt(
fun Cursor.getDouble(columnName: String): Double = getDouble(
getColumnIndexOrThrow(columnName)
)
fun Cursor.getDoubleOrNull(columnName: String): Double? {
return getDoubleOrNull(
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
)
}
fun SQLiteDatabase.select(
table: String,