Add hash function used by pre-JS5 caches

Signed-off-by: Graham <gpe@openrs2.org>
Graham 3 years ago
parent de1ea8bc6f
commit 5cbaf55dd6
  1. 8
      util/src/main/kotlin/org/openrs2/util/StringUtils.kt
  2. 6
      util/src/test/kotlin/org/openrs2/util/StringUtilsTest.kt

@ -19,6 +19,14 @@ public fun CharSequence.krHashCode(): Int {
return hash return hash
} }
public fun CharSequence.jagHashCode(): Int {
var hash = 0
for (c in this) {
hash = (hash * 61) + (c.code - 32)
}
return hash
}
public fun String.capitalize(): String { public fun String.capitalize(): String {
return replaceFirstChar { it.titlecase() } return replaceFirstChar { it.titlecase() }
} }

@ -21,6 +21,12 @@ class StringUtilsTest {
assertEquals(92340183, "h€llo".krHashCode()) assertEquals(92340183, "h€llo".krHashCode())
} }
@Test
fun testJagHashCode() {
assertEquals(0, "".jagHashCode())
assertEquals(1012849752, "hello".jagHashCode())
}
@Test @Test
fun testCapitalize() { fun testCapitalize() {
assertEquals("Hello", "hello".capitalize()) assertEquals("Hello", "hello".capitalize())

Loading…
Cancel
Save