diff options
author | Linnea Gräf <nea@nea.moe> | 2024-10-13 17:32:10 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-10-13 17:32:10 +0200 |
commit | e6142bb93619dee768fc18b87ffdd28558d4bcab (patch) | |
tree | 03df79712151f7579cd683c8340741ebb3191822 /src/main/kotlin/util/regex.kt | |
parent | daa63bd914a2f6c5e9b668abb8474884685ee818 (diff) | |
download | Firmament-e6142bb93619dee768fc18b87ffdd28558d4bcab.tar.gz Firmament-e6142bb93619dee768fc18b87ffdd28558d4bcab.tar.bz2 Firmament-e6142bb93619dee768fc18b87ffdd28558d4bcab.zip |
Make pickaxe ability display use AbilityUtils
[no changelog]
Diffstat (limited to 'src/main/kotlin/util/regex.kt')
-rw-r--r-- | src/main/kotlin/util/regex.kt | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/kotlin/util/regex.kt b/src/main/kotlin/util/regex.kt index 78c90e8..a44435c 100644 --- a/src/main/kotlin/util/regex.kt +++ b/src/main/kotlin/util/regex.kt @@ -1,8 +1,14 @@ +@file:OptIn(ExperimentalTypeInference::class, ExperimentalContracts::class) + package moe.nea.firmament.util import java.util.regex.Matcher import java.util.regex.Pattern import org.intellij.lang.annotations.Language +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract +import kotlin.experimental.ExperimentalTypeInference import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -10,10 +16,14 @@ import kotlin.time.Duration.Companion.seconds 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) +inline fun <T> Pattern.useMatch(string: String, block: Matcher.() -> T): T? { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + } + return matcher(string) .takeIf(Matcher::matches) ?.let(block) +} @Language("RegExp") val TIME_PATTERN = "[0-9]+[ms]" |