import std.string : outdent, strip; prettyprint("Foo").shouldEqual("Foo"); prettyprint("Foo(").shouldEqual("Foo("); prettyprint("Foo()").shouldEqual("Foo()"); prettyprint("Foo[]").shouldEqual("Foo[]"); prettyprint("Foo{}").shouldEqual("Foo{}"); prettyprint("Foo(A, B)").shouldEqual("Foo(A, B)"); prettyprint("Foo(Bar(Baz()), Baq())", 16).shouldEqual(" Foo( Bar(Baz()), Baq() )".outdent.strip); prettyprint("Foo(Bar(Baz()), Baq())", 12).shouldEqual(" Foo( Bar( Baz( ) ), Baq() )".outdent.strip);
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)).