/* * SPDX-FileCopyrightText: 2023 Linnea Gräf * * SPDX-License-Identifier: GPL-3.0-or-later */ 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)