1 // Simple item. 2 auto example1 = new Output(); 3 4 example1.adaptiveLine("foo"); 5 6 assert(example1.data() == "foo"); 7 8 // Inline function. 9 auto example2 = new Output(); 10 11 example2.adaptiveLine("void foo(%@,%@);") in { 12 example2.adaptiveLine("int bar"); 13 example2.adaptiveLine("int baz"); 14 }; 15 16 assert(example2.data() == "void foo(int bar, int baz);"); 17 18 // Broken function. 19 auto example3 = new Output(); 20 21 example3.adaptiveLine("void foo(%@,%@);") in { 22 example3.adaptiveLine("int bar0"); 23 example3.adaptiveLine("int bar1"); 24 example3.adaptiveLine("int bar2"); 25 example3.adaptiveLine("int bar3"); 26 example3.adaptiveLine("int bar4"); 27 example3.adaptiveLine("int bar5"); 28 example3.adaptiveLine("int bar6"); 29 example3.adaptiveLine("int bar7"); 30 example3.adaptiveLine("int bar8"); 31 }; 32 33 assert(example3.data() == 34 q"D 35 void foo( 36 int bar0, 37 int bar1, 38 int bar2, 39 int bar3, 40 int bar4, 41 int bar5, 42 int bar6, 43 int bar7, 44 int bar8); 45 D"[0 .. $ - 1]); 46 47 // The adaptive lines can be nested multiple times. Breaking algorithm 48 // will try to break only the most outer levels. The %@<sep>%@ can be 49 // mixed with standard format specifiers. 50 auto example4 = new Output(); 51 52 example4.adaptiveLine("foo%d%s(%@,%@);", 123, "bar") in { 53 example4.adaptiveLine("bar0"); 54 example4.adaptiveLine("bar1"); 55 example4.adaptiveLine("bar2"); 56 example4.adaptiveLine("baz(%@ +%@)") in { 57 example4.adaptiveLine("0"); 58 example4.adaptiveLine("1"); 59 example4.adaptiveLine("2"); 60 example4.adaptiveLine("3"); 61 example4.adaptiveLine("4"); 62 }; 63 example4.adaptiveLine("bar4"); 64 example4.adaptiveLine("bar5"); 65 example4.adaptiveLine("bar6"); 66 example4.adaptiveLine("bar7"); 67 example4.adaptiveLine("bar8"); 68 }; 69 70 assert(example4.data() == 71 q"D 72 foo123bar( 73 bar0, 74 bar1, 75 bar2, 76 baz(0 + 1 + 2 + 3 + 4), 77 bar4, 78 bar5, 79 bar6, 80 bar7, 81 bar8); 82 D"[0 .. $ - 1]); 83 84
adaptiveLine adds a line to the output that is automatically broken to multiple lines, if it's too long (80 characters).
It takes a special format specifier that is replaced with other nested adaptive lines. The specifier has form %@<separator>%@, where <separator> is a string that separates the items/lines (the spaces and end-lines are added automatically).