projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
5. Change the badwords interface to be the same as baddx, badspotter et al.
[spider.git]
/
perl
/
BadWords.pm
diff --git
a/perl/BadWords.pm
b/perl/BadWords.pm
index 2336bb0468e22b1b95e3b517f5750c6397dd9fc2..e7d1169e3a390abd5845f5922bb299eaa79cefdc 100644
(file)
--- a/
perl/BadWords.pm
+++ b/
perl/BadWords.pm
@@
-12,12
+12,13
@@
use strict;
use DXUtil;
use DXVars;
use DXUtil;
use DXVars;
+use DXHash;
use IO::File;
use IO::File;
-use vars qw(
%badwords $fn
);
+use vars qw(
$badword
);
-
$
fn = "$main::data/badwords";
-
%badwords = ()
;
+
my $old
fn = "$main::data/badwords";
+
$badword = new DXHash "badword"
;
use vars qw($VERSION $BRANCH);
$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
use vars qw($VERSION $BRANCH);
$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
@@
-29,23
+30,24
@@
$main::branch += $BRANCH;
sub load
{
my @out;
sub load
{
my @out;
- return unless -e $fn;
- my $fh = new IO::File $fn;
+ return unless -e $
old
fn;
+ my $fh = new IO::File $
old
fn;
if ($fh) {
if ($fh) {
- %badwords = ();
while (<$fh>) {
chomp;
next if /^\s*\#/;
my @list = split " ";
for (@list) {
while (<$fh>) {
chomp;
next if /^\s*\#/;
my @list = split " ";
for (@list) {
- $badword
s{lc $_}++
;
+ $badword
->add($_)
;
}
}
$fh->close;
}
}
$fh->close;
+ $badword->put;
+ unlink $oldfn;
} else {
} else {
- my $l = "can't open $fn $!";
- dbg(
'err',
$l);
+ my $l = "can't open $
old
fn $!";
+ dbg($l);
push @out, $l;
}
return @out;
push @out, $l;
}
return @out;
@@
-54,7
+56,7
@@
sub load
# check the text against the badwords list
sub check
{
# check the text against the badwords list
sub check
{
- return grep { $badword
s{$_}
} split(/\b/, lc shift);
+ return grep { $badword
->in($_)
} split(/\b/, lc shift);
}
1;
}
1;