Add some scripts for getting character usage info

This commit is contained in:
Tellow Krinkle
2018-09-07 04:18:05 -05:00
parent 7ca3d475e0
commit a28e0cce65
7 changed files with 642 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import Foundation
var standardError = FileHandle.standardError
extension FileHandle : TextOutputStream {
public func write(_ string: String) {
guard let data = string.data(using: .utf8) else { return }
self.write(data)
}
}
guard CommandLine.arguments.count > 1 else {
print("Usage: \(CommandLine.arguments[0]) file\nUse - to read from stdin", to: &standardError)
exit(EXIT_FAILURE)
}
let input: String
if CommandLine.arguments[1] == "-" {
input = String(decoding: FileHandle.standardInput.readDataToEndOfFile(), as: UTF8.self)
} else {
input = try String(contentsOf: URL(fileURLWithPath: CommandLine.arguments[1]))
}
let chars = Set(input.unicodeScalars)
let out = chars.sorted().lazy.map(Character.init)
print(String(out), terminator: "")