unDecorateComment

Removes "decoration" such as leading whitespace, leading + and * characters, and places the result into the given output range

void
unDecorateComment
(
T
)
(
string comment
,
auto ref T outputRange
)
if (
isOutputRange!(T, string)
)

Examples

1 import std.array:array, appender;
2 import std.stdio:stderr;
3 stderr.writeln("Running unittest for unDecorateComment...");
4 
5 string[] inputs = [
6     "/***************\n*******************/",
7     "/***************\n *\n ******************/",
8     "/**\n*/",
9     "/** */",
10     "/***/",
11     "/******/",
12     "/** abcde1 */",
13     "/// abcde2\n/// abcde2",
14     "/**\n * stuff1\n */",
15     "/**\n *\n * stuff2\n */",
16     "/**\n *\n * stuff3\n *\n */",
17     "/**\n *\n * stuff4\n *\n*/",
18     "/**\n *  abcde3\n *    abcde3 \n */",
19     "/**\n * abcde4\n *\n * abcde4\n */",
20     "/**abcde5\n*abcde5\n*/",
21     "/** abcde6\n * abcde6\n*/",
22     "/**\n1\n\n\n\n*/",
23     "/**\r\n1\r\n\r\n\r\n\r\n*/",
24     "/**\na1\n\na2\n\n*/",
25     "/**b1\n*b2\n*b3*/",
26     "/**c1\n    *c2\n    *c3*/",
27     "/**d1\n    *d2\n    *d3\n*/",
28     "///a\fbc\n///def"
29 ];
30 string[] outputs = [
31     "",
32     "",
33     "",
34     "",
35     "",
36     "",
37     "abcde1",
38     "abcde2\nabcde2",
39     "stuff1",
40     "stuff2",
41     "stuff3",
42     "stuff4",
43     "abcde3\n  abcde3",
44     "abcde4\n\nabcde4",
45     "abcde5\nabcde5",
46     "abcde6\nabcde6",
47     "1",
48     "1",
49     "a1\n\na2",
50     "b1\nb2\nb3",
51     "c1\nc2\nc3",
52     "d1\nd2\nd3",
53     "a\fbc\ndef"
54 ];
55 
56 // tests where * and + are not interchangeable
57 string[2][] np =
58 [
59     ["/**\n * d1\n d2\n */", "* d1\nd2"],
60     ["/**\n + d1\n d2\n */", "+ d1\nd2"],
61     ["/**d1\n\n\n*d2\n*/",  "d1\n\n*d2"],
62 ];
63 
64 assert(inputs.length == outputs.length);
65 foreach (pair; zip(inputs, outputs))
66 {
67     foreach (b; [true, false])
68     {
69         auto app = appender!string();
70         unDecorateComment(b ? pair[0] : pair[0].replace("*", "+"), app);
71         assert(pair[1] == app.data, "[[" ~ pair[0] ~ "]] => [[" ~ app.data ~ "]]");
72     }
73 }
74 foreach (pair; np)
75 {
76     auto app = appender!string();
77     unDecorateComment(pair[0], app);
78     assert(pair[1] == app.data, "[[" ~ pair[0] ~ "]] => [[" ~ app.data ~ "]]");
79 }
80 stderr.writeln("Unittest for unDecorateComment passed.");

Meta