1
0
Fork 0

Switch to any calls

master
Tiger Oakes 2020-07-02 14:59:48 -07:00 committed by Mihai Branescu
parent 41452e945b
commit fd18687ac9
2 changed files with 5 additions and 26 deletions

View File

@ -82,14 +82,8 @@ abstract class BaseSearchTelemetry {
abstract fun install(engine: Engine, store: BrowserStore) abstract fun install(engine: Engine, store: BrowserStore)
internal fun getProviderForUrl(url: String): SearchProviderModel? { internal fun getProviderForUrl(url: String): SearchProviderModel? =
for (provider in providerList) { providerList.find { provider -> provider.regexp.containsMatchIn(url) }
if (Regex(provider.regexp).containsMatchIn(url)) {
return provider
}
}
return null
}
internal fun installWebExtension( internal fun installWebExtension(
engine: Engine, engine: Engine,

View File

@ -39,23 +39,8 @@ data class SearchProviderModel(
* Checks if any of the given URLs represent an ad from the search engine. * Checks if any of the given URLs represent an ad from the search engine.
* Used to check if a clicked link was for an ad. * Used to check if a clicked link was for an ad.
*/ */
fun containsAds(urlList: List<String>) = urlList.containsAds(extraAdServersRegexps) fun containsAds(urlList: List<String>) = urlList.any { url -> isAd(url) }
private fun String.isAd(adRegexps: List<Regex>): Boolean { private fun isAd(url: String) =
for (adsRegex in adRegexps) { extraAdServersRegexps.any { adsRegex -> adsRegex.containsMatchIn(url) }
if (adsRegex.containsMatchIn(this)) {
return true
}
}
return false
}
private fun List<String>.containsAds(adRegexps: List<Regex>): Boolean {
for (url in this) {
if (url.isAd(adRegexps)) {
return true
}
}
return false
}
} }