ReadYou/app/src/main/java/me/ash/reader/StringExt.kt
2022-03-08 09:20:50 +08:00

18 lines
427 B
Kotlin

package me.ash.reader
fun String.formatUrl(): String {
if (this.startsWith("//")) {
return "https:$this"
}
val regex = Regex("^(https?|ftp|file).*")
return if (!regex.matches(this)) {
"https://$this"
} else {
this
}
}
fun String.isUrl(): Boolean {
val regex = Regex("(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]")
return regex.matches(this)
}