1
0
mirror of https://github.com/golang/go synced 2024-11-26 21:01:31 -07:00

a couple of bugs in print.

1) bool wasn't handled (added '%t' for 'truth').
2) float64 had a typo.

TBR=rsc
DELTA=11  (10 added, 0 deleted, 1 changed)
OCL=18314
CL=18318
This commit is contained in:
Rob Pike 2008-11-01 16:37:53 -07:00
parent 74427c6346
commit 59f029cbf2

View File

@ -197,7 +197,7 @@ func getFloat(v reflect.Value) (val float64, ok bool) {
case reflect.Float32Kind: case reflect.Float32Kind:
return float64(v.(reflect.Float32Value).Get()), true; return float64(v.(reflect.Float32Value).Get()), true;
case reflect.Float64Kind: case reflect.Float64Kind:
return float64(v.(reflect.Float32Value).Get()), true; return float64(v.(reflect.Float64Value).Get()), true;
case reflect.Float80Kind: case reflect.Float80Kind:
break; // TODO: what to do here? break; // TODO: what to do here?
} }
@ -273,6 +273,14 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
fieldnum++; fieldnum++;
s := ""; s := "";
switch c { switch c {
// bool
case 't':
if field.(reflect.BoolValue).Get() {
s = "true";
} else {
s = "false";
}
// int // int
case 'b': case 'b':
if v, signed, ok := getInt(field); ok { if v, signed, ok := getInt(field); ok {
@ -369,6 +377,8 @@ func (p *P) doprint(v reflect.StructValue, is_println bool) {
p.add(' ') p.add(' ')
} }
switch field.Kind() { switch field.Kind() {
case reflect.BoolKind:
s = p.fmt.boolean(field.(reflect.BoolValue).Get()).str();
case reflect.IntKind, reflect.Int8Kind, reflect.Int16Kind, reflect.Int32Kind, reflect.Int64Kind: case reflect.IntKind, reflect.Int8Kind, reflect.Int16Kind, reflect.Int32Kind, reflect.Int64Kind:
v, signed, ok := getInt(field); v, signed, ok := getInt(field);
s = p.fmt.d64(v).str(); s = p.fmt.d64(v).str();