bufr/runefunc.go
2023-01-20 23:59:36 +01:00

53 lines
778 B
Go

package bufr
import "git.milar.in/milarin/ds"
type RuneFunc = func(rn rune) bool
func IsNewLine(rn rune) bool {
return rn == '\n'
}
func IsSpace(rn rune) bool {
return rn == ' '
}
func IsWhitespace(rn rune) bool {
return IsSpace(rn) || IsNewLine(rn)
}
func And(f ...RuneFunc) RuneFunc {
return func(rn rune) bool {
return findFirstFalse(rn, f)
}
}
func Or(f ...RuneFunc) RuneFunc {
return func(rn rune) bool {
return findFirstTrue(rn, f)
}
}
func Not(f RuneFunc) RuneFunc {
return func(rn rune) bool {
return !f(rn)
}
}
func Is(rn rune) RuneFunc {
return func(r rune) bool {
return rn == r
}
}
func OneOf(runes string) RuneFunc {
m := ds.NewSet[rune]()
for _, rn := range runes {
m.Add(rn)
}
return func(r rune) bool {
return m.Has(r)
}
}