[Libreoffice] Remove NULL checks from delete

Thomas Arnhold thomas at arnhold.org
Mon Sep 19 15:08:06 PDT 2011


Hi Stephan,

thanks for adjusting the regex. false positives like if (foo) delete bar 
wouldn't occur within my regex (the inner one). But this is some kind of 
hidden (the $1). I did this some kind of obfuscated, because I didn't 
remembered \1 for lookaheads ;)

I you want to, run it :)

On 09/19/2011 10:52 PM, Stephan Bergmann wrote:
> By the way, using the below regexps (best run in a C locale) should find
> even more instances, and should avoid false positives of the form "if
> (foo) delete bar;" or (unlikely) "#if (foo) \n delete foo;":
>
>> foreach (@ARGV) {
>> my $file = $_;
>> open(FH, "<$file");
>> my $data = "";
>> while (<FH>) { $data .= $_; }
>> close(FH);
>> while ($data =~ /((?<!#)\s*\bif\s*\(\s*(\w+)\s*\)\s*delete\s+\2\s*;)/g) {
>> print "found <$1>\n";
>> }
>> while ($data =~
>> /((?<!#)\s*\bif\s*\(\s*(\w+)\s*\)\s*{\s*delete\s+\2\s*;\s*})/g) {
>> print "found <$1>\n";
>> }
>> }
>
> (The outer parentheses are only there for print "found <$1>\n" to work
> -- no idea how Perl makes available the complete match without that
> hack... The leading "(?<!#)\s*" should really read "(?<!#\s*)", but then
> Perl complains that "Variable length lookbehind [is] not implemented.")

Thomas


More information about the LibreOffice mailing list