45 lines
No EOL
918 B
Text
45 lines
No EOL
918 B
Text
|
|
|
|
class StringUtil{
|
|
static possesive(string){
|
|
if(string.endsWith("s")){
|
|
return "%(string)'"
|
|
} else {
|
|
return "%(string)'s"
|
|
}
|
|
}
|
|
|
|
static plural(string){
|
|
if(string.endsWith("s")){
|
|
return "%(string)'"
|
|
} else {
|
|
return "%(string)s"
|
|
}
|
|
}
|
|
|
|
//todo: this doesnt cover all cases perfectly, add more
|
|
static a(string){
|
|
var firstChar = string[0]
|
|
if(isVowel(firstChar)){
|
|
return "an %(string)"
|
|
} else {
|
|
return "a %(string)"
|
|
}
|
|
}
|
|
|
|
static isVowel(char){
|
|
return "aeiou".contains(char)
|
|
}
|
|
|
|
//todo: do
|
|
static capitalize(string){
|
|
return string
|
|
}
|
|
|
|
//todo: ths ignores words that arent preceeded by a space like (this) or "this". maybe fix that?
|
|
static capitalize_all(string){
|
|
var words = string.split(" ")
|
|
words = words.map{|word| capitalize(word)}
|
|
return words.join(" ")
|
|
}
|
|
} |