同じものが必要だったので、私はこれを作ることになりました:
/**
* Given a letter and an accent, return the char with the accent included.
*
* @param accentCode: The accent char; i.e '~', '´';
* @param letter: Letter to put accent in it.
* @return: Char with {@code letter} with accent if it was a valid letter.
*/
public static int getAccent(char accentChar, int letter) {
int index = 0;
boolean upperCase = false;
for (char vogal : vogalList) {
if (letter == vogal) {
if (index >= 5) {
index -= 5;
upperCase = true;
}
for (int accentType = 0; accentType < convertTable.length; accentType++) {
if (convertTable[accentType][0] == accentChar) {
char converted = convertTable[accentType][index + 1];
if (converted != '-') {
if (upperCase)
converted = Character.toUpperCase(converted);
return converted;
}
}
}
}
index++;
}
return letter;
}
/**
* Verify if {@code charID} is an accent character;
*
* @param charID: Character code id to be verified.
* @return: true in case {@code charID} is an accent character id.
*/
public static boolean isAccent(int charID) {
for (int i = 0; i < convertTable.length; i++) {
if (convertTable[i][0] == charID)
return true;
}
return false;
}
private static final char[] vogalList = { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
private static final char[][] convertTable = { { '´', 'á', 'é', 'í', 'ó', 'ú' }, { '`', 'à', 'è', 'ì', 'ò', 'ù' }, { '^', 'â', 'ê', 'î', 'ô', 'û' }, { '~', 'ã', '-', '-', 'õ', '-' }, { '¨', 'ä', 'ë', 'ï', 'ö', 'ü' } };