carddav: add matchType

This commit is contained in:
Simon Ser 2020-01-23 19:27:31 +01:00
parent 38b729ad9c
commit 30977aac83
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -77,7 +77,7 @@ const (
) )
func (ft *filterTest) UnmarshalText(b []byte) error { func (ft *filterTest) UnmarshalText(b []byte) error {
v := filterTest(string(b)) v := filterTest(b)
switch v { switch v {
case filterAnyOf, filterAllOf: case filterAnyOf, filterAllOf:
*ft = v *ft = v
@ -104,7 +104,27 @@ type textMatch struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
Collation string `xml:"collation,attr,omitempty"` Collation string `xml:"collation,attr,omitempty"`
NegateCondition string `xml:"negate-condition,attr,omitempty"` NegateCondition string `xml:"negate-condition,attr,omitempty"`
MatchType string `xml:"match-type,attr,omitempty"` MatchType matchType `xml:"match-type,attr,omitempty"`
}
type matchType string
const (
matchEquals matchType = "equals"
matchContains matchType = "contains"
matchStartsWith matchType = "starts-with"
matchEndsWith matchType = "ends-with"
)
func (mt *matchType) UnmarshalText(b []byte) error {
v := matchType(b)
switch v {
case matchEquals, matchContains, matchStartsWith, matchEndsWith:
*mt = v
return nil
default:
return fmt.Errorf("carddav: invalid match type value: %q", v)
}
} }
// https://tools.ietf.org/html/rfc6352#section-10.5.2 // https://tools.ietf.org/html/rfc6352#section-10.5.2