2 # Search for bad words in strings
4 # Copyright (c) 2000 Dirk Koopman
20 use vars qw($badword $regexcode);
22 my $oldfn = localdata("badwords");
23 my $regex = localdata("badw_regex");
24 my $bwfn = localdata("badword");
26 # copy issue ones across
27 filecopy("$regex.gb.issue", $regex) unless -e $regex;
28 filecopy("$bwfn.issue", $bwfn) unless -e $bwfn;
30 $badword = new DXHash "badword";
32 # load the badwords file
36 my $fh = new IO::File $oldfn;
51 push @out, create_regex();
58 my $fh = new IO::File $regex;
61 my $s = "sub { my \$str = shift; my \@out; \n";
67 # create a closure for each word so that it matches stuff with spaces/punctuation
68 # and repeated characters in it
71 my $e = join '+[\s\W]*', @l;
72 $s .= "push \@out, \$1 if \$str =~ /\\b($e)/;\n";
75 $s .= "return \@out;\n}";
77 dbg($s) if isdbg('badword');
85 my $l = "can't open $regex $!";
93 # check the text against the badwords list
99 push @out, &$regexcode($s) if $regexcode;
103 for (split(/\b/, $s)) {
104 push @out, $_ if $badword->in($_);