File: itoa.go

package info (click to toggle)
golang-gopkg-errgo.v2 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 112 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 583 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package errors

// itoa converts val to a decimal string. It allows this package to
// avoid a dependency on strconv. Adapted from net/parse.go
func appendInt(buf []byte, val int) []byte {
	if val < 0 {
		buf = append(buf, '-')
		return appendUint(buf, uint(-val))
	}
	return appendUint(buf, uint(val))
}

func appendUint(p []byte, val uint) []byte {
	var buf [20]byte // big enough for 64bit value base 10
	i := len(buf) - 1
	for val >= 10 {
		q := val / 10
		buf[i] = byte('0' + val - q*10)
		i--
		val = q
	}
	// val < 10
	buf[i] = byte('0' + val)
	return append(p, buf[i:]...)
}