func (filters Args) FuzzyMatch(field, source string) bool {
	if filters.ExactMatch(field, source) {
		return true
	}
	fieldValues := filters.fields[field]
	for prefix := range fieldValues {
		if strings.HasPrefix(source, prefix) {
			return true
		}
	}
	return false
}
FuzzyMatch returns true if the source matches exactly one of the filters,
or the source has one of the filters as a prefix.
package filters
import (
	"encoding/json"
	"errors"
	"fmt"
	"regexp"
	"strings"
	"github.com/docker/docker/api/types/versions"
)
type Args struct {
	fields map[string]map[string]bool
}
func NewArgs() Args {
	return Args{fields: map[string]map[string]bool{}}
}
func ParseFlag(arg string, prev Args) (Args, error) {
	filters := prev
	if len(arg) == 0 {
		return filters, nil
	}
	if !strings.Contains(arg, "=") {
		return filters, ErrBadFormat
	}
	f := strings.SplitN(arg, "=", 2)
	name := strings.ToLower(strings.TrimSpace(f[0]))
	value := strings.TrimSpace(f[1])
	filters.Add(name, value)
	return filters, nil
}
var ErrBadFormat = errors.New("bad format of filter (expected name=value)")
func ToParam(a Args) (string, error) {
	if a.Len() == 0 {
		return "", nil
	}
	buf, err := json.Marshal(a.fields)
	if err != nil {
		return "", err
	}
	return string(buf), nil
}
func ToParamWithVersion(version string, a Args) (string, error) {
	if a.Len() == 0 {
		return "", nil
	}
	buf := []byte{}
	err := errors.New("")
	if version != "" && versions.LessThan(version, "1.22") {
		buf, err = json.Marshal(convertArgsToSlice(a.fields))
	} else {
		buf, err = json.Marshal(a.fields)
	}
	if err != nil {
		return "", err
	}
	return string(buf), nil
}
func FromParam(p string) (Args, error) {
	if len(p) == 0 {
		return NewArgs(), nil
	}
	r := strings.NewReader(p)
	d := json.NewDecoder(r)
	m := map[string]map[string]bool{}
	if err := d.Decode(&m); err != nil {
		r.Seek(0, 0)
		deprecated := map[string][]string{}
		if deprecatedErr := d.Decode(&deprecated); deprecatedErr == nil {
			m = deprecatedArgs(deprecated)
		} else {
			return NewArgs(), err
		}
	}
	return Args{m}, nil
}
func (filters Args) Get(field string) []string {
	values := filters.fields[field]
	if values == nil {
		return make([]string, 0)
	}
	slice := make([]string, 0, len(values))
	for key := range values {
		slice = append(slice, key)
	}
	return slice
}
func (filters Args) Add(name, value string) {
	if _, ok := filters.fields[name]; ok {
		filters.fields[name][value] = true
	} else {
		filters.fields[name] = map[string]bool{value: true}
	}
}
func (filters Args) Del(name, value string) {
	if _, ok := filters.fields[name]; ok {
		delete(filters.fields[name], value)
		if len(filters.fields[name]) == 0 {
			delete(filters.fields, name)
		}
	}
}
func (filters Args) Len() int {
	return len(filters.fields)
}
func (filters Args) MatchKVList(field string, sources map[string]string) bool {
	fieldValues := filters.fields[field]
	if len(fieldValues) == 0 {
		return true
	}
	if len(sources) == 0 {
		return false
	}
	for name2match := range fieldValues {
		testKV := strings.SplitN(name2match, "=", 2)
		v, ok := sources[testKV[0]]
		if !ok {
			return false
		}
		if len(testKV) == 2 && testKV[1] != v {
			return false
		}
	}
	return true
}
func (filters Args) Match(field, source string) bool {
	if filters.ExactMatch(field, source) {
		return true
	}
	fieldValues := filters.fields[field]
	for name2match := range fieldValues {
		match, err := regexp.MatchString(name2match, source)
		if err != nil {
			continue
		}
		if match {
			return true
		}
	}
	return false
}
func (filters Args) ExactMatch(field, source string) bool {
	fieldValues, ok := filters.fields[field]
	if !ok || len(fieldValues) == 0 {
		return true
	}
	return fieldValues[source]
}
func (filters Args) UniqueExactMatch(field, source string) bool {
	fieldValues := filters.fields[field]
	if len(fieldValues) == 0 {
		return true
	}
	if len(filters.fields[field]) != 1 {
		return false
	}
	return fieldValues[source]
}