Files
fast-messenger/app/src/main/kotlin/com/meloda/fast/ext/StringExt.kt
T
melod1n 8a6378f509 upstream changes
upstream changes
2023-08-09 03:49:14 +03:00

31 lines
800 B
Kotlin

package com.meloda.fast.ext
import android.content.Context
import android.widget.Toast
import com.meloda.fast.model.base.UiText
inline fun String?.ifEmpty(defaultValue: () -> String?): String? =
if (this?.isEmpty() == true) defaultValue() else this
fun String?.orDots(count: Int = 3): String {
return this ?: ("." * count)
}
operator fun String.times(count: Int): String {
val builder = StringBuilder()
for (i in 0 until count) {
builder.append(this)
}
return builder.toString()
}
fun String.toast(context: Context, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(context, this, duration).show()
}
context (Context)
fun String.toast(duration: Int = Toast.LENGTH_LONG) = toast(this@Context, duration)
fun String.asUiText(): UiText = UiText.Simple(this)