// DecodeFormats takes a list of output format configurations and merges those,
// in the order given, with the Hugo defaults as the last resort.
13087
func DecodeFormats(mediaTypes media.Types, maps ...map[string]interface{}) (Formats, error) {
	f := make(Formats, len(DefaultFormats))
	copy(f, DefaultFormats)

	for _, m := range maps {
		for k, v := range m {
			found := false
			for i, vv := range f {
				if strings.EqualFold(k, vv.Name) {
					// Merge it with the existing
					if err := decode(mediaTypes, v, &f[i]); err != nil {
						return f, err
					}
					found = true
				}
			}
			if !found {
				var newOutFormat Format
				newOutFormat.Name = k
				if err := decode(mediaTypes, v, &newOutFormat); err != nil {
					return f, err
				}

				// We need values for these
				if newOutFormat.BaseName == "" {
					newOutFormat.BaseName = "index"
				}
				if newOutFormat.Rel == "" {
					newOutFormat.Rel = "alternate"
				}

				f = append(f, newOutFormat)
			}
		}
	}

	sort.Sort(f)

	return f, nil
}
361892
func (u *DefaultDecoder) Decode(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
360732
func (jsonEncoderDecoder) Decode(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
1169574
func Decode(input string) ([]byte, error) {
	if len(input) == 0 {
		return nil, ErrEmptyString
	}
	if !has0xPrefix(input) {
		return nil, ErrMissingPrefix
	}
	b, err := hex.DecodeString(input[2:])
	if err != nil {
		err = mapError(err)
	}
	return b, err
}
1062354
func ParseMatchers(regexes, inverseRegexes, globs, inverseGlobs []string) (m Matcher, err error) {
	var matchers multiMatcher
	if len(regexes) == 0 && len(globs) == 0 {
		matchers = multiMatcher{matchAll{}}
	}
	for _, r := range regexes {
		regex, err := regexp.Compile(r)
		if err != nil {
			return nil, err
		}
		matchers = append(matchers, newRegexMatcher(regex, false))
	}
	for _, r := range inverseRegexes {
		regex, err := regexp.Compile(r)
		if err != nil {
			return nil, err
		}
		matchers = append(matchers, newRegexMatcher(regex, true))
	}
	for _, g := range globs {
		matchers = append(matchers, &globMatcher{glob: g})
	}
	for _, g := range inverseGlobs {
		matchers = append(matchers, &globMatcher{
			glob:    g,
			inverse: true,
		})
	}
	return matchers, nil
}
240598
func DecodeInts(s string) ([]int, error) {
	xs, err := DecodeUints(s)
	if err != nil {
		return nil, err
	}
	ys := make([]int, len(xs))
	for i, u := range xs {
		if u&1 == 0 {
			ys[i] = int(u >> 1)
		} else {
			ys[i] = -int((u + 1) >> 1)
		}
	}
	return ys, nil
}
86198
func (d *Decoder) Decode(data []byte, v interface{}) error {
	f, ok := v.(unmarshalFaster)
	if ok {
		if d.fs == nil {
			d.fs = fflib.NewFFLexer(data)
		} else {
			d.fs.Reset(data)
		}
		return f.UnmarshalJSONFFLexer(d.fs, fflib.FFParse_map_start)
	}

	um, ok := v.(json.Unmarshaler)
	if ok {
		return um.UnmarshalJSON(data)
	}
	return json.Unmarshal(data, v)
}
1020208
func formatBytes(i int64) (result string) {
	var n float64
	sFmt, eFmt := "%.01f", ""
	switch {
	case i > EB:
		eFmt = "E"
		n = float64(i) / float64(EB)
	case i > PB:
		eFmt = "P"
		n = float64(i) / float64(PB)
	case i > TB:
		eFmt = "T"
		n = float64(i) / float64(TB)
	case i > GB:
		eFmt = "G"
		n = float64(i) / float64(GB)
	case i > MB:
		eFmt = "M"
		n = float64(i) / float64(MB)
	case i > KB:
		eFmt = "K"
		n = float64(i) / float64(KB)
	default:
		sFmt = "%.0f"
		n = float64(i)
	}
	if eFmt != "" && n >= 10 {
		sFmt = "%.0f"
	}
	result = fmt.Sprintf(sFmt+eFmt, n)
	result = strings.Trim(result, " ")
	return
}
1311313
func OutputFormat(s string) string {
	var buf bytes.Buffer
	for _, old := range s {
		if newVal, ok := replace[old]; ok {
			buf.WriteString(newVal)
			continue
		}
		buf.WriteRune(old)
	}

	return buf.String()
}
598792
func DecodeConfig(r io.Reader) (*Config, error) {
	var raw interface{}
	dec := json.NewDecoder(r)
	if err := dec.Decode(&raw); err != nil {
		return nil, err
	}

	// Decode
	var md mapstructure.Metadata
	var result Config
	msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
		Metadata:    &md,
		Result:      &result,
		ErrorUnused: true,
	})
	if err != nil {
		return nil, err
	}

	if err := msdec.Decode(raw); err != nil {
		return nil, err
	}

	// Decode the time values
	if result.ReconnectIntervalRaw != "" {
		dur, err := time.ParseDuration(result.ReconnectIntervalRaw)
		if err != nil {
			return nil, err
		}
		result.ReconnectInterval = dur
	}

	if result.ReconnectTimeoutRaw != "" {
		dur, err := time.ParseDuration(result.ReconnectTimeoutRaw)
		if err != nil {
			return nil, err
		}
		result.ReconnectTimeout = dur
	}

	if result.TombstoneTimeoutRaw != "" {
		dur, err := time.ParseDuration(result.TombstoneTimeoutRaw)
		if err != nil {
			return nil, err
		}
		result.TombstoneTimeout = dur
	}

	if result.RetryIntervalRaw != "" {
		dur, err := time.ParseDuration(result.RetryIntervalRaw)
		if err != nil {
			return nil, err
		}
		result.RetryInterval = dur
	}

	if result.BroadcastTimeoutRaw != "" {
		dur, err := time.ParseDuration(result.BroadcastTimeoutRaw)
		if err != nil {
			return nil, err
		}
		result.BroadcastTimeout = dur
	}

	return &result, nil
}
1225626
func (enc Encoding) Decode(dst, src []byte) (int, error) {
	data := ensurePadding(string(src))
	if enc.convert {
		data = convertEncoding(data)
	}
	return enc.encoding.Decode(dst, []byte(data))
}
501768
func DecodeChannels(data []byte) ([]string, error) {
	channels := []string{}
	pos := 0
	for pos < len(data) {
		if pos+2 > len(data) {
			return nil, fmt.Errorf("unable to decode size, pos=%v len=%v", pos, len(data))
		}
		cl := int(ByteOrder.Uint16(data[pos:]))
		pos += encodedChannelLen
		end := pos + cl
		if end > len(data) {
			return nil, fmt.Errorf("unable to decode channel, pos=%v len=%v max=%v (string=%v)",
				pos, cl, len(data), string(data[pos:]))
		}
		c := string(data[pos:end])
		channels = append(channels, c)
		pos = end
	}
	return channels, nil
}
1136187
func (r ContainerDecoder) DecodeConfig(src io.Reader) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) {
	return decodeContainerConfig(src)
}
1186744
func DecodeBytes(b []byte, val interface{}) error {
	r := bytes.NewReader(b)
	d := NewDecoder(r)
	return d.Decode(val)
}
896486
func DecodeUints(s string) ([]uint, error) {
	xs := make([]uint, 0)
	var x, shift uint
	for i, c := range []byte(s) {
		switch {
		case 63 <= c && c < 95:
			xs = append(xs, x+(uint(c)-63)<<shift)
			x = 0
			shift = 0
		case 95 <= c && c < 127:
			x += (uint(c) - 95) << shift
			shift += 5
		default:
			return nil, &InvalidCharacterError{i, c}
		}
	}
	if shift != 0 {
		return nil, &UnterminatedError{}
	}
	return xs, nil
}
696829
func Decode(code *string) error {
	// Don't decode empty strings
	if *code == "" {
		return nil
	}
	unhexedBytes, err := hex.DecodeString(*code)
	if err != nil {
		return err
	}
	buf := bytes.NewBuffer(unhexedBytes)
	decompressorReader := flate.NewReader(buf)
	decompressedBytes, err := ioutil.ReadAll(decompressorReader)
	decompressorReader.Close()
	if err != nil {
		return err
	}
	*code = string(decompressedBytes)
	return nil
}
1275049
func splitFormatOnSemicolon(format string) ([]string, error) {
	var formats []string
	prevIndex := 0
	for i := 0; i < len(format); i++ {
		if format[i] == ';' {
			formats = append(formats, format[prevIndex:i])
			prevIndex = i + 1
		} else if format[i] == '\\' {
			i++
		} else if format[i] == '"' {
			endQuoteIndex := strings.Index(format[i+1:], "\"")
			if endQuoteIndex == -1 {
				// This is an invalid format string, fall back to general
				return nil, errors.New("invalid format string, unmatched double quote")
			}
			i += endQuoteIndex + 1
		}
	}
	return append(formats, format[prevIndex:]), nil
}