From b4a93bd7515ffd8f1fcbcf5315729ddd36b0166a Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 7 Mar 2025 00:21:38 +0100 Subject: feat: Add block breaking indicators to jade --- src/main/kotlin/util/regex.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/main/kotlin/util/regex.kt') diff --git a/src/main/kotlin/util/regex.kt b/src/main/kotlin/util/regex.kt index a44435c..f239810 100644 --- a/src/main/kotlin/util/regex.kt +++ b/src/main/kotlin/util/regex.kt @@ -16,12 +16,13 @@ import kotlin.time.Duration.Companion.seconds 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? { +inline fun Pattern.useMatch(string: String?, block: Matcher.() -> T): T? { contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } - return matcher(string) - .takeIf(Matcher::matches) + return string + ?.let(this::matcher) + ?.takeIf(Matcher::matches) ?.let(block) } -- cgit