Function 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));
Example
import std .array:array, appender;
import std .stdio:stderr;
stderr .writeln("Running unittest for unDecorateComment...");
string[] inputs = [
"/***************\n*******************/",
"/***************\n *\n ******************/",
"/**\n*/",
"/** */",
"/***/",
"/******/",
"/** abcde1 */",
"/// abcde2\n/// abcde2",
"/**\n * stuff1\n */",
"/**\n *\n * stuff2\n */",
"/**\n *\n * stuff3\n *\n */",
"/**\n *\n * stuff4\n *\n*/",
"/**\n * abcde3\n * abcde3 \n */",
"/**\n * abcde4\n *\n * abcde4\n */",
"/**abcde5\n*abcde5\n*/",
"/** abcde6\n * abcde6\n*/",
"/**\n1\n\n\n\n*/",
"/**\r\n1\r\n\r\n\r\n\r\n*/",
"/**\na1\n\na2\n\n*/",
"/**b1\n*b2\n*b3*/",
"/**c1\n *c2\n *c3*/",
"/**d1\n *d2\n *d3\n*/",
"///a\fbc\n///def"
];
string[] outputs = [
"",
"",
"",
"",
"",
"",
"abcde1",
"abcde2\nabcde2",
"stuff1",
"stuff2",
"stuff3",
"stuff4",
"abcde3\n abcde3",
"abcde4\n\nabcde4",
"abcde5\nabcde5",
"abcde6\nabcde6",
"1",
"1",
"a1\n\na2",
"b1\nb2\nb3",
"c1\nc2\nc3",
"d1\nd2\nd3",
"a\fbc\ndef"
];
// tests where * and + are not interchangeable
string[2][] np =
[
["/**\n * d1\n d2\n */", "* d1\nd2"],
["/**\n + d1\n d2\n */", "+ d1\nd2"],
["/**d1\n\n\n*d2\n*/", "d1\n\n*d2"],
];
assert(inputs .length == outputs .length);
foreach (pair; zip(inputs, outputs))
{
foreach (b; [true, false])
{
auto app = appender!string();
unDecorateComment(b ? pair[0] : pair[0] .replace("*", "+"), app);
assert(pair[1] == app .data, "[[" ~ pair[0] ~ "]] => [[" ~ app .data ~ "]]");
}
}
foreach (pair; np)
{
auto app = appender!string();
unDecorateComment(pair[0], app);
assert(pair[1] == app .data, "[[" ~ pair[0] ~ "]] => [[" ~ app .data ~ "]]");
}
stderr .writeln("Unittest for unDecorateComment passed.");