[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 01/02: c/cruft: rewrite perl "FAQ strip comments" regex



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit a4a1658558a65a8ab1107d3543c713ddebc94d34
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Aug 30 18:20:49 2015 +0200

    c/cruft: rewrite perl "FAQ strip comments" regex
    
    Rewrite the "strip comments" regex from the perl FAQ to scale a bit
    better.  Notably:
    
     * Split it into 3 distinct parts with their own purpose.
     * Limit the places were perl is permitted to backtrack by using
       "++" or "*+"
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 checks/cruft.pm | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/checks/cruft.pm b/checks/cruft.pm
index 09f05bb..baca13c 100644
--- a/checks/cruft.pm
+++ b/checks/cruft.pm
@@ -961,14 +961,19 @@ sub _linelength_test {
             $entry, $info, $name, $basename, $dirname, $block,1024
         )
       ) {
-# now try to be more clever and work only on the 8192 character in order to avoid
-# regexp recursion problems
+        # now try to be more clever and work only on the 8192
+        # character in order to avoid regexp recursion problems
         my $strip = substr($block,0,8192);
         # strip indention
         $strip =~ s/^\s+//g;
-        # from perl faq strip comments
+        # from perl faq strip comments (split into 3 and rewritten a bit)
+        # - Part 1) Strip /* */ comments
+        $strip =~ s# /\* [^*]*+\*++ (?:[^/*][^*]*+\*++)*+ / ##xgs;
+        # - Part 2) Strip // comments (allowing "\\\n" line continuation)
+        $strip =~ s# // (?:[^\\]++|[^\n][\n]?)*? (?=\n)##xgs;
+        # - Part 3) "De-stringify" elements ("foo" => foo)
         $strip
-          =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?(?=\n)|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : ""#gse;
+          =~ s#("(\\.|[^"\\]++)*"|'(\\.|[^'\\]++)*'|.[^/"'\\]*+)#defined $1 ? $1 : ""#xgse;
         # strip empty line
         $strip =~ s/^\s*\n//mg;
         # remove last \n

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: