bufr/runefunc.go

57 lines
840 B
Go
Raw Permalink Normal View History

2023-01-20 23:59:36 +01:00
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 IsTab(rn rune) bool {
return rn == '\t'
}
2023-01-20 23:59:36 +01:00
func IsWhitespace(rn rune) bool {
return IsSpace(rn) || IsTab(rn) || IsNewLine(rn)
2023-01-20 23:59:36 +01:00
}
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)
}
}