File indexing completed on 2024-04-14 05:35:08

0001 #!/usr/bin/perl
0002 
0003 # laurent Montel <montel@kde.org> 2006 GPL
0004 # Reinhold Kainhofer <reinhold@kainhofer.com> 2006 GPL
0005 #
0006 # simple script to replace QT3_SUPPORT find by indexOf
0007 #
0008 # usage:
0009 #    convert-find-to-indexof.pl *.cpp
0010 #
0011 # CAUTION: This script replaces all calls to methods named 'find', even if the 
0012 # object is not a class where the find method is deprecated. 
0013 # I apply the script only to files that 
0014 # throw a deprecated warning and compare the # of deprecated warnings to the nr 
0015 # of replacements.
0016 #
0017 # NOTE: The results need a lot of manual tweaking!!!!
0018 
0019 
0020 use File::Basename;
0021 use lib dirname( $0 );
0022 use functionUtilkde;
0023 use strict;
0024 
0025 foreach my $file (@ARGV) {
0026     chomp $file;
0027     next if functionUtilkde::excludeFile( $file);
0028 
0029     my $modified;
0030     my @necessaryIncludes = ();
0031     open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
0032     my @l = map {
0033       my $orig = $_;
0034       if ( m![\.>]find\s*\(! ) {
0035 #       s/(.*\.)find/!XXX-\1-XXXYYY-\2-YYY/g;
0036 #       s/(.*\.)find(\(.*\)\s*)==\s*([.*]\.)end\s*\(\s*\)/!\1contains\2/g;
0037         s/([^ ].*(.|->))find(\(.*\)\s*)==\s*\1end\s*\(\s*\)/!\1contains\3/g;
0038         s/([^ ]*(.|->))find(\(.*\)\s*)==\s*-1\s*/!\1contains\3/g;
0039         s/([^ ].*(.|->))find(\(.*\)\s*)!=\s*\1end\s*\(\s*\)/\1contains\3/g;
0040         s/([^ ]*(.|->))find(\(.*\)\s*)>=\s*0\s*/\1contains\3/g;
0041         s/([^ ]*(.|->))find(\(.*\)\s*)!=\s*-1\s*/\1contains\3/g;
0042 # print "Old line:      \n$orig";
0043 # print "New line:      \n$_====================\n";
0044       }
0045       
0046       if ( m![\.>]find\s*\(! && ! m/[mM]ap/ ) {
0047         s/([\.>])find(\s*)\(/\1indexOf\2(/g;
0048       }
0049       # third argument of find was changed from bool to  Qt::CaseSensitivity cs = Qt::CaseSensitive
0050       if ( my ($head, $parm1, $parm2, $ws, $parm3,$trailer) = m!^(.*ndexOf\s*)\(([^,]*),([^,]*),(\s*)([^, \)]*)(\s*\).*$)! ) {
0051         if ( $parm3 eq 'true' ) {
0052           $_ = "$head($parm1,$parm2,$ws"."Qt::CaseSensitive$trailer\n";
0053         } elsif ( $parm3 eq 'false' ) {
0054           $_ = "$head($parm1,$parm2,$ws"."Qt::CaseInsensitive$trailer\n";
0055         }
0056 #if ( $orig ne $_ ) {
0057 #  print "Old line:      \n$orig";
0058 #  print "New line:      \n$_====================\n";
0059 #}
0060       }
0061       $modified ||= $orig ne $_;
0062       $_;
0063     } <$FILE>;
0064 
0065     if ($modified) {
0066       print "Modified: $file\n";
0067       open (my $OUT, ">", $file);
0068       print $OUT @l;
0069       close $OUT;
0070     }
0071 
0072 }
0073 functionUtilkde::diffFile( @ARGV );
0074