lower case of turkish character dotted i

2019-01-25 17:41发布

问题:

In Java 6,

System.out.println(String.valueOf('\u0130').toLowerCase());

prints i (u0069), but in Java 7 it prints i with double dots (u0069 u0307).

I understand it is a Turkish character, but how do I make Java 7 print the same output as v6 using this code?

System.out.println(inputText.toLowerCase());

Also make sure that the code can handle international text without hardcoding the toLowerCase function to use only Turkish locale.

回答1:

There is a quite detailed blog post about this i toLowerCase problem


Let me try to summarize the essential parts:

In Java 7 this method has indeed changed and handles this char differently than Java 6. The following code was added:

} else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
    lowerChar = Character.ERROR;
}

==> This change results in the following way:

Basically the end result of this change is that for this specific case (the upper-case dotted I), Java 7 now consults a special Unicode character database (http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt), which provides data on complex case-mappings. Looking at this file you can see several lines for the upper-case dotted I:

CODE       LOWER   TITLE   UPPER  LANGUAGE
0130;  0069 0307;   0130;   0130;
0130;  0069;        0130;   0130;       tr;
0130;  0069;        0130;   0130;       az;