diff options
| author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-08-31 22:31:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-31 22:31:55 +0200 |
| commit | 79d891d5a3e1bffd31491a921757ccf7ab66b5fe (patch) | |
| tree | f6fd36060dd3764ecf81295f77a0aecf68e82364 /src/main/java/at/hannibal2/skyhanni/utils | |
| parent | c834fbbb6a535b0c0c27d02c893433e687332268 (diff) | |
| download | skyhanni-79d891d5a3e1bffd31491a921757ccf7ab66b5fe.tar.gz skyhanni-79d891d5a3e1bffd31491a921757ccf7ab66b5fe.tar.bz2 skyhanni-79d891d5a3e1bffd31491a921757ccf7ab66b5fe.zip | |
Feature: Bits on Cookie (#2265)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt | 10 |
1 files changed, 10 insertions, 0 deletions
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 <T> Pattern.firstMatcherWithIndex(sequence: Sequence<String>, 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 <T> List<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? = pattern.firstMatcher(this, consumer) inline fun <T> Pattern.firstMatcher(list: List<String>, consumer: Matcher.() -> T): T? = firstMatcher(list.asSequence(), consumer) + inline fun <T> Pattern.firstMatcherWithIndex(list: List<String>, consumer: Matcher.(Int) -> T): T? = + firstMatcherWithIndex(list.asSequence(), consumer) + @Deprecated("", ReplaceWith("pattern.matchAll(this) { consumer() }")) inline fun <T> List<String>.matchAll(pattern: Pattern, consumer: Matcher.() -> T): T? = pattern.matchAll(this, consumer) |
