whitespace.pl can now do a better job (although surely still not 100% perfect job) of formatting constructor member initialization lists according to the rules described in the current CodingStyle file.
Signed-off-by: K. Heller <[email protected]> --- I ran this version of whitespace.pl on most of the source files in the subsurface repo and I was very happy with the results. I did not find anywhere that 'indent_ctor_init_lists' led to side-effects on lines that have nothing to do with ctors. An additional comment about whitespace.pl: So far in my testing with clang-format 3.5.0, there appear to be parts of whitespace.pl that can now be removed. (I have not made any removals, though.) For example: clang-format does handle the Q_FOREACH and for_each_dive in my testing. So I don't think whitespace.pl needs to manipulate 'each'es. Also, I am not sure that I see any 'messing-up' with clang adding 4 spaces or 6 spaces anywhere. scripts/whitespace.pl | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/whitespace.pl b/scripts/whitespace.pl index 6cd8081..9ed9bf4 100755 --- a/scripts/whitespace.pl +++ b/scripts/whitespace.pl @@ -38,6 +38,44 @@ $source =~ s/^(#(?:if |)define.*)((?:\\\n.*){4})\n +([^*].*)$/$1$2\n\t$3/mg; $source =~ s/^(#(?:if |)define.*)((?:\\\n.*){5})\n +([^*].*)$/$1$2\n\t$3/mg; # don't put line break before the last single term argument of a calculation $source =~ s/(?:\G|^)(.*[+-])\n\s*(\S*\;)$/$1 $2/mg; + +sub indent_ctor_init_lists { + my($content) = @_; + + my @not_ctor_words = qw( + \bdo\b + \belse\b + \bfor\b + \bif\b + \bsizeof\b + \bswitch\b + \bwhile\b + \btr\b + \bconnect\b + ); + + my $regexStr = "(" . join("|", @not_ctor_words) . ")"; + my $not_ctor_regex = qr{$regexStr}; + + my $result = ""; + + for ( split(/\n/, $content) ) { + + if ($_ =~ $not_ctor_regex) { + # probably not a ctor line. leave it be. + $result .= $_ . "\n"; + } + else { + $_ =~ s/^\s*(\w*\(.*\),?)$/\t$1/mg; + $result .= $_ . "\n"; + } + } + + return $result; +} + +$source = indent_ctor_init_lists($source); + $quotedinput = $input; $quotedinput =~ s|/|\\/|g; open (DIFF, "| diff -u $input - | sed -e 's/--- $quotedinput/--- $quotedinput.old/' | sed -e 's/+++ -/+++ $quotedinput/'"); -- 2.5.0 _______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
