Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active September 17, 2020 14:07
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 Koze/21024d4ef744089d79be82dedd939a64 to your computer and use it in GitHub Desktop.
Save Koze/21024d4ef744089d79be82dedd939a64 to your computer and use it in GitHub Desktop.
The test for Equatable of precomposed characters of Unicode.
func unicodeCodePointsToString(_ codePoints :[UInt32]) -> String {
let unicodeScalars = codePoints.compactMap { Unicode.Scalar($0) }
let characters = unicodeScalars.map { Character($0) }
let string = String(characters)
return string
}
// HIRAGANA LETTER GA
let ga = unicodeCodePointsToString([0x304C])
// HIRAGANA LETTER KA, COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
let kaPlusDakuten = unicodeCodePointsToString([0x304B, 0x3099])
print(ga == kaPlusDakuten) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment