// ParseToMultiMap parses the specified text and returns a map with the
// results. Values are stored in an string slice, so values from captures with
// the same name don't get overridden.
434736
func (g *Grok) ParseToMultiMap(pattern, text string) (map[string][]string, error) {
	gr, err := g.compile(pattern)
	if err != nil {
		return nil, err
	}

	captures := make(map[string][]string)
	if match := gr.regexp.FindStringSubmatch(text); len(match) > 0 {
		for i, name := range gr.regexp.SubexpNames() {
			if name != "" {
				if g.config.RemoveEmptyValues == true && match[i] == "" {
					continue
				}
				name = g.nameToAlias(name)
				captures[name] = append(captures[name], match[i])
			}
		}
	}

	return captures, nil
}
1255179
func ParseTagSliceToMap(tags []string) map[string]string {
	mappedTags := make(map[string]string)
	for _, tag := range tags {
		splt := strings.SplitN(tag, ":", 2)
		if len(splt) < 2 {
			mappedTags[splt[0]] = ""
		} else {
			mappedTags[splt[0]] = splt[1]
		}
	}
	return mappedTags
}
45146
func (e *EtcdStore) GetMultiMap(prefix string) (map[string]io.Reader, error) {
	kv := make(map[string]io.Reader)
	recursive := true
	res, err := get(e, prefix, recursive)
	if err != nil {
		return kv, err
	}
	extractKeyValues(res.Node, kv)
	return kv, nil
}
980298
func stringMapFromValue(val cty.Value) map[string]string {
	m := map[string]string{}
	if val.IsNull() || !val.IsKnown() {
		return m
	}

	for it := val.ElementIterator(); it.Next(); {
		ak, av := it.Element()
		name := ak.AsString()

		if !av.IsKnown() || av.IsNull() {
			continue
		}

		av, _ = ctyconvert.Convert(av, cty.String)
		m[name] = av.AsString()
	}

	return m
}
528503
func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
	format := formatPicture{
		FPrintsWithSheet: true,
		FLocksWithSheet:  false,
		NoChangeAspect:   false,
		OffsetX:          0,
		OffsetY:          0,
		XScale:           1.0,
		YScale:           1.0,
	}
	err := json.Unmarshal(parseFormatSet(formatSet), &format)
	return &format, err
}
593066
func (br *Reader) readContextMap(cm []uint8, numTrees uint) {
	// TODO(dsnet): Test the following edge cases:
	// * Test with largest and smallest MAXRLE sizes
	// * Test with with very large MAXRLE value
	// * Test inverseMoveToFront

	maxRLE := br.rd.ReadSymbol(&decMaxRLE)
	br.rd.ReadPrefixCode(&br.rd.prefix, maxRLE+numTrees)
	for i := 0; i < len(cm); {
		sym := br.rd.ReadSymbol(&br.rd.prefix)
		if sym == 0 || sym > maxRLE {
			// Single non-zero value.
			if sym > 0 {
				sym -= maxRLE
			}
			cm[i] = uint8(sym)
			i++
		} else {
			// Repeated zeros.
			n := int(br.rd.ReadOffset(sym-1, maxRLERanges))
			if i+n > len(cm) {
				errors.Panic(errCorrupted)
			}
			for j := i + n; i < j; i++ {
				cm[i] = 0
			}
		}
	}

	if invert := br.rd.ReadBits(1) == 1; invert {
		br.mtf.Decode(cm)
	}
}
411799
func (v Values) AsMap() map[string]interface{} {
	if v == nil || len(v) == 0 {
		return map[string]interface{}{}
	}
	return v
}
479921
func parseAnnotationsString(a map[string]string, key string, def string) string {
	if v, ok := a[key]; ok {
		return v
	}
	return def
}
225762
func ParseMetadataListFromParams(p params.CloudImageMetadataList, cfg *config.Config) []cloudimagemetadata.Metadata {
	results := make([]cloudimagemetadata.Metadata, len(p.Metadata))
	for i, metadata := range p.Metadata {
		results[i] = cloudimagemetadata.Metadata{
			MetadataAttributes: cloudimagemetadata.MetadataAttributes{
				Stream:          metadata.Stream,
				Region:          metadata.Region,
				Version:         metadata.Version,
				Series:          metadata.Series,
				Arch:            metadata.Arch,
				VirtType:        metadata.VirtType,
				RootStorageType: metadata.RootStorageType,
				RootStorageSize: metadata.RootStorageSize,
				Source:          metadata.Source,
			},
			Priority: metadata.Priority,
			ImageId:  metadata.ImageId,
		}
		// TODO (anastasiamac 2016-08-24) This is a band-aid solution.
		// Once correct value is read from simplestreams, this needs to go.
		// Bug# 1616295
		if results[i].Stream == "" {
			results[i].Stream = cfg.ImageStream()
		}
	}
	return results
}
1114546
func (t *Translator) parseFormat(pattern string, includeDecimalDigits bool) *numberFormat {

	processed := false
	if includeDecimalDigits {
		_, processed = numberFormats[pattern]
	} else {
		_, processed = numberFormatsNoDecimals[pattern]
	}

	if !processed {

		format := new(numberFormat)
		patterns := strings.Split(pattern, ";")

		matches := prefixSuffixRegex.FindAllStringSubmatch(patterns[0], -1)
		if len(matches) > 0 {
			if len(matches[0]) > 1 {
				format.positivePrefix = matches[0][1]
			}
			if len(matches[0]) > 2 {
				format.positiveSuffix = matches[0][2]
			}
		}

		// default values for negative prefix & suffix
		format.negativePrefix = string(t.rules.Numbers.Symbols.Negative) + string(format.positivePrefix)
		format.negativeSuffix = format.positiveSuffix

		// see if they are in the pattern
		if len(patterns) > 1 {
			matches = prefixSuffixRegex.FindAllStringSubmatch(patterns[1], -1)

			if len(matches) > 0 {
				if len(matches[0]) > 1 {
					format.negativePrefix = matches[0][1]
				}
				if len(matches[0]) > 2 {
					format.negativeSuffix = matches[0][2]
				}
			}
		}

		pat := patterns[0]

		if strings.Index(pat, "%") != -1 {
			format.multiplier = 100
		} else if strings.Index(pat, "‰") != -1 {
			format.multiplier = 1000
		} else {
			format.multiplier = 1
		}

		pos := strings.Index(pat, ".")

		if pos != -1 {
			pos2 := strings.LastIndex(pat, "0")
			if pos2 > pos {
				format.minDecimalDigits = pos2 - pos
			}

			pos3 := strings.LastIndex(pat, "#")
			if pos3 >= pos2 {
				format.maxDecimalDigits = pos3 - pos
			} else {
				format.maxDecimalDigits = format.minDecimalDigits
			}

			pat = pat[0:pos]
		}

		p := strings.Replace(pat, ",", "", -1)
		pos = strings.Index(p, "0")
		if pos != -1 {
			format.minIntegerDigits = strings.LastIndex(p, "0") - pos + 1
		}

		p = strings.Replace(pat, "#", "0", -1)
		pos = strings.LastIndex(pat, ",")
		if pos != -1 {
			format.groupSizeFinal = strings.LastIndex(p, "0") - pos
			pos2 := strings.LastIndex(p[0:pos], ",")
			if pos2 != -1 {
				format.groupSizeMain = pos - pos2 - 1
			} else {
				format.groupSizeMain = format.groupSizeFinal
			}
		}

		if includeDecimalDigits {
			numberFormats[pattern] = format
		} else {
			format.maxDecimalDigits = 0
			format.minDecimalDigits = 0
			numberFormatsNoDecimals[pattern] = format
		}

	}

	if includeDecimalDigits {
		return numberFormats[pattern]
	}

	return numberFormatsNoDecimals[pattern]
}
321915
func SplitMap(s, sep string, m func(p string) (string, bool)) []string {
	parts := strings.Split(s, sep)
	out := []string{}
	for _, part := range parts {
		if mp, ok := m(part); ok {
			out = append(out, mp)
		}
	}
	return out
}
1002659
func flattenMultiMaps(m map[string]interface{}) error {
	for k, v := range m {
		switch v := v.(type) {
		case []map[string]interface{}:
			switch {
			case len(v) > 1:
				return fmt.Errorf("multiple map declarations not supported for variables")
			case len(v) == 1:
				m[k] = v[0]
			}
		}
	}
	return nil
}
307386
func optArgsToMap(optArgs OptArgs) map[string]interface{} {
	data, err := encode(optArgs)

	if err == nil && data != nil {
		if m, ok := data.(map[string]interface{}); ok {
			return m
		}
	}

	return map[string]interface{}{}
}
912285
func ParseTypeMap(args []string) (map[string]rewrite.Type, error) {
	typeMap := make(map[string]rewrite.Type)

	for _, arg := range args {
		part := strings.Split(arg, "->")

		if len(part) != 2 {
			return nil, errors.New("RULE must be in form of `TypeXXX->OtherType`")
		}

		var (
			from = strings.TrimSpace(part[0])
			to   = strings.TrimSpace(part[1])
		)

		if !strings.HasPrefix(from, "Type") {
			return nil, errors.New("REPL type must start with `Type`")
		}

		var t rewrite.Type
		if strings.Contains(to, ":") {
			toPart := strings.Split(to, ":")

			if len(toPart) != 2 {
				return nil, errors.New("REPL type must be in form of DESTPATH:OtherType")
			}

			t.Import = []string{strings.TrimSpace(toPart[0])}
			t.Expr = strings.TrimSpace(toPart[1])
			if strings.Count(t.Expr, ".") != 1 {
				return nil, errors.New("REPL type must contain one `.`")
			}
		} else {
			t.Expr = to
			if strings.Count(t.Expr, ".") != 0 {
				return nil, errors.New("REPL type must not contain `.`")
			}
		}
		if t.Expr == "" {
			return nil, errors.New("REPL type cannot be empty")
		}

		typeMap[from] = t
	}
	return typeMap, nil
}
128035
func (p *PilosaKeyMapper) MapResult(field string, res interface{}) (mappedRes interface{}, err error) {
	log.Printf("mapping result: '%#v'", res)
	defer func() {
		log.Printf("mapped result: '%#v'", mappedRes)
	}()
	switch result := res.(type) {
	case uint64:
		// Count
		mappedRes = result
	case []interface{}:
		return p.mapSliceInterfaceResult(field, result)
	case map[string]interface{}:
		// Bitmap/Intersect/Difference/Union
		return p.mapBitmapResult(field, result)
	case bool:
		// SetBit/ClearBit
		mappedRes = result
	default:
		// Range? SetRowAttrs?
		mappedRes = result
	}
	return mappedRes, nil
}
1276063
func (g *Grok) ParseTyped(pattern string, text string) (map[string]interface{}, error) {
	gr, err := g.compile(pattern)
	if err != nil {
		return nil, err
	}
	match := gr.regexp.FindStringSubmatch(text)
	captures := make(map[string]interface{})
	if len(match) > 0 {
		for i, segmentName := range gr.regexp.SubexpNames() {
			if len(segmentName) != 0 {
				if g.config.RemoveEmptyValues == true && match[i] == "" {
					continue
				}
				name := g.nameToAlias(segmentName)
				if segmentType, ok := gr.typeInfo[segmentName]; ok {
					switch segmentType {
					case "int":
						captures[name], _ = strconv.Atoi(match[i])
					case "float":
						captures[name], _ = strconv.ParseFloat(match[i], 64)
					default:
						return nil, fmt.Errorf("ERROR the value %s cannot be converted to %s", match[i], segmentType)
					}
				} else {
					captures[name] = match[i]
				}
			}

		}
	}

	return captures, nil
}
1019905
func ParseTag(str string) map[string]string {
	tags := strings.Split(str, ";")
	setting := map[string]string{}
	for _, value := range tags {
		v := strings.Split(value, ":")
		k := strings.TrimSpace(strings.ToUpper(v[0]))
		if len(v) == 2 {
			setting[k] = v[1]
		} else {
			setting[k] = k
		}
	}
	return setting
}