// Dehumanize converts a human-readable byte slice into a uint64.
332535
func dehumanize(hbytes []byte) (uint64, error) {
	ll := len(hbytes)
	if ll == 0 {
		return 0, fmt.Errorf("zero-length reply")
	}
	lastByte := hbytes[ll-1]
	mul := float64(1)
	var (
		mant float64
		err  error
	)
	// If lastByte is beyond the range of ASCII digits, it must be a
	// multiplier.
	if lastByte > 57 {
		// Remove multiplier from slice.
		hbytes = hbytes[:len(hbytes)-1]

		const (
			_ = 1 << (10 * iota)
			KiB
			MiB
			GiB
			TiB
			PiB
			EiB
			ZiB
			YiB
		)

		multipliers := map[rune]float64{
			// Source for conversion rules:
			// linux-kernel/drivers/md/bcache/util.c:bch_hprint()
			'k': KiB,
			'M': MiB,
			'G': GiB,
			'T': TiB,
			'P': PiB,
			'E': EiB,
			'Z': ZiB,
			'Y': YiB,
		}
		mul = multipliers[rune(lastByte)]
		mant, err = parsePseudoFloat(string(hbytes))
		if err != nil {
			return 0, err
		}
	} else {
		// Not humanized by bch_hprint
		mant, err = strconv.ParseFloat(string(hbytes), 64)
		if err != nil {
			return 0, err
		}
	}
	res := uint64(mant * mul)
	return res, nil
}
942127
func (r *PortRuleDNS) Sanitize() error {
	if len(r.MatchName) > 0 && !allowedMatchNameChars.MatchString(r.MatchName) {
		return fmt.Errorf("Invalid characters in MatchName: \"%s\". Only 0-9, a-z, A-Z and . and - characters are allowed", r.MatchName)
	}

	if len(r.MatchPattern) > 0 && !allowedPatternChars.MatchString(r.MatchPattern) {
		return fmt.Errorf("Invalid characters in MatchPattern: \"%s\". Only 0-9, a-z, A-Z and ., - and * characters are allowed", r.MatchPattern)
	}
	_, err := matchpattern.Validate(r.MatchPattern)
	return err
}
534818
func decodeVarint(b []byte) (uint64, int) {
	var x, y uint64
	if len(b) == 0 {
		goto bad
	}
	x = uint64(b[0])
	if x < 0x80 {
		return x, 1
	}
	x -= 0x80

	if len(b) <= 1 {
		goto bad
	}
	y = uint64(b[1])
	x += y << 7
	if y < 0x80 {
		return x, 2
	}
	x -= 0x80 << 7

	if len(b) <= 2 {
		goto bad
	}
	y = uint64(b[2])
	x += y << 14
	if y < 0x80 {
		return x, 3
	}
	x -= 0x80 << 14

	if len(b) <= 3 {
		goto bad
	}
	y = uint64(b[3])
	x += y << 21
	if y < 0x80 {
		return x, 4
	}
	x -= 0x80 << 21

	if len(b) <= 4 {
		goto bad
	}
	y = uint64(b[4])
	x += y << 28
	if y < 0x80 {
		return x, 5
	}
	x -= 0x80 << 28

	if len(b) <= 5 {
		goto bad
	}
	y = uint64(b[5])
	x += y << 35
	if y < 0x80 {
		return x, 6
	}
	x -= 0x80 << 35

	if len(b) <= 6 {
		goto bad
	}
	y = uint64(b[6])
	x += y << 42
	if y < 0x80 {
		return x, 7
	}
	x -= 0x80 << 42

	if len(b) <= 7 {
		goto bad
	}
	y = uint64(b[7])
	x += y << 49
	if y < 0x80 {
		return x, 8
	}
	x -= 0x80 << 49

	if len(b) <= 8 {
		goto bad
	}
	y = uint64(b[8])
	x += y << 56
	if y < 0x80 {
		return x, 9
	}
	x -= 0x80 << 56

	if len(b) <= 9 {
		goto bad
	}
	y = uint64(b[9])
	x += y << 63
	if y < 2 {
		return x, 10
	}

bad:
	return 0, 0
}
534447
func (id *HashID) Normalize() error {
	// encoding/hex encodes using lower-case hexadecimal. Note that this is a
	// no-op if the ID is already lowercase.
	idv := strings.ToLower(string(*id))

	if decodeSize := hex.DecodedLen(len(idv)); decodeSize != sha256.Size {
		return fmt.Errorf("invalid SHA256 hash size (%d != %d)", decodeSize, sha256.Size)
	}
	for i, r := range idv {
		if !strings.ContainsRune(validHashIDChars, r) {
			return fmt.Errorf("invalid character '%c' at %d", r, i)
		}
	}
	*id = HashID(idv)
	return nil
}
28185
func (p *NodbProvider) Destory(sid string) error {
	_, err := p.c.Del([]byte(sid))
	return err
}
434863
func Deinterleave(b uint64) uint64 {
	b &= interleaveMagic[0]
	b = (b ^ (b >> interleaveShift[0])) & interleaveMagic[1]
	b = (b ^ (b >> interleaveShift[1])) & interleaveMagic[2]
	b = (b ^ (b >> interleaveShift[2])) & interleaveMagic[3]
	b = (b ^ (b >> interleaveShift[3])) & interleaveMagic[4]
	b = (b ^ (b >> interleaveShift[4])) & interleaveMagic[5]
	return b
}
8368
func (t *File_Template) Normalize() error {
	if t.Body == "" {
		return errors.New("body is empty")
	}

	defaultParams := make(map[string]*Value, len(t.Param))
	for k, param := range t.Param {
		if k == "" {
			return fmt.Errorf("param %q: invalid name", k)
		}
		if !ParamRegex.MatchString(k) {
			return fmt.Errorf("param %q: malformed name", k)
		}
		if !strings.Contains(t.Body, k) {
			return fmt.Errorf("param %q: not present in body", k)
		}
		if err := param.Normalize(); err != nil {
			return fmt.Errorf("param %q: %s", k, err)
		}
		if param.Default != nil {
			defaultParams[k] = param.Default
		} else {
			defaultParams[k] = param.Schema.Zero()
		}
	}

	maybeJSON, err := t.Render(defaultParams)
	if err != nil {
		return fmt.Errorf("rendering: %s", err)
	}

	err = json.Unmarshal([]byte(maybeJSON), &map[string]interface{}{})
	if err != nil {
		return fmt.Errorf("parsing rendered body: %s", err)
	}
	return nil
}
1012251
func (ctx *Context) Sanitize(s string) string {
	return ctx.App.sanitizerPolicy.Sanitize(s)
}
737886
func (a *AnonUUID) Sanitize(input string) string {
	r := regexp.MustCompile(UUIDRegex)

	return r.ReplaceAllStringFunc(input, func(m string) string {
		parts := r.FindStringSubmatch(m)
		return a.FakeUUID(parts[0])
	})
}
1260704
func (quat *T) Normalize() *T {
	norm := quat.Norm()
	if norm != 1 && norm != 0 {
		ool := 1 / math.Sqrt(norm)
		quat[0] *= ool
		quat[1] *= ool
		quat[2] *= ool
		quat[3] *= ool
	}
	return quat
}
773846
func (m mathUtil) Normalize(values ...float64) []float64 {
	var total float64
	for _, v := range values {
		total += v
	}
	output := make([]float64, len(values))
	for x, v := range values {
		output[x] = m.RoundDown(v/total, 0.0001)
	}
	return output
}
865612
func (ident Identifier) Sanitize() string {
	parts := make([]string, len(ident))
	for i := range ident {
		parts[i] = `"` + strings.Replace(ident[i], `"`, `""`, -1) + `"`
	}
	return strings.Join(parts, ".")
}
1130119
func (n *SimpleNameNormalizer) Normalize(name string) string {
	var retMe []byte
	nameBytes := []byte(name)
	for i, b := range nameBytes {
		if n.safeByte(b) {
			if retMe != nil {
				retMe[i] = b
			}
		} else {
			if retMe == nil {
				retMe = make([]byte, len(nameBytes))
				copy(retMe[0:i], nameBytes[0:i])
			}
			retMe[i] = n.Replacement
		}
	}
	if retMe == nil {
		return name
	}
	return string(retMe)
}
1278480
func humanDuration(d time.Duration) string {
	if d == 0 {
		return "0s"
	}

	s := d.String()
	if strings.HasSuffix(s, "m0s") {
		s = s[:len(s)-2]
	}
	if idx := strings.Index(s, "h0m"); idx > 0 {
		s = s[:idx+1] + s[idx+3:]
	}
	return s
}
108830
func (s *FQDNSelector) sanitize() error {
	if len(s.MatchName) > 0 && !allowedMatchNameChars.MatchString(s.MatchName) {
		return fmt.Errorf("Invalid characters in MatchName: \"%s\". Only 0-9, a-z, A-Z and . and - characters are allowed", s.MatchName)
	}

	if len(s.MatchPattern) > 0 && !allowedPatternChars.MatchString(s.MatchPattern) {
		return fmt.Errorf("Invalid characters in MatchPattern: \"%s\". Only 0-9, a-z, A-Z and ., - and * characters are allowed", s.MatchPattern)
	}
	_, err := matchpattern.Validate(s.MatchPattern)
	return err
}
980960
func Deserialize(p []byte) (*structs.DiskStats, error) {
	st := &structs.DiskStats{}
	err := json.Unmarshal(p, st)
	if err != nil {
		return nil, err
	}
	return st, nil
}
104680
func ParseHumanName(n string) (*HumanName, error) {
	h := &HumanName{}
	parts := strings.Split(n, " ")
	if len(parts) == 2 {
		h.FirstName = parts[0]
		h.LastName = parts[1]
	} else if len(parts) == 3 {
		h.FirstName = parts[0]
		h.MiddleName = parts[1]
		h.LastName = parts[2]
	}
	return h, nil
}