summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorappable <enzospiacitelli@gmail.com>2023-03-23 04:25:28 -0700
committerGitHub <noreply@github.com>2023-03-23 12:25:28 +0100
commite7c8613f2bfbf5c93479e63c5d6fca78b525cfc4 (patch)
treee740c96a60ff2ec44434a5c525aebd5cbe51831f /src/main/java/at/hannibal2/skyhanni/utils
parent178f081be7b877aea7c1e965135fa1d9b87714d0 (diff)
downloadskyhanni-e7c8613f2bfbf5c93479e63c5d6fca78b525cfc4.tar.gz
skyhanni-e7c8613f2bfbf5c93479e63c5d6fca78b525cfc4.tar.bz2
skyhanni-e7c8613f2bfbf5c93479e63c5d6fca78b525cfc4.zip
Merge pull request #20
* regex for trophy fish + customizable formatting options * hide duplicate fish * don't load trophy fish repeatedly per profile + cleanup * rework config option for readability * i messed up the regex in two ways that somehow cancelled out, but thi… * using config instead of SkyHanniMod.feature.fishing everywhere * Added to changelog files and give credits
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 6da701b78..397613f40 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.utils.NumberUtil.addSuffix
import java.text.NumberFormat
import java.util.*
import java.util.regex.Pattern
@@ -74,17 +75,25 @@ object NumberUtil {
return (this * scale).roundToInt().toFloat() / scale
}
- fun Number.addSuffix(): String {
+ fun Number.ordinal(): String {
val long = this.toLong()
- if (long in 11..13) return "${this}th"
+ if (long % 100 in 11..13) return "th"
return when (long % 10) {
- 1L -> "${this}st"
- 2L -> "${this}nd"
- 3L -> "${this}rd"
- else -> "${this}th"
+ 1L -> "st"
+ 2L -> "nd"
+ 3L -> "rd"
+ else -> "th"
}
}
+ fun Number.addSuffix(): String {
+ return this.toString() + this.ordinal()
+ }
+
+ fun Number.addSeparators(): String {
+ return NumberFormat.getNumberInstance().format(this)
+ }
+
fun String.romanToDecimalIfNeeded() = toIntOrNull() ?: romanToDecimal()
/**