mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Lang lib tries to determine correct article for nouns
This commit is contained in:
@@ -49,9 +49,13 @@ public class Lang {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> String nounWithAmount(int cnt, String noun) {
|
public static <T> String nounWithAmount(int cnt, String noun) {
|
||||||
// Simpliest check
|
|
||||||
String suffix = cnt <= 1 ? "" : ( noun.endsWith("s") || noun.endsWith("x") ? "es" : "s");
|
String suffix = cnt <= 1 ? "" : ( noun.endsWith("s") || noun.endsWith("x") ? "es" : "s");
|
||||||
return String.valueOf(cnt) + " " + noun + suffix;
|
final String strCount;
|
||||||
|
if( cnt == 1 )
|
||||||
|
strCount = startsWithVowel(noun) ? "an " : "a ";
|
||||||
|
else
|
||||||
|
strCount = String.valueOf(cnt) + " ";
|
||||||
|
return strCount + noun + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,4 +66,17 @@ public class Lang {
|
|||||||
public static String getPossesive(String name) {
|
public static String getPossesive(String name) {
|
||||||
return name.endsWith("s") ? name + "'" : name + "'s";
|
return name.endsWith("s") ? name + "'" : name + "'s";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean startsWithVowel(String word) {
|
||||||
|
return isVowel(word.trim().charAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final char[] vowels = { 'a', 'i', 'e', 'o', 'u' };
|
||||||
|
public static boolean isVowel(char letter) {
|
||||||
|
char l = Character.toLowerCase(letter);
|
||||||
|
for(char c : vowels)
|
||||||
|
if ( c == l ) return true;
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user