aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/regex.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-01-15 00:32:43 +0100
committerLinnea Gräf <nea@nea.moe>2024-01-17 21:10:51 +0100
commitac151c8ebc4c5546795cdbf5b0c179183e2c71d1 (patch)
tree52141110008ba6809d0dde5bc4456fc37e6a665a /src/main/kotlin/moe/nea/firmament/util/regex.kt
parentc49b65835d37266508561e60782bda36275fb8ae (diff)
downloadfirmament-ac151c8ebc4c5546795cdbf5b0c179183e2c71d1.tar.gz
firmament-ac151c8ebc4c5546795cdbf5b0c179183e2c71d1.tar.bz2
firmament-ac151c8ebc4c5546795cdbf5b0c179183e2c71d1.zip
Add Pristine Profit Tracker
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/regex.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/regex.kt8
1 files changed, 8 insertions, 0 deletions
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 <T> String.ifMatches(regex: Regex, block: (MatchResult) -> T): T? =
regex.matchEntire(this)?.let(block)
+
+inline fun <T> Pattern.useMatch(string: String, block: Matcher.() -> T): T? =
+ matcher(string)
+ .takeIf(Matcher::matches)
+ ?.let(block)