Convert indefiniteArticle() to an extension method

bzip2
Graham 5 years ago
parent b32c691148
commit db971f6b2b
  1. 3
      deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java
  2. 10
      util/src/main/java/dev/openrs2/util/StringUtils.kt
  3. 7
      util/src/test/java/dev/openrs2/util/StringUtilsTest.kt

@ -11,6 +11,7 @@ import dev.openrs2.asm.MemberRef;
import dev.openrs2.asm.classpath.ClassMetadata; import dev.openrs2.asm.classpath.ClassMetadata;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.util.StringUtils; import dev.openrs2.util.StringUtils;
import dev.openrs2.util.StringUtilsKt;
import dev.openrs2.util.collect.DisjointSet; import dev.openrs2.util.collect.DisjointSet;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.commons.Remapper;
@ -165,7 +166,7 @@ public final class TypedRemapper extends Remapper {
throw new IllegalArgumentException("Unknown field type " + type); 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); var mappedName = generateName(prefixes, prefix);
for (var field : partition) { for (var field : partition) {

@ -1,18 +1,16 @@
package dev.openrs2.util package dev.openrs2.util
object StringUtils { fun CharSequence.indefiniteArticle(): String {
// TODO(gpe): convert to an extension function require(isNotEmpty())
@JvmStatic
fun indefiniteArticle(str: String): String {
require(str.isNotEmpty())
val first = str.first().toLowerCase() val first = first().toLowerCase()
return when (first) { return when (first) {
'a', 'e', 'i', 'o', 'u' -> "an" 'a', 'e', 'i', 'o', 'u' -> "an"
else -> "a" else -> "a"
} }
} }
object StringUtils {
@JvmStatic @JvmStatic
fun capitalize(str: String): String { fun capitalize(str: String): String {
return str.capitalize() return str.capitalize()

@ -1,7 +1,6 @@
package dev.openrs2.util package dev.openrs2.util
import dev.openrs2.util.StringUtils.capitalize import dev.openrs2.util.StringUtils.capitalize
import dev.openrs2.util.StringUtils.indefiniteArticle
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
@ -9,10 +8,10 @@ import kotlin.test.assertFailsWith
object StringUtilsTest { object StringUtilsTest {
@Test @Test
fun testIndefiniteArticle() { fun testIndefiniteArticle() {
assertEquals("a", indefiniteArticle("book")) assertEquals("a", "book".indefiniteArticle())
assertEquals("an", indefiniteArticle("aeroplane")) assertEquals("an", "aeroplane".indefiniteArticle())
assertFailsWith(IllegalArgumentException::class) { assertFailsWith(IllegalArgumentException::class) {
indefiniteArticle("") "".indefiniteArticle()
} }
} }

Loading…
Cancel
Save