// MapKeySeparator defines the separator used to split strings when
// decoding or encoding a map key.
328578
func MapKeySeparator(sep rune) Option {
	return func(ini *INI) error {
		ini.mapkeySep = sep
		return nil
	}
}
707960
func stringKeysFromMap(m interface{}) (keys []string) {
	for _, k := range reflect.ValueOf(m).MapKeys() {
		keys = append(keys, k.String())
	}
	return
}
387392
func SortedKeys(m interface{}) []string {
	list := Keys(m)
	sort.Strings(list)

	return list
}
1028693
func FormatKey(parts []string) string {
	if len(parts) < 1 {
		panic("Not allowed 0-length parts slice")
	}

	key := parts[0]
	for i := 1; i < len(parts); i++ {
		key += "[" + parts[i] + "]"
	}
	return key
}
104813
func ToLower(m map[string]interface{}) {
	for k, v := range m {
		switch v.(type) {
		case map[interface{}]interface{}:
			v = cast.ToStringMap(v)
			ToLower(v.(map[string]interface{}))
		case map[string]interface{}:
			ToLower(v.(map[string]interface{}))
		}

		lKey := strings.ToLower(k)
		if k != lKey {
			delete(m, k)
			m[lKey] = v
		}

	}
}
89770
func (c Context) Split(s string, sep string) []string {
	return strings.Split(s, sep)
}
127720
func parseKeyValue(body []byte) (map[string]string, error) {
	p := make(map[string]string)
	for _, b := range bytes.Split(body, []byte("\n")) {
		if len(b) == 0 {
			continue
		}
		parts := bytes.SplitN(b, []byte(":"), 2)
		if len(parts) != 2 {
			return nil, fmt.Errorf("invalid key-value line %q", b)
		}
		p[string(parts[0])] = string(parts[1])
	}
	return p, nil
}
916335
func ParseKeyRangeParts(start, end string) (*topodatapb.KeyRange, error) {
	s, err := hex.DecodeString(start)
	if err != nil {
		return nil, err
	}
	e, err := hex.DecodeString(end)
	if err != nil {
		return nil, err
	}
	return &topodatapb.KeyRange{Start: s, End: e}, nil
}
1167099
func KeysOfMap(m map[string]string) []string {
	keys := make(sort.StringSlice, len(m))
	i := 0
	for key, _ := range m {
		keys[i] = key
		i++
	}

	keys.Sort()
	return []string(keys)
}
479802
func (v Value) StringMap() map[string]string {
	tmp := v.StringSlice()
	m := make(map[string]string, len(tmp))
	for _, s := range tmp {
		kv := strings.Split(s, ":")
		if len(kv) > 1 {
			m[strings.TrimSpace(kv[0])] = strings.TrimSpace(kv[1])
		}
	}
	return m
}
450863
func splitPathOnSeparator(path string, separator rune) []string {
	// if the separator is '\\', then we can just split...
	if separator == '\\' {
		return strings.Split(path, string(separator))
	}

	// otherwise, we need to be careful of situations where the separator was escaped
	cnt := strings.Count(path, string(separator))
	if cnt == 0 {
		return []string{path}
	}
	ret := make([]string, cnt+1)
	pathlen := len(path)
	separatorLen := utf8.RuneLen(separator)
	idx := 0
	for start := 0; start < pathlen; {
		end := indexRuneWithEscaping(path[start:], separator)
		if end == -1 {
			end = pathlen
		} else {
			end += start
		}
		ret[idx] = path[start:end]
		start = end + separatorLen
		idx++
	}
	return ret[:idx]
}
1294565
func parseKeyVal(pair string) (string, string) {
	split := strings.Split(pair, ":")
	return split[0], split[1]
}
1035567
func sortParameters(params map[string]string, format string) []string {
	// sort by key
	keys := make([]string, len(params))
	i := 0
	for key := range params {
		keys[i] = key
		i++
	}
	sort.Strings(keys)
	// parameter join
	pairs := make([]string, len(params))
	for i, key := range keys {
		pairs[i] = fmt.Sprintf(format, key, params[key])
	}
	return pairs
}
258316
func ParseKey(data map[string]interface{}, key string, t string) error {
	val, ok := data[key]
	if !ok {
		return errors.New("lack of key")
	}

	switch t {
	case "string":
		_, ok = val.(string)
	case "int":
		_, ok = val.(int)
	case "map":
		_, ok = val.(map[string]interface{})
	case "list":
		_, ok = val.([]interface{})
	default:
		panic("invalid type")
	}

	if !ok {
		return errors.New("invalid key type")
	}

	return nil
}
1129291
func mapToString(extensions map[string]string, keyValSep string, elemSep string) string {
	buf := make([]string, 0, len(extensions))

	for k, v := range extensions {
		buf = append(buf, k+keyValSep+v)
	}

	sort.Strings(buf)

	return strings.Join(buf, elemSep)
}
1183864
func normalizePathSeparator(p string) string {
	if filepath.Separator == '/' {
		return strings.Replace(p, `\`, string(filepath.Separator), -1)
	}
	return strings.Replace(p, "/", string(filepath.Separator), -1)
}
131223
func (p *SortKeys) AsStringSliceComparator() StringSliceComparator {
	numeric := utils.NewIndex(p.Numeric)
	reverseIndex := utils.NewIndex(p.Reversed)
	comparators := make([]StringComparator, len(p.Keys))
	for i, k := range p.Keys {
		if numeric.Contains(k) {
			comparators[i] = LessNumericStrings
		} else {
			comparators[i] = LessStrings
		}
		if reverseIndex.Contains(k) {
			f := comparators[i]
			comparators[i] = func(l, r string) bool {
				return !f(l, r)
			}
		}
	}
	return AsStringSliceComparator(comparators)
}