Unicode normalization.
There are multiple ways to normalize a string, referred to as Normalization
Forms. Which one you want depends on what you want to do with the string, but
the most common is NFC, which preserves the exact visual appearance of the
string. If you don't care about the details, just use normalize NFC.
import Unicode.Normalize exposing (Form(..), normalize)
normalize NFC "é"
--> "é"
normalize NFC (String.fromList [ 'ᄉ', 'ᅥ', 'ᆼ' ])
--> "성"Normalize a string to a particular Normalization Form.
-- Two equivalent representations of "é" become identical after NFC
normalize NFC "é" == normalize NFC "é"
--> True
-- ASCII strings are unaffected
normalize NFC "hello"
--> "hello"
-- Compatibility normalization replaces special forms
normalize NFKC "①②③"
--> "123"
normalize NFKC "ffi"
--> "ffi"
The different ways to normalize a string.
Canonical decomposition splits single characters into sequences of equivalent combining characters. Compatibility decomposition extends canonical decomposition by also replacing variants of the same logical character (such as replacing ¼ with 1/4).
Canonical composition undoes the process of canonical decomposition, combining sequences into single characters wherever possible.
For example, the character "ñ" can be represented as a single code point (
U+00F1) or as two code points ("n" followed by a combining tilde,U+006E U+0303). The normalization forms handle this differently:The compatibility forms also replace visual variants: