2022-11-06 21:05:36 +05:30
|
|
|
package com.github.libretube.util
|
|
|
|
|
2022-12-26 21:12:47 +05:30
|
|
|
import java.net.URL
|
|
|
|
|
2022-11-06 21:05:36 +05:30
|
|
|
object TextUtils {
|
|
|
|
/**
|
|
|
|
* Separator used for descriptions
|
|
|
|
*/
|
|
|
|
const val SEPARATOR = " • "
|
2022-11-09 22:31:59 +05:30
|
|
|
|
2022-12-01 19:58:41 +05:30
|
|
|
/**
|
|
|
|
* Regex to check for e-mails
|
|
|
|
*/
|
|
|
|
const val EMAIL_REGEX = "^[A-Za-z](.*)([@]{1})(.{1,})(\\.)(.{1,})"
|
|
|
|
|
2022-11-09 22:31:59 +05:30
|
|
|
fun toTwoDecimalsString(num: Int): String {
|
|
|
|
return if (num >= 10) num.toString() else "0$num"
|
|
|
|
}
|
2022-12-26 21:12:47 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether an Url is valid
|
|
|
|
* @param url The url to test
|
|
|
|
* @return Whether the URL is valid
|
|
|
|
*/
|
|
|
|
fun validateUrl(url: String): Boolean {
|
|
|
|
runCatching {
|
|
|
|
URL(url).toURI()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-11-06 21:05:36 +05:30
|
|
|
}
|