From 570bb1a512418d9e0a4193f5d4747b883c41826b Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 5 Jul 2023 18:08:54 +0200 Subject: [PATCH] Dip the regex set into caramell - hmmm --- .../org/pgpainless/wot/dijkstra/sq/RegexSet.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/RegexSet.kt b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/RegexSet.kt index ce332dbb..91289e77 100644 --- a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/RegexSet.kt +++ b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/RegexSet.kt @@ -43,16 +43,9 @@ data class RegexSet(val regexStrings: Set) { * 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 { - if (regexStrings.isEmpty()) { - return true + // wildcard or any match + 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 } } \ No newline at end of file