ReadYou/app/src/main/java/me/ash/reader/StringExt.kt

18 lines
427 B
Kotlin
Raw Normal View History

2022-03-07 18:11:01 +01:00
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)
}