Created
August 19, 2019 12:13
-
-
Save kocyigityunus/4bd0cdf6918a89d082edeb86c53c8644 to your computer and use it in GitHub Desktop.
CharacterSet+getCharacters()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CharacterSet { | |
func getCharacters() -> [String] { | |
let characterSet = self as NSCharacterSet | |
var characters: [String] = [] | |
for plane:UInt8 in 0..<17 { | |
if characterSet.hasMemberInPlane(plane) { | |
let planeStart = UInt32(plane) << 16 | |
let nextPlaneStart = (UInt32(plane) + 1) << 16 | |
for char: UTF32Char in planeStart..<nextPlaneStart { | |
if characterSet.longCharacterIsMember(char) { | |
if let unicodeCharacter = UnicodeScalar(char) { | |
characters.append(String(unicodeCharacter)) | |
} | |
} | |
} | |
} | |
} | |
return characters | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment