fix a talk bug for t xxx > yyy
[spider.git] / perl / BadWords.pm
diff --git a/perl/BadWords.pm b/perl/BadWords.pm
new file mode 100644 (file)
index 0000000..ff9dd04
--- /dev/null
@@ -0,0 +1,54 @@
+#
+# Search for bad words in strings
+#
+# Copyright (c) 2000 Dirk Koopman
+#
+# $Id$
+#
+
+package BadWords;
+
+use strict;
+
+use DXUtil;
+use DXVars;
+use IO::File;
+
+use vars qw(%badwords $fn);
+
+$fn = "$main::data/badwords";
+%badwords = ();
+
+# load the badwords file
+sub load
+{
+       my @out;
+       return unless -e $fn;
+       my $fh = new IO::File $fn;
+       
+       if ($fh) {
+               %badwords = ();
+               while (<$fh>) {
+                       chomp;
+                       next if /^\s*\#/;
+                       my @list = split " ";
+                       for (@list) {
+                               $badwords{lc $_}++;
+                       }
+               }
+               $fh->close;
+       } else {
+               my $l = "can't open $fn $!";
+               dbg('err', $l);
+               push @out, $l;
+       }
+       return @out;
+}
+
+# check the text against the badwords list
+sub check
+{
+       return grep { $badwords{$_} } split(/\b/, lc shift);
+}
+
+1;