Skip to content

Instantly share code, notes, and snippets.

@neilpa
Created February 5, 2015 23:04
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 neilpa/443e5c854839c008c5f9 to your computer and use it in GitHub Desktop.
Save neilpa/443e5c854839c008c5f9 to your computer and use it in GitHub Desktop.
Simple CLI around CFStringTransform for Unicode to ASCII transliteration
#!/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