// Pads the value with units to a given width.
// padUnits(14, 0.22, 2, "µs") = "0.22µs        "
12791
func padUnits(width int, value float64, precision int, units string) string {
	format1 := fmt.Sprintf("%%-%ds", width)
	format2 := fmt.Sprintf("%%.%df%%s", precision)
	return fmt.Sprintf(format1, fmt.Sprintf(format2, value, units))
}
1061113
func UnitsToPointsVar(t int, u ...*float64) {
	for x := 0; x < len(u); x++ {
		*u[x] = UnitsToPoints(t, *u[x])
	}
}
290026
func (enc *encoder) padding(offset, algn int) int {
	abs := enc.pos + offset
	if abs%algn != 0 {
		newabs := (abs + algn - 1) & ^(algn - 1)
		return newabs - abs
	}
	return 0
}
573097
func Resize(s string, length uint, rightAlign bool) string {
	slen := runewidth.StringWidth(s)
	n := int(length)
	if slen == n {
		return s
	}
	// Pads only when length of the string smaller than len needed
	if rightAlign {
		s = PadLeft(s, n, ' ')
	} else {
		s = PadRight(s, n, ' ')
	}
	if slen > n {
		rs := []rune(s)
		var buf bytes.Buffer
		w := 0
		for _, r := range rs {
			buf.WriteRune(r)
			rw := runewidth.RuneWidth(r)
			if w+rw >= n-3 {
				break
			}
			w += rw
		}
		buf.WriteString("...")
		s = buf.String()
	}
	return s
}
580379
func ZeroPadF(x []float64, length int) []float64 {
	if len(x) >= length {
		return x
	}

	r := make([]float64, length)
	copy(r, x)
	return r
}
909676
func BoundedDigits(digits, low, high int) string {
	if low > high {
		low, high = high, low
	}

	max := int(math.Pow10(digits)) - 1
	if high > max {
		high = max
	}

	num := privateRand.Intn(high-low+1) + low
	format := fmt.Sprintf("%%0%dd", digits)
	return fmt.Sprintf(format, num)
}
1255338
func SizeToString(s int64) string {
	v := float64(s)
	i := 0
	for ; i < len(units); i++ {
		if v < 1024. {
			break
		}
		v /= 1024.
	}
	if i == 0 {
		return fmt.Sprintf("%d%s", s, units[i])
	}
	if v >= 10 {
		return fmt.Sprintf("%.1f%s", v, units[i])
	}
	return fmt.Sprintf("%.2f%s", v, units[i])
}
16348
func (tu Unit) String() string {
	if s, found := unitStrings[tu]; found {
		return s
	}

	return "unknown"
}
291292
func makePad(l int) []byte {
	ret := make([]byte, l)
	for i := 0; i < l; i++ {
		ret[i] = ' '
	}
	return ret
}
40273
func UnitsToPoints(t int, u float64) float64 {
	switch t {
	case Unit_PT:
		return u * conversion_Unit_PT
	case Unit_MM:
		return u * conversion_Unit_MM
	case Unit_CM:
		return u * conversion_Unit_CM
	case Unit_IN:
		return u * conversion_Unit_IN
	default:
		return u
	}
}
53656
func ConvertUnits(val float64, from Unit, to Unit) float64 {
	value := Unit(val)
	// convert to I unit by multiplying with the current unit
	value *= from
	// convert to the target unit by dividing by it
	if to == I {
		return math.Round(float64(value))
	}
	value /= to
	return float64(value)
}
1193151
func Format(i int64, units Units, width int) string {
	switch units {
	case U_BYTES:
		return FormatBytes(i)
	default:
		// by default just convert to string
		return fmt.Sprintf(fmt.Sprintf("%%%dd", width), i)
	}
}
960235
func (d *state) padAndPermute(dsbyte byte) {
	if d.buf == nil {
		d.buf = d.storage[:0]
	}
	// Pad with this instance's domain-separator bits. We know that there's
	// at least one byte of space in d.buf because, if it were full,
	// permute would have been called to empty it. dsbyte also contains the
	// first one bit for the padding. See the comment in the state struct.
	d.buf = append(d.buf, dsbyte)
	zerosStart := len(d.buf)
	d.buf = d.storage[:d.rate]
	for i := zerosStart; i < d.rate; i++ {
		d.buf[i] = 0
	}
	// This adds the final one bit for the padding. Because of the way that
	// bits are numbered from the LSB upwards, the final bit is the MSB of
	// the last byte.
	d.buf[d.rate-1] ^= 0x80
	// Apply the permutation
	d.permute()
	d.state = spongeSqueezing
	d.buf = d.storage[:d.rate]
	copyOut(d, d.buf)
}
1012489
func FormatBytes(s uint64) string {
	var e float64
	if s == 0 {
		e = 0
	} else {
		e = math.Floor(log(float64(s), 1000))
	}

	unit := uint64(math.Pow(1000, e))
	suffix := sizes[int(e)]

	return fmt.Sprintf("%s %s",
		FormatBytesUnit(s, unit), suffix)
}
1151495
func Size(s int64) string {

	symbols := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
	i := index(s)
	if s < 10 {
		return fmt.Sprintf("%dB", s)
	}
	size := countSize(s, i)
	format := "%.0f"
	if size < 10 {
		format = "%.1f"
	}

	return fmt.Sprintf(format+"%s", size, symbols[int(i)])
}
28839
func padWithSpace(source string, prefix, suffix int) string {
	if source == "" {
		return source
	}
	return strings.Repeat(" ", prefix) + source + strings.Repeat(" ", suffix)
}
451948
func twoDigits(buf *bytes.Buffer, value int) {
	buf.WriteByte(digits[value/10])
	buf.WriteByte(digits[value%10])
}