diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/regex.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/regex.kt | 8 |
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) |