mirror of
https://gist.github.com/7ed3c3ef3b56e47b27dbf6153da0d7d9.git
synced 2025-04-24 21:27:12 -07:00
This commit is contained in:
commit
67308d3ec3
1 changed files with 17 additions and 0 deletions
17
Plural.kt
Normal file
17
Plural.kt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
fun String.plural(size: Int): String {
|
||||||
|
val consonants = "bcdfghjklmnpqrstvwxz"
|
||||||
|
|
||||||
|
if (size > 1 && this.length > 2) {
|
||||||
|
if ((this.endsWith("o", true) || this.endsWith("s", true)) &&
|
||||||
|
consonants.contains(this[this.length - 2], true)) {
|
||||||
|
return this + "es"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.endsWith("y", true) &&
|
||||||
|
consonants.contains(this[this.length - 2], true)) {
|
||||||
|
return this + "ies"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this + "s"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue