github.com/safing/portbase@v0.19.5/database/query/condition-not.go (about) 1 package query 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/safing/portbase/database/accessor" 8 ) 9 10 // Not negates the supplied condition. 11 func Not(c Condition) Condition { 12 return ¬Cond{ 13 notC: c, 14 } 15 } 16 17 type notCond struct { 18 notC Condition 19 } 20 21 func (c *notCond) complies(acc accessor.Accessor) bool { 22 return !c.notC.complies(acc) 23 } 24 25 func (c *notCond) check() error { 26 return c.notC.check() 27 } 28 29 func (c *notCond) string() string { 30 next := c.notC.string() 31 if strings.HasPrefix(next, "(") { 32 return fmt.Sprintf("not %s", c.notC.string()) 33 } 34 splitted := strings.Split(next, " ") 35 return strings.Join(append([]string{splitted[0], "not"}, splitted[1:]...), " ") 36 }