Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


On 09/19/2011 08:58 PM, Thomas Arnhold wrote:
I've recently seen some changes, which removed unnecessary NULL checks
for delete commands with the form:

- if (pTextPContext)
- delete pTextPContext;
+ delete pTextPContext;

Codebase is full with these. I've attached a little perl script which
should solve this conversion. I've attached a sample for the vcl dir.

Any objections?

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.")

-Stephan

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.