Created
February 5, 2015 23:04
-
-
Save neilpa/443e5c854839c008c5f9 to your computer and use it in GitHub Desktop.
Simple CLI around CFStringTransform for Unicode to ASCII transliteration
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
#!/usr/bin/env swift | |
// | |
// Naive wrapper around CFStringTransform that attempts to transliterate | |
// Unicode strings to lower-case ASCII | |
// | |
// http://nshipster.com/cfstringtransform/ | |
// | |
import Foundation | |
let stdin = NSFileHandle.fileHandleWithStandardInput() | |
let data: NSData = stdin.readDataToEndOfFile() | |
let str = NSString(data: data, encoding: NSUTF8StringEncoding) | |
let cfstr = str?.mutableCopy() as CFMutableString | |
var rng = CFRangeMake(0, CFStringGetLength(cfstr)) | |
CFStringTransform(cfstr, &rng, "Any-Latin; Latin-ASCII; Any-Lower", 0) | |
println(cfstr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment