2020-03-27 03:16:56 +01:00
|
|
|
package org.schabi.newpipe.util.urlfinder
|
|
|
|
|
|
|
|
import java.util.regex.Pattern
|
|
|
|
|
|
|
|
class UrlFinder {
|
|
|
|
companion object {
|
|
|
|
private val WEB_URL_WITH_PROTOCOL = Pattern.compile(PatternsCompat.WEB_URL_WITH_PROTOCOL)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the first url found in the input, null otherwise.
|
|
|
|
*/
|
|
|
|
@JvmStatic
|
|
|
|
fun firstUrlFromInput(input: String?): String? {
|
|
|
|
if (input.isNullOrEmpty()) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
val matcher = WEB_URL_WITH_PROTOCOL.matcher(input)
|
|
|
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
return matcher.group()
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 20:13:21 +02:00
|
|
|
}
|