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