Convert indefiniteArticle() to an extension method

master
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.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) {

@ -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()
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()

@ -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()
}
}

Loading…
Cancel
Save