2019-04-24 18:28:41 +00:00
|
|
|
package com.topjohnwu.magisk.utils
|
|
|
|
|
2019-05-10 14:22:03 +00:00
|
|
|
import android.content.res.Resources
|
|
|
|
|
2019-04-24 18:28:41 +00:00
|
|
|
val specialChars = arrayOf('!', '@', '#', '$', '%', '&', '?')
|
|
|
|
|
|
|
|
fun String.replaceRandomWithSpecial(): String {
|
|
|
|
var random: Char
|
|
|
|
do {
|
|
|
|
random = random()
|
|
|
|
} while (random == '.')
|
|
|
|
return replace(random, specialChars.random())
|
2019-05-06 17:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun StringBuilder.appendIf(condition: Boolean, builder: StringBuilder.() -> Unit) =
|
2019-05-10 14:43:37 +00:00
|
|
|
if (condition) apply(builder) else this
|
|
|
|
|
2019-05-10 14:22:03 +00:00
|
|
|
fun Int.res(vararg args: Any): String {
|
|
|
|
val resources: Resources by inject()
|
|
|
|
return resources.getString(this, *args)
|
2019-06-03 14:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun String.trimEmptyToNull(): String? = if (isBlank()) null else this
|