2012-03-27 23:13:14 +00:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-10-07 00:16:47 +00:00
|
|
|
// Simple conversions to avoid depending on strconv.
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
package os
|
|
|
|
|
2017-04-10 11:32:00 +00:00
|
|
|
// Convert integer to decimal string
|
|
|
|
func itoa(val int) string {
|
2012-03-27 23:13:14 +00:00
|
|
|
if val < 0 {
|
2017-04-10 11:32:00 +00:00
|
|
|
return "-" + uitoa(uint(-val))
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
2017-04-10 11:32:00 +00:00
|
|
|
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
|
2012-03-27 23:13:14 +00:00
|
|
|
i := len(buf) - 1
|
|
|
|
for val >= 10 {
|
2017-04-10 11:32:00 +00:00
|
|
|
q := val / 10
|
|
|
|
buf[i] = byte('0' + val - q*10)
|
2012-03-27 23:13:14 +00:00
|
|
|
i--
|
2017-04-10 11:32:00 +00:00
|
|
|
val = q
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
2017-04-10 11:32:00 +00:00
|
|
|
// val < 10
|
|
|
|
buf[i] = byte('0' + val)
|
2012-03-27 23:13:14 +00:00
|
|
|
return string(buf[i:])
|
|
|
|
}
|