Skip to content

Instantly share code, notes, and snippets.

@zhaorui
Created February 7, 2017 09:43
Show Gist options
  • Save zhaorui/fd2fbb988b82981bdf7c8e6e550b6c08 to your computer and use it in GitHub Desktop.
Save zhaorui/fd2fbb988b82981bdf7c8e6e550b6c08 to your computer and use it in GitHub Desktop.
See characters in CharacterSet (swift)
extension CharacterSet {
var characters:[UnicodeScalar] {
var chars = [UnicodeScalar]()
for plane:UInt8 in 0...16 {
if self.hasMember(inPlane: plane) {
let p0 = UInt32(plane) << 16
let p1 = (UInt32(plane) + 1) << 16
for c:UInt32 in p0..<p1 {
if let us = UnicodeScalar(c) {
if self.contains(us) {
chars.append(us)
}
}
}
}
}
return chars
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment