Separating Unicode ligature characters

后端 未结 3 1141
忘了有多久
忘了有多久 2020-12-18 18:45

Throughout the vast number of unicode characters, there are some that actually represent more than one character, like the U+FB00 ligature ff for two \'f\' characters. Is the

相关标签:
3条回答
  • 2020-12-18 19:25

    U+FB00 is a compatibility character. Normally Unicode doesn't support separate codepoints for ligatures (arguing that it's a layout decision if and when a ligature should be used and should not influence how the data is stored). A few of those still exist to allow round-trip conversion compatibility with older encodings that do represent ligatures as separate entities.

    Luckily, the information which characters the ligature represents is present in the Unicode data file and most capable string handling systems have that data built-in.

    In Java, you'll need to use the Normalizer class and the NFKC form:

    String ff ="\uFB00";
    String normalized = Normalizer.normalize(ff, Form.NFKC);
    System.out.println(ff + " = " + normalized);
    

    This will print

    ff = ff
    0 讨论(0)
  • 2020-12-18 19:26

    The process you are talking about is called Normalization and is specified in the Unicode Normalization Forms technical note.

    There is a class in the Java SE class library called java.text.Normalizer which implements this process. However, you need to read the Unicode document linked above to figure out which of the "normalization forms" you need to use to get the result you want. It is not straightforward ....

    0 讨论(0)
  • 2020-12-18 19:27

    You could try the java.text.Normalizer, but I am not really sure if that works for ligatures.

    0 讨论(0)
提交回复
热议问题