// Parse a properties file to a map.
502290
func readPropertiesFile(filePath string) (map[string]string, error) {
	props, err := properties.LoadFile(filePath, properties.UTF8)
	if err != nil {
		return nil, err
	}

	return props.Map(), nil
}
851571
func (env *Glisp) ParseFile(file string) ([]Sexp, error) {
	in, err := os.Open(file)
	if err != nil {
		return nil, err
	}

	var exp []Sexp

	exp, err = env.ParseStream(in)

	in.Close()

	return exp, err
}
11187
func (js *JSONConfig) Parse(filename string) (Configer, error) {
	file, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer file.Close()
	content, err := ioutil.ReadAll(file)
	if err != nil {
		return nil, err
	}

	return js.ParseData(content)
}
1093305
func (b *PersonJSONBuilder) Properties() []*PersonPropertyInfo {
	return []*PersonPropertyInfo{
		b.Name,
		b.Age,
		b.Password,
	}
}
182869
func (b *SampleJSONBuilder) Properties() []*SamplePropertyInfo {
	return []*SamplePropertyInfo{
		b.B,
		b.C,
		b.D,
		b.E,
	}
}
911802
func properties(props *structpb.Struct) []property {
	if props == nil {
		return nil
	}
	// Render the fields to JSON.
	m := jsonpb.Marshaler{}
	buf := bytes.NewBuffer(nil)
	if err := m.Marshal(buf, props); err != nil {
		panic(err) // This shouldn't happen.
	}
	d := json.NewDecoder(buf)
	jsonProps := map[string]json.RawMessage{}
	if err := d.Decode(&jsonProps); err != nil {
		panic(err) // This shouldn't happen.
	}

	// Sort the names.
	names := make([]string, 0, len(jsonProps))
	for n := range jsonProps {
		names = append(names, n)
	}
	sort.Strings(names)

	// Rearrange the fields into a slice.
	results := make([]property, len(jsonProps))
	for i, n := range names {
		buf.Reset()
		json.Indent(buf, jsonProps[n], "", "  ")
		results[i] = property{
			Name:  n,
			Value: buf.String(),
		}
	}
	return results
}
655722
func parseMetadata(md map[string]string) map[string]interface{} {
	m := make(map[string]interface{}, len(md))
	for key, value := range md {
		m[key] = value
	}
	return m
}
1188134
func parseMetadata(md swift.Headers) (map[string]interface{}, error) {
	m := make(map[string]interface{}, len(md))
	for key, value := range md.ObjectMetadata() {
		m[key] = value
	}
	return m, 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
}
1336764
func (c Config) Parse(s string) error {
	c.file = "<string>"
	c.input = s
	return c.parse()
}
368392
func AppendProperties(propertiesFile string, properties ...*Property) error {
	file, err := os.OpenFile(propertiesFile, os.O_RDWR|os.O_APPEND, NewFilePermissions)
	if err != nil {
		return err
	}
	for _, property := range properties {
		file.WriteString(fmt.Sprintf("\n%s\n", property.String()))
	}
	return file.Close()
}
639068
func parseMap(r reflect.Value, node *XMLNode, tag reflect.StructTag) error {
	if r.IsNil() {
		r.Set(reflect.MakeMap(r.Type()))
	}

	if tag.Get("flattened") == "" { // look at all child entries
		for _, entry := range node.Children["entry"] {
			parseMapEntry(r, entry, tag)
		}
	} else { // this element is itself an entry
		parseMapEntry(r, node, tag)
	}

	return nil
}
1313748
func ParseFile(path string) (map[string]map[string]string, error) {
	r, err := os.Open(path)
	if err != nil {
		return nil, errors.Wrapf(err, "ParseFile")
	}
	defer r.Close()
	return Parse(r)
}
1070260
func GetProperties(required bool) (*Properties, error) {
	filename := flag.String("props", "", "properties filename")
	flag.Parse()
	if *filename == "" {
		if required {
			return nil, NO_PROPS_FILE
		} else {
			return &Properties{make(map[string]string)}, nil
		}
	}
	return readPropertiesFile(*filename)
}
63482
func (m *GenericParser) getProperty(mapKey reflect.Value) (Property, error) {
	properteerType := reflect.TypeOf(new(Properteer)).Elem()
	stringerType := reflect.TypeOf(new(fmt.Stringer)).Elem()

	// if mapKey implements the pdk.Properteer interface, use that.
	if k2, ok := anyImplements(mapKey, properteerType); ok {
		return k2.Interface().(Properteer).Property(), nil
	}
	// if mapKey implements fmt.Stringer, use that.
	if k2, ok := anyImplements(mapKey, stringerType); ok {
		return Property(k2.Interface().(fmt.Stringer).String()), nil
	}

	// Otherwise, handle all comparable types (see https://golang.org/ref/spec#Comparison_operators):
	mapKey = deref(mapKey)
	switch k := mapKey.Kind(); k {
	case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
		return Property(fmt.Sprintf("%v", mapKey)), nil
	case reflect.Chan:
		m.Stats.Count("parser.getProperty.Chan", 1, 1)
		return "", errors.New("channel cannot be converted to property")
	case reflect.Array:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.New("array cannot be converted to property")
	case reflect.Struct:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.New("struct cannot be converted to property")
	case reflect.Complex128, reflect.Complex64:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.New("complex value cannot be converted to property")
	default:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.Errorf("unexpected kind: %v mapKey: %v", mapKey.Kind(), mapKey)
	}
}
7505
func (p *Parser) parse() (map[string]string, error) {
	p.scan() // init scannedItems

	labelsMap := map[string]string{}
	for {
		tok, lit := p.lookahead()
		switch tok {
		case IdentifierToken:
			key, value, err := p.parseLabel()
			if err != nil {
				return nil, fmt.Errorf("unable to parse requirement: %v", err)
			}
			labelsMap[key] = value
			t, l := p.consume()
			switch t {
			case EndOfStringToken:
				return labelsMap, nil
			case CommaToken:
				t2, l2 := p.lookahead()
				if t2 != IdentifierToken {
					return nil, fmt.Errorf("found '%s', expected: identifier after ','", l2)
				}
			default:
				return nil, fmt.Errorf("found '%s', expected: ',' or 'end of string'", l)
			}
		case EndOfStringToken:
			return labelsMap, nil
		default:
			return nil, fmt.Errorf("found '%s', expected: identifier or 'end of string'", lit)
		}
	}
}
933085
func Map(path string, sz int64) ([]byte, error) {
	fi, err := os.Stat(path)
	if err != nil {
		return nil, err
	}

	// Truncate file to size if too small.
	if fi.Size() < sz {
		if err := os.Truncate(path, sz); err != nil {
			return nil, err
		}
	} else {
		sz = fi.Size()
	}
	if sz == 0 {
		return nil, nil
	}

	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	lo, hi := uint32(sz), uint32(sz>>32)
	fmap, err := syscall.CreateFileMapping(syscall.Handle(f.Fd()), nil, syscall.PAGE_READONLY, hi, lo, nil)
	if err != nil {
		return nil, err
	}
	defer syscall.CloseHandle(fmap)

	ptr, err := syscall.MapViewOfFile(fmap, syscall.FILE_MAP_READ, 0, 0, uintptr(sz))
	if err != nil {
		return nil, err
	}
	data := (*[1 << 30]byte)(unsafe.Pointer(ptr))[:sz]

	return data, nil
}