From ac151c8ebc4c5546795cdbf5b0c179183e2c71d1 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Mon, 15 Jan 2024 00:32:43 +0100 Subject: Add Pristine Profit Tracker --- src/main/kotlin/moe/nea/firmament/util/regex.kt | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/main/kotlin/moe/nea/firmament/util/regex.kt') diff --git a/src/main/kotlin/moe/nea/firmament/util/regex.kt b/src/main/kotlin/moe/nea/firmament/util/regex.kt index 97c2797..4cc3f03 100644 --- a/src/main/kotlin/moe/nea/firmament/util/regex.kt +++ b/src/main/kotlin/moe/nea/firmament/util/regex.kt @@ -6,5 +6,13 @@ package moe.nea.firmament.util +import java.util.regex.Matcher +import java.util.regex.Pattern + inline fun String.ifMatches(regex: Regex, block: (MatchResult) -> T): T? = regex.matchEntire(this)?.let(block) + +inline fun Pattern.useMatch(string: String, block: Matcher.() -> T): T? = + matcher(string) + .takeIf(Matcher::matches) + ?.let(block) -- cgit