aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ComponentMatcherUtils.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MobUtils.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt52
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SkyblockSeason.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt2
12 files changed, 77 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ComponentMatcherUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ComponentMatcherUtils.kt
index f5c25ab2b..9faa3cd74 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ComponentMatcherUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ComponentMatcherUtils.kt
@@ -6,8 +6,8 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.ComponentMatcherUtils.findStyledMatcher
import at.hannibal2.skyhanni.utils.ComponentMatcherUtils.intoSpan
import at.hannibal2.skyhanni.utils.ComponentMatcherUtils.matchStyledMatcher
-import at.hannibal2.skyhanni.utils.StringUtils.findMatcher
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.findMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChatStyle
import net.minecraft.util.IChatComponent
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt
index e1a277d36..37849d79a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt
@@ -2,8 +2,8 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 90ef85025..cf5cc266e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -5,12 +5,12 @@ import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
-import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.removeResets
import com.google.gson.GsonBuilder
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index d07f3b149..2a351a7d9 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -352,8 +352,10 @@ object LorenzUtils {
* Get the group, otherwise, return null
* @param groupName The group name in the pattern
*/
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.groupOrNull"))
fun Matcher.groupOrNull(groupName: String): String? = runCatching { this.group(groupName) }.getOrNull()
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.hasGroup"))
fun Matcher.hasGroup(groupName: String): Boolean = groupOrNull(groupName) != null
fun inAdvancedMiningIsland() =
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
index 5b6d9e8c8..dde61c7c1 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
@@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MobUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/MobUtils.kt
index 6aff6406d..76b603542 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/MobUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/MobUtils.kt
@@ -5,7 +5,7 @@ import at.hannibal2.skyhanni.data.mob.MobData
import at.hannibal2.skyhanni.utils.EntityUtils.cleanName
import at.hannibal2.skyhanni.utils.LocationUtils.distanceTo
import at.hannibal2.skyhanni.utils.LocationUtils.rayIntersects
-import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index d533dfc42..742bc3654 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
-import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
import java.text.NumberFormat
import java.util.TreeMap
import kotlin.math.pow
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt
new file mode 100644
index 000000000..f12ecdef6
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RegexUtils.kt
@@ -0,0 +1,52 @@
+package at.hannibal2.skyhanni.utils
+
+import java.util.regex.Matcher
+import java.util.regex.Pattern
+
+object RegexUtils {
+ inline fun <T> Pattern.matchMatcher(text: String, consumer: Matcher.() -> T) =
+ matcher(text).let { if (it.matches()) consumer(it) else null }
+
+ inline fun <T> Pattern.findMatcher(text: String, consumer: Matcher.() -> T) =
+ matcher(text).let { if (it.find()) consumer(it) else null }
+
+ inline fun <T> Sequence<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? =
+ toList().matchFirst(pattern, consumer)
+
+ inline fun <T> List<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? {
+ for (line in this) {
+ pattern.matcher(line).let { if (it.matches()) return consumer(it) }
+ }
+ return null
+ }
+
+ inline fun <T> List<String>.matchAll(pattern: Pattern, consumer: Matcher.() -> T): T? {
+ for (line in this) {
+ pattern.matcher(line).let { if (it.find()) consumer(it) }
+ }
+ return null
+ }
+
+ inline fun <T> List<Pattern>.matchMatchers(text: String, consumer: Matcher.() -> T): T? {
+ for (pattern in iterator()) {
+ pattern.matchMatcher<T>(text) {
+ return consumer()
+ }
+ }
+ return null
+ }
+
+ fun Pattern.matches(string: String?): Boolean = string?.let { matcher(it).matches() } ?: false
+ fun Pattern.find(string: String?) = string?.let { matcher(it).find() } ?: false
+
+ fun Pattern.anyMatches(list: List<String>?): Boolean = list?.any { this.matches(it) } ?: false
+ fun Pattern.anyMatches(list: Sequence<String>?): Boolean = anyMatches(list?.toList())
+
+ /**
+ * Get the group, otherwise, return null
+ * @param groupName The group name in the pattern
+ */
+ fun Matcher.groupOrNull(groupName: String): String? = runCatching { this.group(groupName) }.getOrNull()
+
+ fun Matcher.hasGroup(groupName: String): Boolean = groupOrNull(groupName) != null
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyblockSeason.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyblockSeason.kt
index fb596bea7..edeb706b7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/SkyblockSeason.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyblockSeason.kt
@@ -1,6 +1,6 @@
package at.hannibal2.skyhanni.utils
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.UtilsPatterns.seasonPattern
import kotlin.time.Duration.Companion.seconds
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index 4e87646fe..305c825f7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -100,15 +100,19 @@ object StringUtils {
fun UUID.toDashlessUUID(): String = toString().replace("-", "")
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.matchMatcher(text, consumer)"))
inline fun <T> Pattern.matchMatcher(text: String, consumer: Matcher.() -> T) =
matcher(text).let { if (it.matches()) consumer(it) else null }
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.matchMatcher(text, consumer)"))
inline fun <T> Pattern.findMatcher(text: String, consumer: Matcher.() -> T) =
matcher(text).let { if (it.find()) consumer(it) else null }
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.matchFirst(pattern, consumer)"))
inline fun <T> Sequence<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? =
toList().matchFirst(pattern, consumer)
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.matchFirst(pattern, consumer)"))
inline fun <T> List<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? {
for (line in this) {
pattern.matcher(line).let { if (it.matches()) return consumer(it) }
@@ -116,6 +120,7 @@ object StringUtils {
return null
}
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.matchAll(pattern, consumer)"))
inline fun <T> List<String>.matchAll(pattern: Pattern, consumer: Matcher.() -> T): T? {
for (line in this) {
pattern.matcher(line).let { if (it.find()) consumer(it) }
@@ -143,6 +148,7 @@ object StringUtils {
}
}
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.matchMatchers(text, consumer)"))
inline fun <T> List<Pattern>.matchMatchers(text: String, consumer: Matcher.() -> T): T? {
for (pattern in iterator()) {
pattern.matchMatcher<T>(text) {
@@ -312,10 +318,16 @@ object StringUtils {
fun String.convertToFormatted(): String = this.replace("&&", "ยง")
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.matches(string)"))
fun Pattern.matches(string: String?): Boolean = string?.let { matcher(it).matches() } ?: false
+
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.anyMatches(list)"))
fun Pattern.anyMatches(list: List<String>?): Boolean = list?.any { this.matches(it) } ?: false
+
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.anyMatches(list)"))
fun Pattern.anyMatches(list: Sequence<String>?): Boolean = anyMatches(list?.toList())
+ @Deprecated("Use the new one instead", ReplaceWith("RegexUtils.find(string)"))
fun Pattern.find(string: String?) = string?.let { matcher(it).find() } ?: false
fun String.allLettersFirstUppercase() = split("_").joinToString(" ") { it.firstLetterUppercase() }
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index e1fbddf5d..78213df56 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.mixins.hooks.tryToReplaceScoreboardLine
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import java.time.LocalDate
import java.time.ZoneId
import kotlin.time.Duration
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
index 09cd4f730..18cfb55c5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
@@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.events.PreInitFinishedEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.utils.ConditionalUtils.afterChange
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
import net.minecraft.launchwrapper.Launch
import net.minecraftforge.fml.common.FMLCommonHandler
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent