# Fix run-together comments to have a tab between them
$source =~ s!\*/(/\*.*\*/)$!*/\t$1!gm;
+ # Postprocess multiline comments except for /**... and /*-... ones
+ $source =~ s!^(/\*[^\*\-].*?\*/)!postprocess_multiline_comment($1)!mgse;
+
## Functions
# Use a single space before '*' in function return types
return $source;
}
+sub postprocess_multiline_comment
+{
+ my $source = shift;
+ my @lines = split "\n", $source;
+
+ # Only reformat comments that actually span more than one line
+ if (scalar @lines < 2)
+ {
+ return $source;
+ }
+
+ # Split any text on the first line onto a separate line,
+ # but keep /* === and /* --- lines as is
+ if ($lines[0] !~ m!^/\*\s+[=-]+$!)
+ {
+ $lines[0] =~ s!/\*\s*(.+)!/\*\n * $1!;
+ }
+
+ # Apply these steps to all lines but the first
+ for my $i (1 .. scalar @lines - 1)
+ {
+ # Insert ' * ' if first non-white-space character is not '*'
+ $lines[$i] =~ s/^\s*/ \* / if $lines[$i] !~ /^\s*\*/;
+ # ... but that might leave us with trailing space
+ $lines[$i] =~ s/\s+$//;
+ # Require exactly one leading '*', and one space before it
+ $lines[$i] =~ s/^\s*\*+/ \*/;
+ }
+
+ # Split trailing "*/" onto its own line if not that already,
+ # but keep === */ and --- */ lines as is
+ if ($lines[-1] !~ m!^\s*[=-]+\s+\*/$!)
+ {
+ # this also removes any trailing whitespace
+ $lines[-1] =~ s!(.+?)\s+\*/!$1\n \*/!;
+ }
+
+ $source = join "\n", @lines;
+
+ return $source;
+}
+
sub run_indent
{
my $source = shift;