1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-16 01:12:05 +01:00

Dip the regex set into caramell - hmmm

This commit is contained in:
Paul Schaub 2023-07-05 18:08:54 +02:00
parent 38d9351620
commit 570bb1a512
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -43,16 +43,9 @@ data class RegexSet(val regexStrings: Set<String>) {
* That is if at least one RegEx in the set matches the [string], or if the set represents a wildcard. * That is if at least one RegEx in the set matches the [string], or if the set represents a wildcard.
*/ */
fun matches(string: String): Boolean { fun matches(string: String): Boolean {
if (regexStrings.isEmpty()) { // wildcard or any match
return true return regexStrings.isEmpty() || regexStrings.any {
Pattern.compile(it).matcher(string).find()
} }
for (regex in regexStrings) {
val matcher = Pattern.compile(regex).matcher(string)
if (matcher.find()) {
return true
}
}
return false
} }
} }