From 1cf1f68672d07767ed93150dd32094234eddd70c Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sun, 3 Dec 2023 19:18:06 -0800 Subject: Internal Change: Remove String.matchRegex() function Usages (#641) Code cleanup and removed .matchRegex() #641 --- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 29 ++++++++++++---------- .../at/hannibal2/skyhanni/utils/StringUtils.kt | 4 --- 2 files changed, 16 insertions(+), 17 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index ae9c24092..420f3decb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -8,7 +8,7 @@ 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.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.GsonBuilder import com.google.gson.JsonObject @@ -25,6 +25,20 @@ import kotlin.time.Duration.Companion.seconds object ItemUtils { + // TODO USE SH-REPO + private val patternInFront = "(?: *§8(\\+§\\w)?(?[\\d.km,]+)(x )?)?(?.*)".toPattern() + private val patternBehind = "(?(?:['\\w-]+ ?)+)(?:§8x(?[\\d,]+))?".toPattern() + private val petLevelPattern = "\\[Lvl (.*)] (.*)".toPattern() + + private val ignoredPetStrings = listOf( + "Archer", + "Berserk", + "Mage", + "Tank", + "Healer", + "➡", + ) + fun ItemStack.cleanName() = this.displayName.removeColor() fun isSack(stack: ItemStack) = stack.getInternalName().endsWith("_SACK") && stack.cleanName().endsWith(" Sack") @@ -51,14 +65,7 @@ object ItemUtils { fun isRecombobulated(stack: ItemStack) = stack.isRecombobulated() - fun isPet(name: String): Boolean = name.matchRegex("\\[Lvl (.*)] (.*)") && !listOf( - "Archer", - "Berserk", - "Mage", - "Tank", - "Healer", - "➡", - ).any { name.contains(it) } + fun isPet(name: String): Boolean = petLevelPattern.matches(name) && !ignoredPetStrings.any { name.contains(it) } fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 @@ -253,10 +260,6 @@ object ItemUtils { fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false - // TODO USE SH-REPO - private val patternInFront = "(?: *§8(\\+§[\\w])?(?[\\d.km,]+)(x )?)?(?.*)".toPattern() - private val patternBehind = "(?(?:['\\w-]+ ?)+)(?:§8x(?[\\d,]+))?".toPattern() - private val itemAmountCache = mutableMapOf>() fun readItemAmount(originalInput: String): Pair? { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index ccfe97b42..f8ab9d092 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -7,7 +7,6 @@ import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiUtilRenderComponents import net.minecraft.util.ChatComponentText import net.minecraft.util.IChatComponent -import org.intellij.lang.annotations.Language import java.util.Base64 import java.util.NavigableMap import java.util.UUID @@ -77,9 +76,6 @@ object StringUtils { return toString().replace("-", "") } - @Deprecated("Do not create a regex pattern each time.", ReplaceWith("toPattern()")) - fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - private fun String.removeAtBeginning(text: String): String = if (this.startsWith(text)) substring(text.length) else this -- cgit