init(_:)
Initialize a new printer using the existing state from another printer.
CodePrinter.swift:82init(_ parent: CodePrinter)
Parameters
- parent
The other printer to copy the configuration/state from.
This can be useful to use with generation subtasks, so see if they actually generate something (via isEmpty
) to then optionally add it back into the parent with whatever surounding content.
This is most useful to then use append
to add the new content.
Other members in extension
Type members
init(CodePrinter, addNewlines: Bool
) Initialize a new printer using the existing state from another printer but with support to control the behavior of
addNewlines
.init(indent: String.UnicodeScalarView
) init(indent: String.UnicodeScalarView, addNewlines: Bool
) Initialize the printer for use.
Instance members
var content: String
The string content that was printed.
var isEmpty: Bool
See if anything was printed.
func append(CodePrinter, indenting: Bool
) Appended the content of another
CodePrinter
to this one.func indent(
) Increases the printer’s indentation level.
func outdent(
) Decreases the printer’s indentation level.
func print(String...
) Writes the given strings to the printer, adding a newline after each string.
func print(String..., newlines: Bool
) Writes the given strings to the printer, optionally adding a newline after each string. If called with no strings, a blank line is added to the printer.
func printIndented(String...
) Indents, writes the given strings to the printer, and then outdents.
func withIndentation(body: (_ p: inout CodePrinter) -> Void
) Indents, calls
body
to do other work relaying along the printer, and the outdents after wards.