-
Notifications
You must be signed in to change notification settings - Fork 8
/
lib.swift
27 lines (23 loc) · 1.06 KB
/
lib.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Foundation
/**
Write the given string to the specified FileHandle.
- parameter str: native string to write encoded in utf-8.
- parameter handle: FileHandle to write to (defaults to /dev/stdout)
- parameter terminator: string to write after `str` (encoded in utf-8) (defaults to a single newline)
*/
func printLine(_ str: String, handle: FileHandle = .standardOutput, terminator: String = "\n") {
if let data = str.data(using: .utf8) {
handle.write(data)
if let terminatorData = terminator.data(using: .utf8) {
handle.write(terminatorData)
}
}
}
func printOut(_ items: Any..., separator: String = " ", terminator: String = "\n") {
let str = items.map { ($0 as AnyObject).description }.joined(separator: separator)
printLine(str, handle: .standardOutput, terminator: terminator)
}
func printErr(_ items: Any..., separator: String = " ", terminator: String = "\n") {
let str = items.map { ($0 as AnyObject).description }.joined(separator: separator)
printLine(str, handle: .standardError, terminator: terminator)
}