# README
gofuckyourself
A sanitization-based swear filter for Go.
Installing
Just import github.com/boosh/swearfilter
if using go modules.
Example
package main
import (
"fmt"
"github.com/boosh/swearfilter"
)
var message = "This is a fûçking message with shitty swear words asswipe."
var swears = []string{"fuck", "shit", "^ass"}
func main() {
filter := NewSwearFilter(false, swears...)
swearFound, swearsFound, err := filter.Check(message)
fmt.Println("Swear found: ", swearFound)
fmt.Println("Swears tripped: ", swearsFound)
fmt.Println("Error: ", err)
}
Output
> go run main.go
Swear found: true
Swears tripped: [fuck shit ^ass]
Error: <nil>
Options
By default substring testing is performed, e.g. so abc
will match any of 1abc
, 1abc2
and abc2
.
To help keep word lists concise but performance good, simple (simulated) regex matching is supported. The only control characters supported are ^
and $
. These will perform prefix/suffix string match tests respectively. E.g. so ^ass
will match asses
but not pass
. These simple regexes aren't compiled to regexes internally so may be faster (but they haven't been benchmarked).
Full regex support can be enabled by passing the relevant parameter when calling swearfilter.New
. In this case, each swear word will be compiled to a regex and tested with regex matching.
License
The source code for gofuckyourself is released under the MIT License. See LICENSE for more details.