diff options
| author | Felix Hanley <felix@userspace.com.au> | 2023-09-16 14:55:13 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2023-09-16 14:55:13 +0000 |
| commit | 1c0f1fb778ced17cc61a1cce69e8afa9ab166f5a (patch) | |
| tree | 1381969dc6d9b01836c29915247c3279aace17cf /generator.go | |
| parent | 3a41ac75bdb15675c9507cb54de40b01fe9ec5af (diff) | |
| download | bechars-1c0f1fb778ced17cc61a1cce69e8afa9ab166f5a.tar.gz bechars-1c0f1fb778ced17cc61a1cce69e8afa9ab166f5a.tar.bz2 | |
Diffstat (limited to 'generator.go')
| -rw-r--r-- | generator.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/generator.go b/generator.go index 881ce45..d80bfb1 100644 --- a/generator.go +++ b/generator.go @@ -3,6 +3,7 @@ package bechars import ( "fmt" "strings" + "unicode" "src.userspace.com.au/lexer" ) @@ -22,6 +23,7 @@ type Generator struct { tok *lexer.Token maxRune *rune minRune *rune + graphic bool } // Option functions allows configuration of the generator. @@ -54,6 +56,14 @@ func MinRune(r rune) Option { } } +// OnlyGraphic filters non-visible characters +func OnlyGraphic(b bool) Option { + return func(g *Generator) error { + g.graphic = b + return nil + } +} + func ensureRangeLimits(g *Generator) { if g.maxRune == nil { maxRune := '\u007F' @@ -197,6 +207,10 @@ func (g *Generator) filter(in, exclude string) string { if strings.ContainsRune(exclude, r) { continue } + if g.graphic && !unicode.IsGraphic(r) { + fmt.Println("non-graphic", r) + continue + } out.WriteRune(r) } return out.String() |
