// FiltersFromString is a helper that creates regex style filters from a \n separated string of
// : separated id -> regex pairs.
191893
func FiltersFromString(newRegex string) (map[string]*regexp.Regexp, error) {
	if newRegex == "" {
		return nil, nil
	}
	lines := strings.Split(newRegex, "\n")
	newFilters := make(map[string]*regexp.Regexp, len(lines))
	for _, line := range lines {
		lineParts := strings.SplitN(line, ":", 2)
		if len(lineParts) != 2 || lineParts[0] == "" || lineParts[1] == "" {
			return nil, errors.Errorf("Cannot parse line %s", line)
		}
		reg, err := regexp.Compile(lineParts[1])
		if err != nil {
			return nil, errors.Annotatef(err, "Cannot parse regex line %s", line)
		}
		newFilters[lineParts[0]] = reg
	}
	return newFilters, nil
}
925524
func Filter(slice []string, handler func(string) bool) []string {
	filtered := []string{}
	for _, element := range slice {
		if handler(element) {
			filtered = append(filtered, element)
		}
	}
	return filtered
}
166128
func (i *GetWAFRuleStatusesInput) formatFilters() map[string]string {
	input := i.Filters
	result := map[string]string{}
	pairings := map[string]interface{}{
		"filter[status]":           input.Status,
		"filter[rule][accuracy]":   input.Accuracy,
		"filter[rule][maturity]":   input.Maturity,
		"filter[rule][message]":    input.Message,
		"filter[rule][revision]":   input.Revision,
		"filter[rule][rule_id]":    input.RuleID,
		"filter[rule][tags]":       input.TagID,
		"filter[rule][tags][name]": input.TagName,
		"filter[rule][version]":    input.Version,
		"include":                  input.Tags,
		"page[size]":               input.MaxResults,
		"page[number]":             input.Page, // starts at 1, not 0
	}
	// NOTE: This setup means we will not be able to send the zero value
	// of any of these filters. It doesn't appear we would need to at present.
	for key, value := range pairings {
		switch t := reflect.TypeOf(value).String(); t {
		case "string":
			if value != "" {
				result[key] = value.(string)
			}
		case "int":
			if value != 0 {
				result[key] = strconv.Itoa(value.(int))
			}
		case "[]int":
			// convert ints to strings
			toStrings := []string{}
			values := value.([]int)
			for _, i := range values {
				toStrings = append(toStrings, strconv.Itoa(i))
			}
			// concat strings
			if len(values) > 0 {
				result[key] = strings.Join(toStrings, ",")
			}
		}
	}
	return result
}
683788
func (r Render) AddFromStringsFuncs(name string, funcMap template.FuncMap, templateStrings ...string) *template.Template {
	tmpl := template.New(name).Funcs(funcMap)

	for _, ts := range templateStrings {
		tmpl = template.Must(tmpl.Parse(ts))
	}

	r.Add(name, tmpl)
	return tmpl
}
1138264
func TypeFromString(s string) (Type, error) {
	for t, str := range toString {
		if s == str {
			return t, nil
		}
	}
	return NoError, fmt.Errorf("invalid Type: %s", s)
}
963372
func (r *report) filter(cum bool, focus *regexp.Regexp) []string {
	r.mu.Lock()
	defer r.mu.Unlock()
	if r.p == nil {
		return nil
	}
	c := r.p.Copy()
	c.FilterSamplesByName(focus, nil, nil)
	rpt := goreport.NewDefault(c, goreport.Options{
		OutputFormat:   goreport.Text,
		CumSort:        cum,
		PrintAddresses: true,
	})
	buf := bytes.NewBuffer(nil)
	goreport.Generate(buf, rpt, nil)
	return strings.Split(buf.String(), "\n")
}
394381
func ClassFromString(s string) (Class, error) {
	switch s {
	case "all":
		return All, nil
	case "success":
		return Success, nil
	case "denial":
		return Denial, nil
	case "error":
		return Error, nil
	}
	return All, fmt.Errorf("invalid Class: %s", s)
}
900265
func SplitFilter(s, sep string, f func(p string) bool) []string {
	parts := strings.Split(s, sep)
	out := []string{}
	for _, part := range parts {
		if f(part) {
			out = append(out, part)
		}
	}
	return out
}
1251962
func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
	format := formatAutoFilter{}
	err := json.Unmarshal([]byte(formatSet), &format)
	return &format, err
}
371973
func Filter(elements map[string]interface{}, keys ...string) map[string]interface{} {
	var keyIdx = make(map[string]bool)
	var result = make(map[string]interface{})

	for _, key := range keys {
		keyIdx[key] = true
	}

	for k, e := range elements {
		if _, ok := keyIdx[k]; !ok {
			result[k] = e
		}
	}

	return result
}
25968
func (b *FilterQueryBuilder) AddQueryStringFilter(querystring string, analyseWildcard bool) *FilterQueryBuilder {
	if len(strings.TrimSpace(querystring)) == 0 {
		return b
	}

	b.filters = append(b.filters, &QueryStringFilter{
		Query:           querystring,
		AnalyzeWildcard: analyseWildcard,
	})
	return b
}
655285
func TagsFilter(t map[string]string) Filter {
	j := tagsEncoder(t, false)
	return Param("tags", j)
}
283851
func (f *RegexFilter) GetFilters() map[string]*regexp.Regexp {
	f.mu.RLock()
	ret := f.currentFilters
	f.mu.RUnlock()
	return ret
}
552896
func (s *NestedSort) Filter(filter Query) *NestedSort {
	s.filter = filter
	return s
}
875905
func Filtered(paths []string, filter Filter) (*Result, error) {
	return all(paths, filter, func(curr *Result, path string, depth int) error {

		bs, err := ioutil.ReadFile(path)
		if err != nil {
			return err
		}

		result, err := loadKnownTypes(path, bs)
		if err != nil {
			if !isUnrecognizedFile(err) {
				return err
			}
			if depth > 0 {
				return nil
			}
			result, err = loadFileForAnyType(path, bs)
			if err != nil {
				return err
			}
		}

		return curr.merge(path, result)
	})
}
669367
func (view *View) RenderFromString(loaderName string, tplSrc string, data map[string]interface{}) (string, error) {
	var buf bytes.Buffer
	// If loaderName is not indicated, use the default template library of Go, no syntax like
	// `extends` or `include` will be supported.
	if loaderName == "" {
		tmpl := template.New("error")
		tmpl.Parse(tplSrc)
		e := tmpl.Execute(&buf, data)
		return buf.String(), e
	}
	loader, ok := view.templateLoader[loaderName]
	if !ok {
		panic(Errorf("Template loader not fount: %s", loaderName))
	}
	e := loader.Render(&buf, tplSrc, data)
	if e != nil {
		return "", e
	}
	return buf.String(), nil
}
1265889
func DataTypeFromString(s string) DataType {
	switch s {
	case "float":
		return Float
	case "integer":
		return Integer
	case "unsigned":
		return Unsigned
	case "string":
		return String
	case "boolean":
		return Boolean
	case "time":
		return Time
	case "duration":
		return Duration
	case "tag":
		return Tag
	case "field":
		return AnyField
	default:
		return Unknown
	}
}