From 79d891d5a3e1bffd31491a921757ccf7ab66b5fe Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:31:55 +0200 Subject: Feature: Bits on Cookie (#2265) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt index 068dfce1d..4faa9969c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt @@ -21,11 +21,21 @@ object RegexUtils { return null } + inline fun Pattern.firstMatcherWithIndex(sequence: Sequence, consumer: Matcher.(Int) -> T): T? { + for ((index, line) in sequence.withIndex()) { + matcher(line).let { if (it.matches()) return consumer(it, index) } + } + return null + } + @Deprecated("", ReplaceWith("pattern.firstMatcher(this) { consumer() }")) inline fun List.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? = pattern.firstMatcher(this, consumer) inline fun Pattern.firstMatcher(list: List, consumer: Matcher.() -> T): T? = firstMatcher(list.asSequence(), consumer) + inline fun Pattern.firstMatcherWithIndex(list: List, consumer: Matcher.(Int) -> T): T? = + firstMatcherWithIndex(list.asSequence(), consumer) + @Deprecated("", ReplaceWith("pattern.matchAll(this) { consumer() }")) inline fun List.matchAll(pattern: Pattern, consumer: Matcher.() -> T): T? = pattern.matchAll(this, consumer) -- cgit