From db971f6b2bd8e005405f861c704000cfaadcd804 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 15 Dec 2019 16:45:31 +0000 Subject: [PATCH] Convert indefiniteArticle() to an extension method --- .../dev/openrs2/deob/remap/TypedRemapper.java | 3 ++- .../main/java/dev/openrs2/util/StringUtils.kt | 18 ++++++++---------- .../java/dev/openrs2/util/StringUtilsTest.kt | 7 +++---- 3 files changed, 13 insertions(+), 15 deletions(-) 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 e6e206c5..0027aca1 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 e9be44a7..125e5425 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 d63374e6..a62e7479 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() } }