- Я загружаю таблицы Unicode
- импортирую таблицы в базу данных
- Я пишу метод upper ().
Вот пример реализации;)
public static String upper(String s) {
if (s == null) {
return null;
}
final int N = s.length(); // Mind the optimization!
PreparedStatement stmtName = null;
PreparedStatement stmtSmall = null;
ResultSet rsName = null;
ResultSet rsSmall = null;
StringBuilder buffer = new StringBuilder (N); // Much faster than StringBuffer!
try {
conn = DBFactory.getConnection();
stmtName = conn.prepareStatement("select name from unicode.chart where codepoint = ?");
// TODO Optimization: Maybe move this in the if() so we don't create this
// unless there are uppercase characters in the string.
stmtSmall = conn.prepareStatement("select codepoint from unicode.chart where name = ?");
for (int i=0; i<N; i++) {
int c = s.charAt(i);
stmtName.setInt(1, c);
rsName = stmtName.execute();
if (rsName.next()) {
String name = rsName.getString(1);
if (name.contains(" SMALL ")) {
name = name.replaceAll(" SMALL ", " CAPITAL ");
stmtSmall.setString(1, name);
rsSmall = stmtSmall.execute();
if (rsSmall.next()) {
c = rsSmall.getInt(1);
}
rsSmall = DBUtil.close(rsSmall);
}
}
rsName = DBUtil.close(rsName);
}
}
finally {
// Always clean up
rsSmall = DBUtil.close(rsSmall);
rsName = DBUtil.close(rsName);
stmtSmall = DBUtil.close(stmtSmall);
stmtName = DBUtil.close(stmtName);
}
// TODO Optimization: Maybe read the table once into RAM at the start
// Would waste a lot of memory, though :/
return buffer.toString();
}
;)
Примечание. Диаграммы Unicode, которые вы можете найти на unicode.org , содержат имя символа / кодовой точки. Эта строка будет содержать «SMALL» для символов в верхнем регистре (обратите внимание на пробелы, или она может совпадать с «SMALLER» и т. П.). Теперь вы можете искать похожее имя с «МАЛЫМ», замененным «КАПИТАЛОМ». Если вы найдете его, вы нашли его версию.