String.equalsIgnoreCase - UpperCase v.小写
我正在浏览openjdk,注意到String.equalsIgnoreCase中有一个奇怪的代码路径,特别是方法区域Matches:
if (ignoreCase) {
// If characters don't match but case may be ignored,
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
}
我理解关于调整特定字母表以检查小写相等性的评论,但想知道为什么还要进行大写检查?为什么不只做所有小写?