justifiedEntryValueText

Takes an unformatted string of serialised entry-value text and justifies it into two neat columns.

It does one pass through it all first to determine the maximum width of the entry names, then another to format it and eventually return a flat string.

@safe pure
string
justifiedEntryValueText
(
const string origLines
)

Parameters

origLines string

Unjustified raw serialised text.

Return Value

Type: string

.ini file-like text, justified into two columns.

Examples

struct Foo
{
    // ...
}

struct Bar
{
    // ...
}

Foo foo;
Bar bar;

Appender!(char[]) sink;

sink.serialise(foo, bar);
immutable justified = sink.data.justifiedEntryValueText;
1     import std.algorithm.iteration : splitter;
2     import std.array : Appender;
3     import lu.uda : Separator;
4 
5     struct Foo
6     {
7         enum Bar { blaawp = 5, oorgle = -1 }
8         int someInt = 42;
9         string someString = "hello world!";
10         bool someBool = true;
11         float someFloat = 3.14f;
12         double someDouble = 99.9;
13         Bar someBars = Bar.oorgle;
14         string harbl;
15 
16         @Separator(",")
17         {
18             int[] intArray = [ 1, 2, -3, 4, 5 ];
19             string[] stringArrayy = [ "hello", "world", "!" ];
20             bool[] boolArray = [ true, false, true ];
21             float[] floatArray = [ 0.0, 1.1, -2.2, 3.3 ];
22             double[] doubleArray = [ 99.9999, 0.0001, -1.0 ];
23             Bar[] barArray = [ Bar.blaawp, Bar.oorgle, Bar.blaawp ];
24             string[] yarn;
25         }
26     }
27 
28     struct DifferentSection
29     {
30         string ignored = "completely";
31         string because = "   no DifferentSection struct was passed";
32         int nil = 5;
33         string naN = `!"#¤%&/`;
34     }
35 
36     Appender!(char[]) sink;
37     sink.reserve(512);
38     Foo foo;
39     DifferentSection diff;
40     enum unjustified =
41 `[Foo]
42 someInt 42
43 someString hello world!
44 someBool true
45 someFloat 3.14
46 someDouble 99.9
47 someBars oorgle
48 #harbl
49 intArray 1,2,-3,4,5
50 stringArrayy hello,world,!
51 boolArray true,false,true
52 floatArray 0,1.1,-2.2,3.3
53 doubleArray 99.9999,0.0001,-1
54 barArray blaawp,oorgle,blaawp
55 #yarn
56 
57 [DifferentSection]
58 ignored completely
59 because    no DifferentSection struct was passed
60 nil 5
61 naN !"#¤%&/`;
62 
63     enum justified =
64 `[Foo]
65 someInt                 42
66 someString              hello world!
67 someBool                true
68 someFloat               3.14
69 someDouble              99.9
70 someBars                oorgle
71 #harbl
72 intArray                1,2,-3,4,5
73 stringArrayy            hello,world,!
74 boolArray               true,false,true
75 floatArray              0,1.1,-2.2,3.3
76 doubleArray             99.9999,0.0001,-1
77 barArray                blaawp,oorgle,blaawp
78 #yarn
79 
80 [DifferentSection]
81 ignored                 completely
82 because                 no DifferentSection struct was passed
83 nil                     5
84 naN                     !"#¤%&/`;
85 
86     sink.serialise(foo, diff);
87     assert((sink.data == unjustified), '\n' ~ sink.data);
88     immutable configText = justifiedEntryValueText(sink.data.idup);
89 
90     assert((configText == justified), '\n' ~ configText);

Meta