Skip to content

Commit

Permalink
add index options
Browse files Browse the repository at this point in the history
Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com>
  • Loading branch information
j10a1n15 committed Jul 24, 2024
1 parent 3990a5d commit 35f15df
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package me.partlysanestudios.partlysaneskies.utils
import me.partlysanestudios.partlysaneskies.PartlySaneSkies
import java.awt.Color
import java.text.DecimalFormat
import java.util.Locale
import java.util.regex.Pattern

object StringUtils {
Expand Down Expand Up @@ -408,14 +407,13 @@ object StringUtils {
}
}

fun String.lastUsedColorCode(): String? {
val colorCodes = "0123456789abcdefklmnor"
val colorCode = colorCodes.indexOfLast { this.contains("§$it") }
return if (colorCode != -1) {
"§${colorCodes[colorCode]}"
} else {
null
}
}
fun String.lastUsedColorCode(startIndex: Int = 0, endIndex: Int = this.length - 1): String? {
val colorCodes = "0123456789abcdef"
val regex = Regex("§[${colorCodes}]")

val subString = this.substring(startIndex, endIndex + 1)
val matches = regex.findAll(subString)

return matches.lastOrNull()?.value
}
}

0 comments on commit 35f15df

Please sign in to comment.