Make CameraX blocklist remote configurable.

This commit is contained in:
Greyson Parrelli
2022-08-05 09:38:04 -04:00
committed by Cody Henthorne
parent ace4157a14
commit 91d3f331e5
7 changed files with 59 additions and 148 deletions

View File

@@ -0,0 +1,23 @@
package org.signal.core.util
/**
* Treats the string as a serialized list of tokens and tells you if an item is present in the list.
* In addition to exact matches, this handles wildcards at the end of an item.
*
* e.g. a,b,c*,d
*/
fun String.asListContains(item: String): Boolean {
val items: List<String> = this
.split(",")
.map { it.trim() }
.filter { it.isNotEmpty() }
.toList()
val exactMatches = items.filter { it.last() != '*' }
val prefixMatches = items.filter { it.last() == '*' }
return exactMatches.contains(item) ||
prefixMatches
.map { it.substring(0, it.length - 1) }
.any { item.startsWith(it) }
}