diff options
author | Russ Cox <rsc@golang.org> | 2009-07-02 16:57:46 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-07-02 16:57:46 -0700 |
commit | 2cb602f86c39b8f6fde6fe4faa90e322f8a34d61 (patch) | |
tree | fcea7b74071a96ee4d439595bb78cbc7fb949e96 /src/pkg/strconv/itoa.go | |
parent | 0949bb97dcea90657e1d42fbb19a875b5b98eebd (diff) | |
download | golang-2cb602f86c39b8f6fde6fe4faa90e322f8a34d61.tar.gz |
add Uitoa etc.
R=r
DELTA=113 (89 added, 9 deleted, 15 changed)
OCL=31087
CL=31096
Diffstat (limited to 'src/pkg/strconv/itoa.go')
-rw-r--r-- | src/pkg/strconv/itoa.go | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/pkg/strconv/itoa.go b/src/pkg/strconv/itoa.go index 7f693ea8c..c6985f438 100644 --- a/src/pkg/strconv/itoa.go +++ b/src/pkg/strconv/itoa.go @@ -4,17 +4,12 @@ package strconv -// Itob64 returns the string representation of i in the given base. -func Itob64(i int64, base uint) string { - if i == 0 { +// Uitob64 returns the string representation of i in the given base. +func Uitob64(u uint64, base uint) string { + if u == 0 { return "0" } - u := uint64(i); - if i < 0 { - u = -u; - } - // Assemble decimal in reverse order. var buf [32]byte; j := len(buf); @@ -25,12 +20,19 @@ func Itob64(i int64, base uint) string { u /= b; } - if i < 0 { // add sign - j--; - buf[j] = '-' + return string(buf[j:len(buf)]) +} + +// Itob64 returns the string representation of i in the given base. +func Itob64(i int64, base uint) string { + if i == 0 { + return "0" } - return string(buf[j:len(buf)]) + if i < 0 { + return "-" + Uitob64(-uint64(i), base); + } + return Uitob64(uint64(i), base); } // Itoa64 returns the decimal string representation of i. @@ -38,6 +40,16 @@ func Itoa64(i int64) string { return Itob64(i, 10); } +// Uitoa64 returns the decimal string representation of i. +func Uitoa64(i uint64) string { + return Uitob64(i, 10); +} + +// Uitob returns the string representation of i in the given base. +func Uitob(i uint, base uint) string { + return Uitob64(uint64(i), base); +} + // Itob returns the string representation of i in the given base. func Itob(i int, base uint) string { return Itob64(int64(i), base); @@ -47,3 +59,8 @@ func Itob(i int, base uint) string { func Itoa(i int) string { return Itob64(int64(i), 10); } + +// Uitoa returns the decimal string representation of i. +func Uitoa(i uint) string { + return Uitob64(uint64(i), 10); +} |