Skip to content

Instantly share code, notes, and snippets.

@ole
Created September 27, 2021 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ole/a54e9d5aa25f9c5350a9767be85158d9 to your computer and use it in GitHub Desktop.
Save ole/a54e9d5aa25f9c5350a9767be85158d9 to your computer and use it in GitHub Desktop.
Unicode canonical equivalence vs. compatibility
let precomposed = "é"
let decomposed = "e\u{301}"
// `==` for strings means canonically equivalent:
assert(precomposed == decomposed)
let letters = "ffi"
let ligature = "ffi"
// The ligature and its decomposition are *not* canonically equivalent:
assert(letters != ligature)
// But they are *compatible* (used for searching etc.)
import Foundation
assert(letters.decomposedStringWithCompatibilityMapping
== ligature.decomposedStringWithCompatibilityMapping)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment