prettyprint

This function takes the input text and returns a pretty-printed, multiline, indented version. It assumes that the input text is the output of a well-structured toString and forms a valid comma separated paren tree.

A comma separated paren tree is a string that contains a balanced number of quotation marks, parentheses and brackets.

For example, the string may take the form Class(field1=1, field2="text", field3=Struct(a=4, b=5)).

string
prettyprint
(
const string text
,
size_t columnWidth = 80
)

Examples

1 import std.string : outdent, strip;
2 
3 prettyprint("Foo").shouldEqual("Foo");
4 prettyprint("Foo(").shouldEqual("Foo(");
5 prettyprint("Foo()").shouldEqual("Foo()");
6 prettyprint("Foo[]").shouldEqual("Foo[]");
7 prettyprint("Foo{}").shouldEqual("Foo{}");
8 prettyprint("Foo(A, B)").shouldEqual("Foo(A, B)");
9 prettyprint("Foo(Bar(Baz()), Baq())", 16).shouldEqual("
10     Foo(
11         Bar(Baz()),
12         Baq()
13     )".outdent.strip);
14 prettyprint("Foo(Bar(Baz()), Baq())", 12).shouldEqual("
15     Foo(
16         Bar(
17             Baz(
18             )
19         ),
20         Baq()
21     )".outdent.strip);

Meta