From e56ab47c437cd0e7d5f80309bf2b70dcbb07a274 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 23 Jan 2020 19:32:10 +0100 Subject: [PATCH] carddav: add negateCondition --- carddav/elements.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/carddav/elements.go b/carddav/elements.go index c5d1ef3..effcfab 100644 --- a/carddav/elements.go +++ b/carddav/elements.go @@ -100,11 +100,32 @@ type propFilter struct { // https://tools.ietf.org/html/rfc6352#section-10.5.4 type textMatch struct { - XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav text-match"` - Text string `xml:",chardata"` - Collation string `xml:"collation,attr,omitempty"` - NegateCondition string `xml:"negate-condition,attr,omitempty"` - MatchType matchType `xml:"match-type,attr,omitempty"` + XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav text-match"` + Text string `xml:",chardata"` + Collation string `xml:"collation,attr,omitempty"` + NegateCondition negateCondition `xml:"negate-condition,attr,omitempty"` + MatchType matchType `xml:"match-type,attr,omitempty"` +} + +type negateCondition bool + +func (nc *negateCondition) UnmarshalText(b []byte) error { + switch s := string(b); s { + case "yes": + *nc = true + case "no": + *nc = false + default: + return fmt.Errorf("carddav: invalid negate-condition value: %q", s) + } + return nil +} + +func (nc negateCondition) MarshalText() ([]byte, error) { + if nc { + return []byte("yes"), nil + } + return nil, nil } type matchType string