func()

in go/metadata/capabilities/capabilities.go [604:655]


func (c *Capabilities) StripAllPrefixedExcept(ex ...string) *Capabilities {
	exemptions := map[string]bool{}
	for _, e := range ex {
		exemptions[e] = true
	}

	// Get the always match capabilities.
	am := map[string]interface{}{}
	for k, v := range c.AlwaysMatch {
		if v != nil {
			am[k] = v
		}
	}

	// Get the first match capabilities
	var fms []map[string]interface{}
	for _, fm := range c.FirstMatch {
		newFM := map[string]interface{}{}
		for k, v := range fm {
			if v != nil {
				newFM[k] = v
			}
		}
		fms = append(fms, newFM)
	}

	// Delete prefixed, non-exempt always match capabilities.
	for c := range am {
		if tokens := strings.Split(c, ":"); len(tokens) == 2 {
			if !exemptions[tokens[0]] {
				delete(am, c)
			}
		}
	}

	// Delete prefixed, non-exempt first match capabilities.
	for _, fm := range fms {
		for c := range fm {
			if tokens := strings.Split(c, ":"); len(tokens) == 2 {
				if !exemptions[tokens[0]] {
					delete(fm, c)
				}
			}
		}
	}

	return &Capabilities{
		AlwaysMatch:  am,
		FirstMatch:   fms,
		W3CSupported: c.W3CSupported,
	}
}