Commit 497bb9c0 authored by Rob Pike's avatar Rob Pike

casify fmt and its dependents.

R=rsc
DELTA=224  (0 added, 2 deleted, 222 changed)
OCL=22875
CL=22875
parent 8559e3ad
......@@ -12,24 +12,22 @@ import (
Raw formatter. See print.go for a more palatable interface.
f := fmt.New();
print f.d(1234).s("\n").str(); // create string, print it
f.d(-1234).s("\n").put(); // print string
f.ud(1<<63).putnl(); // print string with automatic newline
print f.Fmt_d(1234).Fmt_s("\n").Str(); // create string, print it
f.Fmt_d(-1234).Fmt_s("\n").put(); // print string
f.Fmt_ud(1<<63).Putnl(); // print string with automatic newline
*/
// export Fmt, New;
const NByte = 64;
const NPows10 = 160;
const nByte = 64;
const nPows10 = 160;
var ldigits string = "0123456789abcdef" // var not const because we take its address
var udigits string = "0123456789ABCDEF"
var pows10 [NPows10] float64;
var pows10 [nPows10] float64;
func init() {
pows10[0] = 1.0e0;
pows10[1] = 1.0e1;
for i:=2; i<NPows10; i++ {
for i:=2; i<nPows10; i++ {
m := i/2;
pows10[i] = pows10[m] * pows10[i-m];
}
......@@ -76,7 +74,7 @@ export func New() *Fmt {
return f;
}
func (f *Fmt) str() string {
func (f *Fmt) Str() string {
s := f.buf;
f.clearbuf();
f.clearflags();
......@@ -84,19 +82,19 @@ func (f *Fmt) str() string {
return s;
}
func (f *Fmt) put() {
func (f *Fmt) Put() {
print(f.buf);
f.clearbuf();
f.clearflags();
}
func (f *Fmt) putnl() {
func (f *Fmt) Putnl() {
print(f.buf, "\n");
f.clearbuf();
f.clearflags();
}
func (f *Fmt) wp(w, p int) *Fmt {
func (f *Fmt) Wp(w, p int) *Fmt {
f.wid_present = true;
f.wid = w;
f.prec_present = true;
......@@ -104,13 +102,13 @@ func (f *Fmt) wp(w, p int) *Fmt {
return f;
}
func (f *Fmt) p(p int) *Fmt {
func (f *Fmt) P(p int) *Fmt {
f.prec_present = true;
f.prec = p;
return f;
}
func (f *Fmt) w(x int) *Fmt {
func (f *Fmt) W(x int) *Fmt {
f.wid_present = true;
f.wid = x;
return f;
......@@ -132,8 +130,8 @@ func (f *Fmt) pad(s string) {
padchar = '0';
}
if w > 0 {
if w > NByte {
w = NByte;
if w > nByte {
w = nByte;
}
buf := make([]byte, w);
for i := 0; i < w; i++ {
......@@ -154,7 +152,7 @@ func (f *Fmt) pad(s string) {
// never mind.) val is known to be unsigned. we could make things maybe
// marginally faster by splitting the 32-bit case out into a separate function
// but it's not worth the duplication, so val has 64 bits.
func putint(buf *[NByte]byte, i int, base, val uint64, digits *string) int {
func putint(buf *[nByte]byte, i int, base, val uint64, digits *string) int {
for val >= base {
buf[i] = digits[val%base];
i--;
......@@ -165,7 +163,7 @@ func putint(buf *[NByte]byte, i int, base, val uint64, digits *string) int {
}
// boolean
func (f *Fmt) boolean(a bool) *Fmt {
func (f *Fmt) Fmt_boolean(a bool) *Fmt {
if a {
f.pad("true");
} else {
......@@ -177,7 +175,7 @@ func (f *Fmt) boolean(a bool) *Fmt {
// integer; interprets prec but not wid.
func (f *Fmt) integer(a int64, base uint, is_signed bool, digits *string) string {
var buf [NByte]byte;
var buf [nByte]byte;
negative := is_signed && a < 0;
if negative {
a = -a;
......@@ -196,8 +194,8 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits *string) string
}
}
i := putint(&buf, NByte-1, uint64(base), uint64(a), digits);
for i > 0 && prec > (NByte-1-i) {
i := putint(&buf, nByte-1, uint64(base), uint64(a), digits);
for i > 0 && prec > (nByte-1-i) {
buf[i] = '0';
i--;
}
......@@ -212,156 +210,156 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits *string) string
buf[i] = ' ';
i--;
}
return string(buf)[i+1:NByte];
return string(buf)[i+1:nByte];
}
// decimal
func (f *Fmt) d64(a int64) *Fmt {
func (f *Fmt) Fmt_d64(a int64) *Fmt {
f.pad(f.integer(a, 10, true, &ldigits));
f.clearflags();
return f;
}
func (f *Fmt) d32(a int32) *Fmt {
return f.d64(int64(a));
func (f *Fmt) Fmt_d32(a int32) *Fmt {
return f.Fmt_d64(int64(a));
}
func (f *Fmt) d(a int) *Fmt {
return f.d64(int64(a));
func (f *Fmt) Fmt_d(a int) *Fmt {
return f.Fmt_d64(int64(a));
}
// unsigned decimal
func (f *Fmt) ud64(a uint64) *Fmt {
// unsigned Fmt_decimal
func (f *Fmt) Fmt_ud64(a uint64) *Fmt {
f.pad(f.integer(int64(a), 10, false, &ldigits));
f.clearflags();
return f;
}
func (f *Fmt) ud32(a uint32) *Fmt {
return f.ud64(uint64(a));
func (f *Fmt) Fmt_ud32(a uint32) *Fmt {
return f.Fmt_ud64(uint64(a));
}
func (f *Fmt) ud(a uint) *Fmt {
return f.ud64(uint64(a));
func (f *Fmt) Fmt_ud(a uint) *Fmt {
return f.Fmt_ud64(uint64(a));
}
// hexdecimal
func (f *Fmt) x64(a int64) *Fmt {
func (f *Fmt) Fmt_x64(a int64) *Fmt {
f.pad(f.integer(a, 16, true, &ldigits));
f.clearflags();
return f;
}
func (f *Fmt) x32(a int32) *Fmt {
return f.x64(int64(a));
func (f *Fmt) Fmt_x32(a int32) *Fmt {
return f.Fmt_x64(int64(a));
}
func (f *Fmt) x(a int) *Fmt {
return f.x64(int64(a));
func (f *Fmt) Fmt_x(a int) *Fmt {
return f.Fmt_x64(int64(a));
}
// unsigned hexdecimal
func (f *Fmt) ux64(a uint64) *Fmt {
func (f *Fmt) Fmt_ux64(a uint64) *Fmt {
f.pad(f.integer(int64(a), 16, false, &ldigits));
f.clearflags();
return f;
}
func (f *Fmt) ux32(a uint32) *Fmt {
return f.ux64(uint64(a));
func (f *Fmt) Fmt_ux32(a uint32) *Fmt {
return f.Fmt_ux64(uint64(a));
}
func (f *Fmt) ux(a uint) *Fmt {
return f.ux64(uint64(a));
func (f *Fmt) Fmt_ux(a uint) *Fmt {
return f.Fmt_ux64(uint64(a));
}
// HEXADECIMAL
func (f *Fmt) X64(a int64) *Fmt {
func (f *Fmt) Fmt_X64(a int64) *Fmt {
f.pad(f.integer(a, 16, true, &udigits));
f.clearflags();
return f;
}
func (f *Fmt) X32(a int32) *Fmt {
return f.X64(int64(a));
func (f *Fmt) Fmt_X32(a int32) *Fmt {
return f.Fmt_X64(int64(a));
}
func (f *Fmt) X(a int) *Fmt {
return f.X64(int64(a));
func (f *Fmt) Fmt_X(a int) *Fmt {
return f.Fmt_X64(int64(a));
}
// unsigned HEXADECIMAL
func (f *Fmt) uX64(a uint64) *Fmt {
func (f *Fmt) Fmt_uX64(a uint64) *Fmt {
f.pad(f.integer(int64(a), 16, false, &udigits));
f.clearflags();
return f;
}
func (f *Fmt) uX32(a uint32) *Fmt {
return f.uX64(uint64(a));
func (f *Fmt) Fmt_uX32(a uint32) *Fmt {
return f.Fmt_uX64(uint64(a));
}
func (f *Fmt) uX(a uint) *Fmt {
return f.uX64(uint64(a));
func (f *Fmt) Fmt_uX(a uint) *Fmt {
return f.Fmt_uX64(uint64(a));
}
// octal
func (f *Fmt) o64(a int64) *Fmt {
func (f *Fmt) Fmt_o64(a int64) *Fmt {
f.pad(f.integer(a, 8, true, &ldigits));
f.clearflags();
return f;
}
func (f *Fmt) o32(a int32) *Fmt {
return f.o64(int64(a));
func (f *Fmt) Fmt_o32(a int32) *Fmt {
return f.Fmt_o64(int64(a));
}
func (f *Fmt) o(a int) *Fmt {
return f.o64(int64(a));
func (f *Fmt) Fmt_o(a int) *Fmt {
return f.Fmt_o64(int64(a));
}
// unsigned octal
func (f *Fmt) uo64(a uint64) *Fmt {
func (f *Fmt) Fmt_uo64(a uint64) *Fmt {
f.pad(f.integer(int64(a), 8, false, &ldigits));
f.clearflags();
return f;
}
func (f *Fmt) uo32(a uint32) *Fmt {
return f.uo64(uint64(a));
func (f *Fmt) Fmt_uo32(a uint32) *Fmt {
return f.Fmt_uo64(uint64(a));
}
func (f *Fmt) uo(a uint) *Fmt {
return f.uo64(uint64(a));
func (f *Fmt) Fmt_uo(a uint) *Fmt {
return f.Fmt_uo64(uint64(a));
}
// unsigned binary
func (f *Fmt) b64(a uint64) *Fmt {
func (f *Fmt) Fmt_b64(a uint64) *Fmt {
f.pad(f.integer(int64(a), 2, false, &ldigits));
f.clearflags();
return f;
}
func (f *Fmt) b32(a uint32) *Fmt {
return f.b64(uint64(a));
func (f *Fmt) Fmt_b32(a uint32) *Fmt {
return f.Fmt_b64(uint64(a));
}
func (f *Fmt) b(a uint) *Fmt {
return f.b64(uint64(a));
func (f *Fmt) Fmt_b(a uint) *Fmt {
return f.Fmt_b64(uint64(a));
}
// character
func (f *Fmt) c(a int) *Fmt {
func (f *Fmt) Fmt_c(a int) *Fmt {
f.pad(string(a));
f.clearflags();
return f;
}
// string
func (f *Fmt) s(s string) *Fmt {
func (f *Fmt) Fmt_s(s string) *Fmt {
if f.prec_present {
if f.prec < len(s) {
s = s[0:f.prec];
......@@ -373,7 +371,7 @@ func (f *Fmt) s(s string) *Fmt {
}
// hexadecimal string
func (f *Fmt) sx(s string) *Fmt {
func (f *Fmt) Fmt_sx(s string) *Fmt {
t := "";
for i := 0; i < len(s); i++ {
if i > 0 && f.space {
......@@ -388,7 +386,7 @@ func (f *Fmt) sx(s string) *Fmt {
return f;
}
func (f *Fmt) sX(s string) *Fmt {
func (f *Fmt) Fmt_sX(s string) *Fmt {
t := "";
for i := 0; i < len(s); i++ {
v := s[i];
......@@ -401,7 +399,7 @@ func (f *Fmt) sX(s string) *Fmt {
}
// quoted string
func (f *Fmt) q(s string) *Fmt {
func (f *Fmt) Fmt_q(s string) *Fmt {
var quoted string;
if f.sharp && strconv.CanBackquote(s) {
quoted = "`"+s+"`";
......@@ -422,73 +420,73 @@ func Prec(f *Fmt, def int) int {
return def;
}
func FmtString(f *Fmt, s string) *Fmt {
func fmtString(f *Fmt, s string) *Fmt {
f.pad(s);
f.clearflags();
return f;
}
// float64
func (f *Fmt) e64(a float64) *Fmt {
return FmtString(f, strconv.ftoa64(a, 'e', Prec(f, 6)));
func (f *Fmt) Fmt_e64(a float64) *Fmt {
return fmtString(f, strconv.ftoa64(a, 'e', Prec(f, 6)));
}
func (f *Fmt) f64(a float64) *Fmt {
return FmtString(f, strconv.ftoa64(a, 'f', Prec(f, 6)));
func (f *Fmt) Fmt_f64(a float64) *Fmt {
return fmtString(f, strconv.ftoa64(a, 'f', Prec(f, 6)));
}
func (f *Fmt) g64(a float64) *Fmt {
return FmtString(f, strconv.ftoa64(a, 'g', Prec(f, -1)));
func (f *Fmt) Fmt_g64(a float64) *Fmt {
return fmtString(f, strconv.ftoa64(a, 'g', Prec(f, -1)));
}
func (f *Fmt) fb64(a float64) *Fmt {
return FmtString(f, strconv.ftoa64(a, 'b', 0));
func (f *Fmt) Fmt_fb64(a float64) *Fmt {
return fmtString(f, strconv.ftoa64(a, 'b', 0));
}
// float32
// cannot defer to float64 versions
// because it will get rounding wrong in corner cases.
func (f *Fmt) e32(a float32) *Fmt {
return FmtString(f, strconv.ftoa32(a, 'e', Prec(f, 6)));
func (f *Fmt) Fmt_e32(a float32) *Fmt {
return fmtString(f, strconv.ftoa32(a, 'e', Prec(f, 6)));
}
func (f *Fmt) f32(a float32) *Fmt {
return FmtString(f, strconv.ftoa32(a, 'f', Prec(f, 6)));
func (f *Fmt) Fmt_f32(a float32) *Fmt {
return fmtString(f, strconv.ftoa32(a, 'f', Prec(f, 6)));
}
func (f *Fmt) g32(a float32) *Fmt {
return FmtString(f, strconv.ftoa32(a, 'g', Prec(f, -1)));
func (f *Fmt) Fmt_g32(a float32) *Fmt {
return fmtString(f, strconv.ftoa32(a, 'g', Prec(f, -1)));
}
func (f *Fmt) fb32(a float32) *Fmt {
return FmtString(f, strconv.ftoa32(a, 'b', 0));
func (f *Fmt) Fmt_fb32(a float32) *Fmt {
return fmtString(f, strconv.ftoa32(a, 'b', 0));
}
// float
func (x *Fmt) f(a float) *Fmt {
if strconv.floatsize == 32 {
return x.f32(float32(a))
return x.Fmt_f32(float32(a))
}
return x.f64(float64(a))
return x.Fmt_f64(float64(a))
}
func (x *Fmt) e(a float) *Fmt {
if strconv.floatsize == 32 {
return x.e32(float32(a))
return x.Fmt_e32(float32(a))
}
return x.e64(float64(a))
return x.Fmt_e64(float64(a))
}
func (x *Fmt) g(a float) *Fmt {
if strconv.floatsize == 32 {
return x.g32(float32(a))
return x.Fmt_g32(float32(a))
}
return x.g64(float64(a))
return x.Fmt_g64(float64(a))
}
func (x *Fmt) fb(a float) *Fmt {
if strconv.floatsize == 32 {
return x.fb32(float32(a))
return x.Fmt_fb32(float32(a))
}
return x.fb64(float64(a))
return x.Fmt_fb64(float64(a))
}
......@@ -28,38 +28,38 @@ export type Formatter interface {
Flag(int) bool;
}
type Format interface {
export type Format interface {
Format(f Formatter, c int);
}
type String interface {
export type String interface {
String() string
}
const Runeself = 0x80
const AllocSize = 32
const runeSelf = 0x80
const allocSize = 32
type P struct {
type pp struct {
n int;
buf []byte;
fmt *Fmt;
}
func Printer() *P {
p := new(P);
func Printer() *pp {
p := new(pp);
p.fmt = fmt.New();
return p;
}
func (p *P) Width() (wid int, ok bool) {
func (p *pp) Width() (wid int, ok bool) {
return p.fmt.wid, p.fmt.wid_present
}
func (p *P) Precision() (prec int, ok bool) {
func (p *pp) Precision() (prec int, ok bool) {
return p.fmt.prec, p.fmt.prec_present
}
func (p *P) Flag(b int) bool {
func (p *pp) Flag(b int) bool {
switch b {
case '-':
return p.fmt.minus;
......@@ -75,11 +75,11 @@ func (p *P) Flag(b int) bool {
return false
}
func (p *P) ensure(n int) {
func (p *pp) ensure(n int) {
if len(p.buf) < n {
newn := AllocSize + len(p.buf);
newn := allocSize + len(p.buf);
if newn < n {
newn = n + AllocSize
newn = n + allocSize
}
b := make([]byte, newn);
for i := 0; i < p.n; i++ {
......@@ -89,7 +89,7 @@ func (p *P) ensure(n int) {
}
}
func (p *P) addstr(s string) {
func (p *pp) addstr(s string) {
n := len(s);
p.ensure(p.n + n);
for i := 0; i < n; i++ {
......@@ -98,7 +98,7 @@ func (p *P) addstr(s string) {
}
}
func (p *P) addbytes(b []byte, start, end int) {
func (p *pp) addbytes(b []byte, start, end int) {
p.ensure(p.n + end-start);
for i := start; i < end; i++ {
p.buf[p.n] = b[i];
......@@ -106,9 +106,9 @@ func (p *P) addbytes(b []byte, start, end int) {
}
}
func (p *P) add(c int) {
func (p *pp) add(c int) {
p.ensure(p.n + 1);
if c < Runeself {
if c < runeSelf {
p.buf[p.n] = byte(c);
p.n++;
} else {
......@@ -118,13 +118,13 @@ func (p *P) add(c int) {
// Implement Write so we can call fprintf on a P, for
// recursive use in custom verbs.
func (p *P) Write(b []byte) (ret int, err *os.Error) {
func (p *pp) Write(b []byte) (ret int, err *os.Error) {
p.addbytes(b, 0, len(b));
return len(b), nil;
}
func (p *P) doprintf(format string, v reflect.StructValue);
func (p *P) doprint(v reflect.StructValue, addspace, addnewline bool);
func (p *pp) doprintf(format string, v reflect.StructValue);
func (p *pp) doprint(v reflect.StructValue, addspace, addnewline bool);
// These routines end in 'f' and take a format string.
......@@ -329,7 +329,7 @@ func parsenum(s string, start, end int) (n int, got bool, newi int) {
return num, isnum, start;
}
func (p *P) printField(field reflect.Value) (was_string bool) {
func (p *pp) printField(field reflect.Value) (was_string bool) {
inter := field.Interface();
if inter != nil {
if stringer, ok := inter.(String); ok {
......@@ -340,34 +340,34 @@ func (p *P) printField(field reflect.Value) (was_string bool) {
s := "";
switch field.Kind() {
case reflect.BoolKind:
s = p.fmt.boolean(field.(reflect.BoolValue).Get()).str();
s = p.fmt.Fmt_boolean(field.(reflect.BoolValue).Get()).Str();
case reflect.IntKind, reflect.Int8Kind, reflect.Int16Kind, reflect.Int32Kind, reflect.Int64Kind:
v, signed, ok := getInt(field);
s = p.fmt.d64(v).str();
s = p.fmt.Fmt_d64(v).Str();
case reflect.UintKind, reflect.Uint8Kind, reflect.Uint16Kind, reflect.Uint32Kind, reflect.Uint64Kind:
v, signed, ok := getInt(field);
s = p.fmt.ud64(uint64(v)).str();
s = p.fmt.Fmt_ud64(uint64(v)).Str();
case reflect.UintptrKind:
v, signed, ok := getInt(field);
p.fmt.sharp = !p.fmt.sharp; // turn 0x on by default
s = p.fmt.ux64(uint64(v)).str();
s = p.fmt.Fmt_ux64(uint64(v)).Str();
case reflect.Float32Kind:
v, ok := getFloat32(field);
s = p.fmt.g32(v).str();
s = p.fmt.Fmt_g32(v).Str();
case reflect.Float64Kind, reflect.Float80Kind:
v, ok := getFloat64(field);
s = p.fmt.g64(v).str();
s = p.fmt.Fmt_g64(v).Str();
case reflect.FloatKind:
if field.Type().Size()*8 == 32 {
v, ok := getFloat32(field);
s = p.fmt.g32(v).str();
s = p.fmt.Fmt_g32(v).Str();
} else {
v, ok := getFloat64(field);
s = p.fmt.g64(v).str();
s = p.fmt.Fmt_g64(v).Str();
}
case reflect.StringKind:
v, ok := getString(field);
s = p.fmt.s(v).str();
s = p.fmt.Fmt_s(v).Str();
was_string = true;
case reflect.PtrKind:
if v, ok := getPtr(field); v == 0 {
......@@ -385,7 +385,7 @@ func (p *P) printField(field reflect.Value) (was_string bool) {
p.addstr("]");
} else {
p.fmt.sharp = !p.fmt.sharp; // turn 0x on by default
s = p.fmt.uX64(uint64(v)).str();
s = p.fmt.Fmt_uX64(uint64(v)).Str();
}
}
case reflect.ArrayKind:
......@@ -433,7 +433,7 @@ func (p *P) printField(field reflect.Value) (was_string bool) {
return was_string;
}
func (p *P) doprintf(format string, v reflect.StructValue) {
func (p *pp) doprintf(format string, v reflect.StructValue) {
p.ensure(len(format)); // a good starting size
end := len(format) - 1;
fieldnum := 0; // we process one field per non-trivial format
......@@ -508,26 +508,26 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
// int
case 'b':
if v, signed, ok := getInt(field); ok {
s = p.fmt.b64(uint64(v)).str() // always unsigned
s = p.fmt.Fmt_b64(uint64(v)).Str() // always unsigned
} else if v, ok := getFloat32(field); ok {
s = p.fmt.fb32(v).str()
s = p.fmt.Fmt_fb32(v).Str()
} else if v, ok := getFloat64(field); ok {
s = p.fmt.fb64(v).str()
s = p.fmt.Fmt_fb64(v).Str()
} else {
goto badtype
}
case 'c':
if v, signed, ok := getInt(field); ok {
s = p.fmt.c(int(v)).str()
s = p.fmt.Fmt_c(int(v)).Str()
} else {
goto badtype
}
case 'd':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.d64(v).str()
s = p.fmt.Fmt_d64(v).Str()
} else {
s = p.fmt.ud64(uint64(v)).str()
s = p.fmt.Fmt_ud64(uint64(v)).Str()
}
} else {
goto badtype
......@@ -535,9 +535,9 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
case 'o':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.o64(v).str()
s = p.fmt.Fmt_o64(v).Str()
} else {
s = p.fmt.uo64(uint64(v)).str()
s = p.fmt.Fmt_uo64(uint64(v)).Str()
}
} else {
goto badtype
......@@ -545,24 +545,24 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
case 'x':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.x64(v).str()
s = p.fmt.Fmt_x64(v).Str()
} else {
s = p.fmt.ux64(uint64(v)).str()
s = p.fmt.Fmt_ux64(uint64(v)).Str()
}
} else if v, ok := getString(field); ok {
s = p.fmt.sx(v).str();
s = p.fmt.Fmt_sx(v).Str();
} else {
goto badtype
}
case 'X':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.X64(v).str()
s = p.fmt.Fmt_X64(v).Str()
} else {
s = p.fmt.uX64(uint64(v)).str()
s = p.fmt.Fmt_uX64(uint64(v)).Str()
}
} else if v, ok := getString(field); ok {
s = p.fmt.sX(v).str();
s = p.fmt.Fmt_sX(v).Str();
} else {
goto badtype
}
......@@ -570,25 +570,25 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
// float
case 'e':
if v, ok := getFloat32(field); ok {
s = p.fmt.e32(v).str()
s = p.fmt.Fmt_e32(v).Str()
} else if v, ok := getFloat64(field); ok {
s = p.fmt.e64(v).str()
s = p.fmt.Fmt_e64(v).Str()
} else {
goto badtype
}
case 'f':
if v, ok := getFloat32(field); ok {
s = p.fmt.f32(v).str()
s = p.fmt.Fmt_f32(v).Str()
} else if v, ok := getFloat64(field); ok {
s = p.fmt.f64(v).str()
s = p.fmt.Fmt_f64(v).Str()
} else {
goto badtype
}
case 'g':
if v, ok := getFloat32(field); ok {
s = p.fmt.g32(v).str()
s = p.fmt.Fmt_g32(v).Str()
} else if v, ok := getFloat64(field); ok {
s = p.fmt.g64(v).str()
s = p.fmt.Fmt_g64(v).Str()
} else {
goto badtype
}
......@@ -596,13 +596,13 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
// string
case 's':
if v, ok := getString(field); ok {
s = p.fmt.s(v).str()
s = p.fmt.Fmt_s(v).Str()
} else {
goto badtype
}
case 'q':
if v, ok := getString(field); ok {
s = p.fmt.q(v).str()
s = p.fmt.Fmt_q(v).Str()
} else {
goto badtype
}
......@@ -613,7 +613,7 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
if v == 0 {
s = "<nil>"
} else {
s = "0x" + p.fmt.uX64(uint64(v)).str()
s = "0x" + p.fmt.Fmt_uX64(uint64(v)).Str()
}
} else {
goto badtype
......@@ -645,7 +645,7 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
}
}
func (p *P) doprint(v reflect.StructValue, addspace, addnewline bool) {
func (p *pp) doprint(v reflect.StructValue, addspace, addnewline bool) {
prev_string := false;
for fieldnum := 0; fieldnum < v.Len(); fieldnum++ {
// always add spaces if we're doing println
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment