aboutsummaryrefslogtreecommitdiff
path: root/generator.go
diff options
context:
space:
mode:
Diffstat (limited to 'generator.go')
-rw-r--r--generator.go14
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()