2 # Search for bad words in strings
4 # Copyright (c) 2000 Dirk Koopman
20 use vars qw($badword $regexcode);
24 # load the badwords file
27 my $bwfn = localdata("badword");
28 filecopy("$main::data.issue", $bwfn) unless -e $bwfn;
32 $badword = new DXHash "badword";
34 push @out, create_regex();
40 $regex = localdata("badw_regex");
41 filecopy("$regex.gb.issue", $regex) unless -e $regex;
44 my $fh = new IO::File $regex;
47 my $s = "sub { my \$str = shift; my \@out; \n";
53 # create a closure for each word so that it matches stuff with spaces/punctuation
54 # and repeated characters in it
57 my $e = join '+[\s\W]*', @l;
58 $s .= qq{push \@out, \$1 if \$str =~ m|\\b($e+)|;\n};
61 $s .= "return \@out;\n}";
63 dbg($s) if isdbg('badword');
71 my $l = "can't open $regex $!";
79 # check the text against the badwords list
85 push @out, &$regexcode($s) if $regexcode;
89 for (split(/\b/, $s)) {
90 push @out, $_ if $badword->in($_);