Elsewhere I've seen it told that Swift's comparisons use NFD normalization.
However, running in the iSwift playground I've found that
print("\u{0071}\u{0307}\u{0323}" == "\u{0071}\u{0323}\u{0307}");
gives false
, despite this being an example straight from the standard of "Canonical Equivalence", which Swift's documentation claims to follow.
So, what kind of canonicalization is performed by Swift, and is this a bug?
"\u{0071}\u{0307}\u{0323}".precomposedStringWithCanonicalMapping
should return"\u{0071}\u{0323}\u{0307}"
, i.e. the NFC form with the combining marks in a defined order. But it doesn't, as one can verify withprint(Array(string.unicodeScalars))
. – Endounicodedata.normalize
, and Python seems to agree that NFD should reorder. – Lancelancelet