added checkURI and checkName util functions

This commit is contained in:
Juha Heinanen
2018-06-10 18:39:05 +03:00
parent 1245fba3da
commit 1b72542325

View File

@ -11,8 +11,6 @@ import android.os.Build
import android.os.PowerManager
import android.app.KeyguardManager
object Utils {
fun getFileContents(file: File): String {
@ -100,6 +98,13 @@ object Utils {
return true
}
fun checkUri(uri: String): Boolean {
if (!uri.startsWith("sip:")) return false
val parts = uri.substring(4).split("@")
return (checkUserID(parts[0]) || checkTelNo(parts[0])) &&
(checkDomain(parts[1]) || checkIP(parts[1]))
}
fun checkPrintASCII(s: String): Boolean {
if (s == "") return true
val printASCIIRegex = Regex("^[ -~]*\$")
@ -111,6 +116,14 @@ object Utils {
return uintRegex.matches(s)
}
fun checkName(name: String): Boolean {
if (name.length < 2) return false
for (c in name) {
if (!c.isLetterOrDigit() && !(c in "-.!%*_+`'~ ")) return false
}
return true
}
fun implode(list: List<String>, sep: String): String {
var res = ""
for (s in list) {