Modify printInt and printUint to accept base.

This paves the way to improve how byte arrays are output as well as
increases the flexibily of the functions.
This commit is contained in:
Dave Collins 2013-03-08 19:54:27 -06:00
parent f92eb047c3
commit 471552e81e
3 changed files with 8 additions and 8 deletions

View File

@ -186,13 +186,13 @@ func printBool(w io.Writer, val bool) {
} }
// printInt outputs a signed integer value to Writer w. // printInt outputs a signed integer value to Writer w.
func printInt(w io.Writer, val int64) { func printInt(w io.Writer, val int64, base int) {
w.Write([]byte(strconv.FormatInt(val, 10))) w.Write([]byte(strconv.FormatInt(val, base)))
} }
// printUint outputs an unsigned integer value to Writer w. // printUint outputs an unsigned integer value to Writer w.
func printUint(w io.Writer, val uint64) { func printUint(w io.Writer, val uint64, base int) {
w.Write([]byte(strconv.FormatUint(val, 10))) w.Write([]byte(strconv.FormatUint(val, base)))
} }
// printFloat outputs a floating point value using the specified precision, // printFloat outputs a floating point value using the specified precision,

View File

@ -182,10 +182,10 @@ func (d *dumpState) dump(v reflect.Value) {
printBool(d.w, v.Bool()) printBool(d.w, v.Bool())
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
printInt(d.w, v.Int()) printInt(d.w, v.Int(), 10)
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
printUint(d.w, v.Uint()) printUint(d.w, v.Uint(), 10)
case reflect.Float32: case reflect.Float32:
printFloat(d.w, v.Float(), 32) printFloat(d.w, v.Float(), 32)

View File

@ -237,10 +237,10 @@ func (f *formatState) format(v reflect.Value) {
printBool(f.fs, v.Bool()) printBool(f.fs, v.Bool())
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
printInt(f.fs, v.Int()) printInt(f.fs, v.Int(), 10)
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
printUint(f.fs, v.Uint()) printUint(f.fs, v.Uint(), 10)
case reflect.Float32: case reflect.Float32:
printFloat(f.fs, v.Float(), 32) printFloat(f.fs, v.Float(), 32)