Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating Unicode ligature characters

Tags:

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 there any way easy to convert characters like these into multiple single characters? Preferably something available in the standard Java API, but I can refer to an external library if need be.

like image 334
nonoitall Avatar asked Aug 24 '11 06:08

nonoitall


People also ask

What are examples of ligature?

The most common ligature points and ligatures were doors, hooks/handles, windows, and belts or sheets/towels, respectively. Use of shoelaces, doors, and windows increased over time.

Are ligatures still used?

The only ligature that is still quite common in modern English is the ampersand (&), which started out as a combination of the letters 'e' and 't' (spelling the Latin word 'et', meaning 'and').

How do you write a ligature?

In writing and typography, a ligature occurs where two or more graphemes or letters are joined to form a single glyph. Examples are the characters æ and œ used in English and French, in which the letters 'a' and 'e' are joined for the first ligature and the letters 'o' and 'e' are joined for the second ligature.


2 Answers

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
like image 143
Joachim Sauer Avatar answered Sep 22 '22 16:09

Joachim Sauer


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 ....

like image 26
Stephen C Avatar answered Sep 20 '22 16:09

Stephen C