Files
swift-mirror/stdlib/public/core/Print.swift
Dave Abrahams b698a088c7 [stdlib] Add new print functions (underscored)
Getting these ready for API review.

Swift SVN r30776
2015-07-29 20:30:32 +00:00

128 lines
3.8 KiB
Swift

//===--- Print.swift ------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
/// Writes the textual representations of `items`, separated by
/// `separator` and terminated by `terminator`, into the standard
/// output.
///
/// The textual representations are obtained for each `item` via
/// the expression `String(item)`.
///
/// - SeeAlso: `debugPrint`, Streamable`, `CustomStringConvertible`,
/// `CustomDebugStringConvertible`
@inline(never)
@_semantics("stdlib_binary_only")
public func _prext_print(
items: Any...,
separator: String = " ",
end terminator: String = "\n"
) {
var output = _Stdout()
_print(items, toStream: &output, separator: separator, end: terminator)
}
/// Writes the textual representations of `items` most suitable for
/// debugging, separated by `separator` and terminated by
/// `terminator`, into the standard output.
///
/// The textual representations are obtained for each `item` via
/// the expression `String(reflecting: item)`.
///
/// - SeeAlso: `print`, Streamable`, `CustomStringConvertible`,
/// `CustomDebugStringConvertible`
@inline(never)
@_semantics("stdlib_binary_only")
public func _prext_debugPrint(
items: Any...,
separator: String = " ",
end terminator: String = "\n") {
var output = _Stdout()
_debugPrint(items, toStream: &output, separator: separator, end: terminator)
}
/// Writes the textual representations of `items`, separated by
/// `separator` and terminated by `terminator`, into `output`.
///
/// The textual representations are obtained for each `item` via
/// the expression `String(item)`.
///
/// - SeeAlso: `debugPrint`, Streamable`, `CustomStringConvertible`,
/// `CustomDebugStringConvertible`
@inline(__always)
public func _prext_print<Target: OutputStreamType>(
items: Any...,
inout toStream output: Target,
separator: String = " ",
end terminator: String = "\n"
) {
_print(items, toStream: &output, separator: separator, end: terminator)
}
/// Writes the textual representations of `items` most suitable for
/// debugging, separated by `separator` and terminated by
/// `terminator`, into `output`.
///
/// The textual representations are obtained for each `item` via
/// the expression `String(reflecting: item)`.
///
/// - SeeAlso: `print`, Streamable`, `CustomStringConvertible`,
/// `CustomDebugStringConvertible`
@inline(__always)
public func _prext_debugPrint<Target: OutputStreamType>(
items: Any...,
inout toStream output: Target,
separator: String = " ",
end terminator: String = "\n"
) {
_debugPrint(items, toStream: &output, separator: separator, end: terminator)
}
@inline(never)
@_semantics("stdlib_binary_only")
internal func _print<Target: OutputStreamType>(
items: [Any],
inout toStream output: Target,
separator: String = " ",
end terminator: String = "\n"
) {
var prefix = ""
output._lock()
for item in items {
output.write(prefix)
_print_unlocked(item, &output)
prefix = separator
}
output.write(terminator)
output._unlock()
}
@inline(never)
@_semantics("stdlib_binary_only")
internal func _debugPrint<Target: OutputStreamType>(
items: [Any],
inout toStream output: Target,
separator: String = " ",
end terminator: String = "\n"
) {
var prefix = ""
output._lock()
for item in items {
output.write(prefix)
_debugPrint_unlocked(item, &output)
prefix = separator
}
output.write(terminator)
output._unlock()
}