Last active
October 31, 2015 02:33
-
-
Save ZevEisenberg/3c00a03177f57d3fee60 to your computer and use it in GitHub Desktop.
A script that prints all the Unicode characters. I would have uploaded the output as well, but it’s 50 MB and GitHub can’t handle my scale.
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
import Foundation | |
func describeCharsInRange(range: Range<Int>) -> String { | |
return range.map { | |
let swiftCharacter = Character(UnicodeScalar($0)) | |
let string = String(swiftCharacter) | |
let hexString = NSString(format: "0x%.6X", $0) as String | |
// Optional in theory, but in this case it always returns a value | |
let name = string.stringByApplyingTransform(NSStringTransformToUnicodeName, reverse: false)! | |
return "\(hexString) - [\(string)] - \(name)\n" | |
}.reduce("") { $0 + $1 } | |
} | |
// ranges from http://www.unicode.org/glossary/#unicode_scalar_value via http://stackoverflow.com/a/32157540/255489 | |
let charString = describeCharsInRange(0x0...0xD7FF) + describeCharsInRange(0xE000...0x10FFFF) | |
let desktopPath = NSSearchPathForDirectoriesInDomains(.DesktopDirectory, .UserDomainMask, true)[0] | |
let filePath = (desktopPath as NSString).stringByAppendingPathComponent("allCharacters.txt") | |
do { | |
try! charString.writeToFile(filePath, atomically: true, encoding: NSUTF8StringEncoding) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment