/**
* parse str
    style='width:1' class="hello" checked=on
  as
  map[style:width:1 class:hello checked:on]
*/
517540
func StringToMap(str string) (data map[string]string) {
	re := regexp.MustCompile(`\s*([\w-]+)\s*=\s*(['"]?)(.*)`)
	data = make(map[string]string)
	matches := re.FindAllStringSubmatch(str, -1)
	if len(matches) > 0 {
		first := matches[0]
		var reg2_txt string
		if first[2] == "'" || first[2] == `"` {
			reg2_txt = fmt.Sprintf(`([^%s]*)%s(\s+.*)?`, first[2], first[2])
		} else if first[2] == "" {
			reg2_txt = `(\S+)\s*(.*)`
		}
		re2 := regexp.MustCompile(reg2_txt)
		subResult := re2.FindAllStringSubmatch(first[3], -1)

		if len(subResult) > 0 && len(subResult[0]) > 1 {
			data[first[1]] = subResult[0][1]
			if len(subResult[0][2]) > 0 {
				_subResult := StringToMap(subResult[0][2])
				for k, v := range _subResult {
					data[k] = v
				}
			}
		}
	}
	return
}
616505
func Parse(locale, text string, args ...interface{}) (r string, err error) {
	var data interface{}
	if len(args) > 0 {
		data = args[0]
	}

	mutex.RLock()
	tmpl := parseTextCache[text]
	mutex.RUnlock()

	p := parser{locale: locale, data: data}
	funcs := template.FuncMap{"p": p.parsePlural}
	for i := range args {
		arg := args[i]
		funcs[fmt.Sprintf("cldr_arg_%d", i+1)] = func() interface{} { return arg }
	}
	if tmpl == nil {
		for i := range args {
			text = strings.Replace(text, fmt.Sprintf("{{$%d}}", i+1), fmt.Sprintf("{{cldr_arg_%d}}", i+1), -1)
		}
		tmpl = template.New("").Funcs(parseFuncMap).Funcs(funcs)
		tmpl, err = tmpl.Parse(text)
		if err != nil {
			return
		}
		mutex.Lock()
		parseTextCache[text] = tmpl
		mutex.Unlock()
	} else {
		tmpl = tmpl.Funcs(funcs)
	}

	var buf bytes.Buffer
	if err = tmpl.Execute(&buf, data); err != nil {
		return
	}
	r = buf.String()
	return
}
1336764
func (c Config) Parse(s string) error {
	c.file = "<string>"
	c.input = s
	return c.parse()
}
539377
func ParseKind(s string) Kind {
	s = strings.ToLower(s)
	switch s {
	case "view":
		return KindView
	case "active":
		return KindActive
	case "committed":
		return KindCommitted
	}

	return KindUnknown
}
353291
func parse(str string, index int) *Pair {
	var key, value string
	if index > 0 {
		key, value = str[:index], str[index+1:]
	} else if index == 0 {
		key, value = "", str[1:]
	} else if index < 0 {
		key, value = str, ""
	}

	return &Pair{Key: key, Value: value}
}
420831
func (c *ComparativeTime) Parse(query string) error {
	if len(query) <= 2 {
		return errors.New("qstring: Invalid Timestamp Query")
	}

	c.Operator = parseOperator(query)

	// if no operator was provided and we defaulted to an equality operator
	if !strings.HasPrefix(query, c.Operator) {
		query = fmt.Sprintf("=%s", query)
	}

	var err error
	c.Time, err = time.Parse(time.RFC3339, query[len(c.Operator):])
	if err != nil {
		return err
	}

	return nil
}
243915
func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
	return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc)
}
322916
func (m *ChannelMap) Parse(s string) {
	cstr := C.CString(s)
	defer C.free(unsafe.Pointer(cstr))
	m.fromC(C.pa_channel_map_parse(m.toC(), cstr))
}
106997
func (parser *myParser) Parse(s string) error {
	typ := reflect.TypeOf(parser.ptr)
	val := reflect.ValueOf(parser.ptr)
	if typ.Kind() == reflect.Ptr {
		kind := reflect.Indirect(val).Type().Kind()
		if kind == reflect.Struct {
			typElem, valElem := typ.Elem(), val.Elem()
			numField := valElem.NumField()
			for i := 0; i < numField; i++ {
				_, valField := typElem.Field(i), valElem.Field(i)
				if valField.Kind() == reflect.Int &&
					valField.CanSet() {
					valField.SetInt(2)
				}
				if valField.Kind() == reflect.String &&
					valField.CanSet() {
					valField.SetString("B")
				}
			}
		}
	}
	return nil
}
10348
func (parser StringTypeParser) Parse(d DataType) error {
	if value, ok := AsString(d); ok {
		parser.setter(value)
	} else {
		return fmt.Errorf("Error parsing type of %#v as a String", d)
	}
	return nil
}
682065
func (p StringParser) Parse(field string) (result interface{}, err error) {
	return field, nil
}
321203
func Parse(e string) (*expr, string, error) {
	// skip whitespace
	for len(e) > 1 && e[0] == ' ' {
		e = e[1:]
	}

	if len(e) == 0 {
		return nil, "", ErrMissingExpr
	}

	if '0' <= e[0] && e[0] <= '9' || e[0] == '-' || e[0] == '+' {
		return parseConst(e)
	}

	if val, ok := strToBool(e); ok {
		// 'false' is 5 chars, 'true' is 4
		size := 5
		if val {
			size = 4
		}
		return &expr{bool: val, str: e[:size], etype: etBool}, e[size:], nil
	}

	if e[0] == '\'' || e[0] == '"' {
		val, e, err := parseString(e)
		return &expr{str: val, etype: etString}, e, err
	}

	name, e := parseName(e)

	if name == "" {
		return nil, e, ErrMissingArg
	}

	if e != "" && e[0] == '(' {
		for i := range name {
			if !isFnChar(name[i]) {
				return nil, "", ErrIllegalCharacter
			}
		}

		exp := &expr{str: name, etype: etFunc}

		ArgString, posArgs, namedArgs, e, err := parseArgList(e)
		exp.argsStr = ArgString
		exp.args = posArgs
		exp.namedArgs = namedArgs

		return exp, e, err
	}

	return &expr{str: name, etype: etName}, e, nil
}
283773
func Parse(data string, format string) (c Config, err error) {
	var raw map[string]interface{}
	switch format {
	case "json":
		err = json.Unmarshal([]byte(data), &raw)
	case "hcl":
		err = hcl.Decode(&raw, data)
	default:
		err = fmt.Errorf("invalid format: %s", format)
	}
	if err != nil {
		return Config{}, err
	}

	// We want to be able to report fields which we cannot map as an
	// error so that users find typos in their configuration quickly. To
	// achieve this we use the mapstructure library which maps a a raw
	// map[string]interface{} to a nested structure and reports unused
	// fields. The input for a mapstructure.Decode expects a
	// map[string]interface{} as produced by encoding/json.
	//
	// The HCL language allows to repeat map keys which forces it to
	// store nested structs as []map[string]interface{} instead of
	// map[string]interface{}. This is an ambiguity which makes the
	// generated structures incompatible with a corresponding JSON
	// struct. It also does not work well with the mapstructure library.
	//
	// In order to still use the mapstructure library to find unused
	// fields we patch instances of []map[string]interface{} to a
	// map[string]interface{} before we decode that into a Config
	// struct.
	//
	// However, Config has some fields which are either
	// []map[string]interface{} or are arrays of structs which
	// encoding/json will decode to []map[string]interface{}. Therefore,
	// we need to be able to specify exceptions for this mapping. The
	// patchSliceOfMaps() implements that mapping. All fields of type
	// []map[string]interface{} are mapped to map[string]interface{} if
	// it contains at most one value. If there is more than one value it
	// panics. To define exceptions one can specify the nested field
	// names in dot notation.
	//
	// todo(fs): There might be an easier way to achieve the same thing
	// todo(fs): but this approach works for now.
	m := patchSliceOfMaps(raw, []string{
		"checks",
		"segments",
		"service.checks",
		"services",
		"services.checks",
		"watches",
		"service.connect.proxy.config.upstreams", // Deprecated
		"services.connect.proxy.config.upstreams", // Deprecated
		"service.connect.proxy.upstreams",
		"services.connect.proxy.upstreams",
		"service.proxy.upstreams",
		"services.proxy.upstreams",

		// Need all the service(s) exceptions also for nested sidecar service except
		// managed proxy which is explicitly not supported there.
		"service.connect.sidecar_service.checks",
		"services.connect.sidecar_service.checks",
		"service.connect.sidecar_service.proxy.upstreams",
		"services.connect.sidecar_service.proxy.upstreams",

		"config_entries.bootstrap",
	})

	// There is a difference of representation of some fields depending on
	// where they are used. The HTTP API uses CamelCase whereas the config
	// files use snake_case and between the two there is no automatic mapping.
	// While the JSON and HCL parsers match keys without case (both `id` and
	// `ID` are mapped to an ID field) the same thing does not happen between
	// CamelCase and snake_case. Since changing either format would break
	// existing setups we have to support both and slowly transition to one of
	// the formats. Also, there is at least one case where we use the "wrong"
	// key and want to map that to the new key to support deprecation -
	// see [GH-3179]. TranslateKeys maps potentially CamelCased values to the
	// snake_case that is used in the config file parser. If both the CamelCase
	// and snake_case values are set the snake_case value is used and the other
	// value is discarded.
	lib.TranslateKeys(m, map[string]string{
		"deregistercriticalserviceafter": "deregister_critical_service_after",
		"dockercontainerid":              "docker_container_id",
		"scriptargs":                     "args",
		"serviceid":                      "service_id",
		"tlsskipverify":                  "tls_skip_verify",
	})

	var md mapstructure.Metadata
	d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
		Metadata: &md,
		Result:   &c,
	})
	if err != nil {
		return Config{}, err
	}
	if err := d.Decode(m); err != nil {
		return Config{}, err
	}
	for _, k := range md.Unused {
		err = multierror.Append(err, fmt.Errorf("invalid config key %s", k))
	}
	return
}
943675
func (p *parser) Parse() []Pattern {
	// keep parsing until there's no more patterns
	_patterns := make([]Pattern, 0)
	for {
		_pattern := p.Next()
		if _pattern == nil {
			return _patterns
		}
		_patterns = append(_patterns, _pattern)
	}
}
47336
func Parse(in string) *Version {
	v := &Version{}

	sp := strings.Split(in, ".")
	if len(sp) != 3 {
		v.err = errors.Errorf("passed string is not following to semver: %s", in)
		return v
	}

	v.major(sp[0])
	v.minor(sp[1])
	v.patch(sp[2])

	return v
}
54239
func (m *configurableRegexMetricDeconstructor) Parse(originalMetric string) (string, datapoint.MetricType, map[string]string, error) {
	for _, metric := range m.MetricRules {
		if metric.Compiled.MatchString(originalMetric) {
			ms := metric.Compiled.FindStringSubmatch(originalMetric)
			nms := metric.Compiled.SubexpNames()
			dimensions := map[string]string{}
			metricNamePieces := []string{}
			metricNameLookup := map[string]string{}

			for i := 1; i < len(ms); i++ {
				if strings.HasPrefix(nms[i], "sf_metric") {
					metricNamePieces = append(metricNamePieces, nms[i])
					metricNameLookup[nms[i]] = ms[i]
				} else {
					dimensions[nms[i]] = ms[i]
				}
			}
			for k, v := range metric.AdditionalDimensions {
				dimensions[k] = v
			}

			sort.Strings(metricNamePieces)
			metricName := []string{metric.MetricName}
			for _, piece := range metricNamePieces {
				metricName = append(metricName, metricNameLookup[piece])
			}
			actualMetricName := strings.Join(metricName, "")
			if actualMetricName == "" {
				actualMetricName = originalMetric
			}
			return actualMetricName, metric.MetricType, dimensions, nil
		}
	}

	return m.FallBackDeconstructor.Parse(originalMetric)
}
1364037
func (p TimeParser) Parse(field string) (result interface{}, err error) {
	return time.Parse(p.Layout, field)
}