diff --git a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java index e6e206c516..0027aca132 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java +++ b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java @@ -11,6 +11,7 @@ import dev.openrs2.asm.MemberRef; import dev.openrs2.asm.classpath.ClassMetadata; import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.util.StringUtils; +import dev.openrs2.util.StringUtilsKt; import dev.openrs2.util.collect.DisjointSet; import org.objectweb.asm.Type; import org.objectweb.asm.commons.Remapper; @@ -165,7 +166,7 @@ public final class TypedRemapper extends Remapper { throw new IllegalArgumentException("Unknown field type " + type); } - prefix = StringUtils.indefiniteArticle(prefix) + StringUtils.capitalize(prefix); + prefix = StringUtilsKt.indefiniteArticle(prefix) + StringUtils.capitalize(prefix); var mappedName = generateName(prefixes, prefix); for (var field : partition) { diff --git a/util/src/main/java/dev/openrs2/util/StringUtils.kt b/util/src/main/java/dev/openrs2/util/StringUtils.kt index e9be44a7d8..125e5425e5 100644 --- a/util/src/main/java/dev/openrs2/util/StringUtils.kt +++ b/util/src/main/java/dev/openrs2/util/StringUtils.kt @@ -1,18 +1,16 @@ package dev.openrs2.util -object StringUtils { - // TODO(gpe): convert to an extension function - @JvmStatic - fun indefiniteArticle(str: String): String { - require(str.isNotEmpty()) +fun CharSequence.indefiniteArticle(): String { + require(isNotEmpty()) - val first = str.first().toLowerCase() - return when (first) { - 'a', 'e', 'i', 'o', 'u' -> "an" - else -> "a" - } + val first = first().toLowerCase() + return when (first) { + 'a', 'e', 'i', 'o', 'u' -> "an" + else -> "a" } +} +object StringUtils { @JvmStatic fun capitalize(str: String): String { return str.capitalize() diff --git a/util/src/test/java/dev/openrs2/util/StringUtilsTest.kt b/util/src/test/java/dev/openrs2/util/StringUtilsTest.kt index d63374e6cc..a62e747952 100644 --- a/util/src/test/java/dev/openrs2/util/StringUtilsTest.kt +++ b/util/src/test/java/dev/openrs2/util/StringUtilsTest.kt @@ -1,7 +1,6 @@ package dev.openrs2.util import dev.openrs2.util.StringUtils.capitalize -import dev.openrs2.util.StringUtils.indefiniteArticle import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -9,10 +8,10 @@ import kotlin.test.assertFailsWith object StringUtilsTest { @Test fun testIndefiniteArticle() { - assertEquals("a", indefiniteArticle("book")) - assertEquals("an", indefiniteArticle("aeroplane")) + assertEquals("a", "book".indefiniteArticle()) + assertEquals("an", "aeroplane".indefiniteArticle()) assertFailsWith(IllegalArgumentException::class) { - indefiniteArticle("") + "".indefiniteArticle() } }