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

23 lines
550 B
Kotlin
Raw Normal View History

2019-08-08 19:31:47 +02:00
package exh.util
fun List<String>.trimAll() = map { it.trim() }
fun List<String>.dropBlank() = filter { it.isNotBlank() }
fun List<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()
return if (trimmed.isBlank()) null else trimmed
}
2020-07-27 19:32:43 +02:00
fun String?.nullIfBlank(): String? = if (isNullOrBlank()) {
null
} else {
this
}