-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: multiple-values and separator
#75
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,119 +19,147 @@ public class Debug { | |
// MARK: Standard API | ||
|
||
extension Debug { | ||
/// Output `target` to console. | ||
/// Output `targets` to console. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - targets: targets | ||
/// - separator: A string to print between each item. | ||
public static func print( | ||
_ target: Any | ||
_ targets: Any..., | ||
separator: String = " " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This default value |
||
) { | ||
Swift.print(_print(target)) | ||
Swift.print(_print(targets, separator: separator)) | ||
} | ||
|
||
/// Output `target` to `output`. | ||
/// Output `targets` to `output`. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - target: targets | ||
/// - separator: A string to print between each item. | ||
/// - output: output | ||
public static func print<Target: TextOutputStream>( | ||
_ target: Any, | ||
_ targets: Any..., | ||
separator: String = " ", | ||
to output: inout Target | ||
) { | ||
Swift.print(_print(target), to: &output) | ||
Swift.print(_print(targets, separator: separator), to: &output) | ||
} | ||
|
||
/// Output pretty-formatted `target` to console. | ||
/// Output pretty-formatted `targets` to console. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - targets: targets | ||
/// - separator: A string to print between each item. | ||
/// - option: option (default: `Debug.sharedOption`) | ||
public static func prettyPrint( | ||
_ target: Any, | ||
_ targets: Any..., | ||
separator: String = "\n", | ||
option: Option = Debug.sharedOption | ||
) { | ||
Swift.print(_prettyPrint(target, option: option)) | ||
Swift.print(_prettyPrint(targets, separator: separator, option: option)) | ||
} | ||
|
||
/// Output pretty-formatted `target` to console. | ||
/// Output pretty-formatted `targets` to console. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - targets: targets | ||
/// - separator: A string to print between each item. | ||
/// - option: option (default: `Debug.sharedOption`) | ||
/// - output: output | ||
public static func prettyPrint<Target: TextOutputStream>( | ||
_ target: Any, | ||
_ targets: Any..., | ||
separator: String = "\n", | ||
option: Option = Debug.sharedOption, | ||
to output: inout Target | ||
) { | ||
Swift.print(_prettyPrint(target, option: option), to: &output) | ||
Swift.print(_prettyPrint(targets, separator: separator, option: option), to: &output) | ||
} | ||
|
||
/// Output debuggable `target` to console. | ||
/// Output debuggable `targets` to console. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - targets: targets | ||
/// - separator: A string to print between each item. | ||
public static func debugPrint( | ||
_ target: Any | ||
_ targets: Any..., | ||
separator: String = " " | ||
) { | ||
Swift.print(_debugPrint(target)) | ||
Swift.print(_debugPrint(targets, separator: separator)) | ||
} | ||
|
||
/// Output debuggable `target` to console. | ||
/// Output debuggable `targets` to console. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - targets: targets | ||
/// - separator: A string to print between each item. | ||
/// - output: output | ||
public static func debugPrint<Target: TextOutputStream>( | ||
_ target: Any, | ||
_ targets: Any..., | ||
separator: String = " ", | ||
to output: inout Target | ||
) { | ||
Swift.print(_debugPrint(target), to: &output) | ||
Swift.print(_debugPrint(targets, separator: separator), to: &output) | ||
} | ||
|
||
/// Output debuggable and pretty-formatted `target` to console. | ||
/// Output debuggable and pretty-formatted `targets` to console. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - targets: targets | ||
/// - separator: A string to print between each item. | ||
/// - option: option (default: `Debug.sharedOption`) | ||
public static func debugPrettyPrint( | ||
_ target: Any, | ||
_ targets: Any..., | ||
separator: String = "\n", | ||
option: Option = Debug.sharedOption | ||
) { | ||
Swift.print(_debugPrettyPrint(target, option: option)) | ||
Swift.print(_debugPrettyPrint(targets, separator: separator, option: option)) | ||
} | ||
|
||
/// Output debuggable and pretty-formatted `target` to console. | ||
/// - Parameters: | ||
/// - target: target | ||
/// - targets: targets | ||
/// - separator: A string to print between each item. | ||
/// - option: option (default: `Debug.sharedOption`) | ||
/// - output: output | ||
public static func debugPrettyPrint<Target: TextOutputStream>( | ||
_ target: Any, | ||
_ targets: Any..., | ||
separator: String = "\n", | ||
option: Option = Debug.sharedOption, | ||
to output: inout Target | ||
) { | ||
Swift.print(_debugPrettyPrint(target, option: option), to: &output) | ||
Swift.print(_debugPrettyPrint(targets, separator: separator, option: option), to: &output) | ||
} | ||
|
||
// MARK: - private | ||
|
||
private static func _print( | ||
_ target: Any | ||
_ targets: [Any], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is due to Swift language design😎 |
||
separator: String | ||
) -> String { | ||
Pretty(formatter: SinglelineFormatter()).string(target, debug: false) | ||
targets.map { | ||
Pretty(formatter: SinglelineFormatter()).string($0, debug: false) | ||
}.joined(separator: separator) | ||
} | ||
|
||
private static func _prettyPrint( | ||
_ target: Any, | ||
_ targets: [Any], | ||
separator: String, | ||
option: Option | ||
) -> String { | ||
Pretty(formatter: MultilineFormatter(option: option)).string(target, debug: false) | ||
targets.map { | ||
Pretty(formatter: MultilineFormatter(option: option)).string($0, debug: false) | ||
}.joined(separator: separator) | ||
} | ||
|
||
private static func _debugPrint( | ||
_ target: Any | ||
_ targets: [Any], | ||
separator: String | ||
) -> String { | ||
Pretty(formatter: SinglelineFormatter()).string(target, debug: true) | ||
targets.map { | ||
Pretty(formatter: SinglelineFormatter()).string($0, debug: true) | ||
}.joined(separator: separator) | ||
} | ||
|
||
private static func _debugPrettyPrint( | ||
_ target: Any, | ||
_ targets: [Any], | ||
separator: String, | ||
option: Option | ||
) -> String { | ||
Pretty(formatter: MultilineFormatter(option: option)).string(target, debug: true) | ||
targets.map { | ||
Pretty(formatter: MultilineFormatter(option: option)).string($0, debug: true) | ||
}.joined(separator: separator) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/target/targets/g