komikku/app/src/main/java/exh/util/StringUtil.kt

23 lines
552 B
Kotlin
Raw Normal View History

2019-08-08 19:31:47 +02:00
package exh.util
2022-02-01 23:07:57 +01:00
fun Collection<String>.trimAll() = map { it.trim() }
fun Collection<String>.dropBlank() = filter { it.isNotBlank() }
fun Collection<String>.dropEmpty() = filter { it.isNotEmpty() }
2020-05-04 00:34:46 +02:00
private val articleRegex by lazy { "^(an|a|the) ".toRegex(RegexOption.IGNORE_CASE) }
2020-05-04 00:34:46 +02:00
fun String.removeArticles(): String {
2021-03-23 01:25:46 +01:00
return replace(articleRegex, "")
2020-05-04 00:34:46 +02:00
}
fun String.trimOrNull(): String? {
val trimmed = trim()
2022-02-01 23:07:57 +01:00
return trimmed.ifBlank { null }
}
2020-07-27 19:32:43 +02:00
fun String?.nullIfBlank(): String? = if (isNullOrBlank()) {
null
} else {
this
}