mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: add internal/itoa package
This replaces five implementations scattered across low level packages. (And I plan to use it in a sixth soon.) Three of the five were byte-for-byte identical. Change-Id: I3bbbeeac63723a487986c912b604e10ad1e042f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/301549 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
This commit is contained in:
parent
88b8a16089
commit
061a6903a2
32 changed files with 143 additions and 181 deletions
|
|
@ -172,32 +172,6 @@ func xtoi2(s string, e byte) (byte, bool) {
|
|||
return byte(n), ok && ei == 2
|
||||
}
|
||||
|
||||
// Convert integer to decimal string.
|
||||
func itoa(val int) string {
|
||||
if val < 0 {
|
||||
return "-" + uitoa(uint(-val))
|
||||
}
|
||||
return uitoa(uint(val))
|
||||
}
|
||||
|
||||
// Convert unsigned integer to decimal string.
|
||||
func uitoa(val uint) string {
|
||||
if val == 0 { // avoid string allocation
|
||||
return "0"
|
||||
}
|
||||
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 string(buf[i:])
|
||||
}
|
||||
|
||||
// Convert i to a hexadecimal string. Leading zeros are not printed.
|
||||
func appendHex(dst []byte, i uint32) []byte {
|
||||
if i == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue