Lang lib tries to determine correct article for nouns

This commit is contained in:
Maxmtg
2013-05-29 14:44:25 +00:00
parent d733ddc7c7
commit 066d45fbc3
2 changed files with 21 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ public class DrawEffect extends SpellAbilityEffect {
sb.append(" each"); sb.append(" each");
} }
sb.append(Lang.joinVerb(tgtPlayers, " draw")).append(" "); sb.append(Lang.joinVerb(tgtPlayers, " draw")).append(" ");
sb.append(Lang.nounWithAmount(numCards, " card")); sb.append(Lang.nounWithAmount(numCards, "card"));
sb.append("."); sb.append(".");
} }

View File

@@ -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"); final String strCount;
return String.valueOf(cnt) + " " + noun + suffix; 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;
}
} }