Commit 353ef80f authored by Rob Pike's avatar Rob Pike

unexport Fmt. it's not needed outside this package any more

cleans up godoc's output for package fmt substantially.

R=rsc
CC=golang-dev
https://golang.org/cl/165070
parent 4c0e51cd
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
const ( const (
nByte = 64; nByte = 64;
nPows10 = 160;
ldigits = "0123456789abcdef"; ldigits = "0123456789abcdef";
udigits = "0123456789ABCDEF"; udigits = "0123456789ABCDEF";
...@@ -29,12 +28,9 @@ func init() { ...@@ -29,12 +28,9 @@ func init() {
} }
} }
/* // A fmt is the raw formatter used by Printf etc.
Fmt is the raw formatter used by Printf etc. Not meant for normal use. // It prints into a bytes.Buffer that must be set up externally.
It prints into a bytes.Buffer that must be set up externally. type fmt struct {
See print.go for a more palatable interface.
*/
type Fmt struct {
intbuf [nByte]byte; intbuf [nByte]byte;
buf *bytes.Buffer; buf *bytes.Buffer;
wid int; wid int;
...@@ -49,7 +45,7 @@ type Fmt struct { ...@@ -49,7 +45,7 @@ type Fmt struct {
zero bool; zero bool;
} }
func (f *Fmt) ClearFlags() { func (f *fmt) clearflags() {
f.wid = 0; f.wid = 0;
f.widPresent = false; f.widPresent = false;
f.prec = 0; f.prec = 0;
...@@ -61,35 +57,13 @@ func (f *Fmt) ClearFlags() { ...@@ -61,35 +57,13 @@ func (f *Fmt) ClearFlags() {
f.zero = false; f.zero = false;
} }
func (f *Fmt) Init(buf *bytes.Buffer) { func (f *fmt) init(buf *bytes.Buffer) {
f.buf = buf; f.buf = buf;
f.ClearFlags(); f.clearflags();
}
func (f *Fmt) Reset() { f.ClearFlags() }
// Wp sets the width and precision for formatting the next item.
func (f *Fmt) Wp(w, p int) {
f.widPresent = true;
f.wid = w;
f.precPresent = true;
f.prec = p;
}
// P sets the precision for formatting the next item.
func (f *Fmt) P(p int) {
f.precPresent = true;
f.prec = p;
}
// W sets the width for formatting the next item.
func (f *Fmt) W(x int) {
f.widPresent = true;
f.wid = x;
} }
// Compute left and right padding widths (only one will be non-zero). // Compute left and right padding widths (only one will be non-zero).
func (f *Fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth int) { func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth int) {
left := !f.minus; left := !f.minus;
w := f.wid; w := f.wid;
if w < 0 { if w < 0 {
...@@ -112,7 +86,7 @@ func (f *Fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth i ...@@ -112,7 +86,7 @@ func (f *Fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth i
} }
// Generate n bytes of padding. // Generate n bytes of padding.
func (f *Fmt) writePadding(n int, padding []byte) { func (f *fmt) writePadding(n int, padding []byte) {
for n > 0 { for n > 0 {
m := n; m := n;
if m > nByte { if m > nByte {
...@@ -124,7 +98,7 @@ func (f *Fmt) writePadding(n int, padding []byte) { ...@@ -124,7 +98,7 @@ func (f *Fmt) writePadding(n int, padding []byte) {
} }
// Append b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus) // Append b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus)
func (f *Fmt) padBytes(b []byte) { func (f *fmt) padBytes(b []byte) {
var padding []byte; var padding []byte;
var left, right int; var left, right int;
if f.widPresent && f.wid != 0 { if f.widPresent && f.wid != 0 {
...@@ -140,7 +114,7 @@ func (f *Fmt) padBytes(b []byte) { ...@@ -140,7 +114,7 @@ func (f *Fmt) padBytes(b []byte) {
} }
// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus) // append s to buf, padded on left (w > 0) or right (w < 0 or f.minus)
func (f *Fmt) pad(s string) { func (f *fmt) pad(s string) {
var padding []byte; var padding []byte;
var left, right int; var left, right int;
if f.widPresent && f.wid != 0 { if f.widPresent && f.wid != 0 {
...@@ -171,18 +145,18 @@ func putint(buf []byte, base, val uint64, digits string) int { ...@@ -171,18 +145,18 @@ func putint(buf []byte, base, val uint64, digits string) int {
return i - 1; return i - 1;
} }
// Fmt_boolean formats a boolean. // fmt_boolean formats a boolean.
func (f *Fmt) Fmt_boolean(v bool) { func (f *fmt) fmt_boolean(v bool) {
if v { if v {
f.pad("true") f.pad("true")
} else { } else {
f.pad("false") f.pad("false")
} }
f.ClearFlags(); f.clearflags();
} }
// integer; interprets prec but not wid. // integer; interprets prec but not wid.
func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) []byte { func (f *fmt) integer(a int64, base uint, is_signed bool, digits string) []byte {
var buf []byte = &f.intbuf; var buf []byte = &f.intbuf;
negative := is_signed && a < 0; negative := is_signed && a < 0;
if negative { if negative {
...@@ -236,134 +210,134 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) []byte ...@@ -236,134 +210,134 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) []byte
return buf[i+1 : nByte]; return buf[i+1 : nByte];
} }
// Fmt_d64 formats an int64 in decimal. // fmt_d64 formats an int64 in decimal.
func (f *Fmt) Fmt_d64(v int64) { func (f *fmt) fmt_d64(v int64) {
f.padBytes(f.integer(v, 10, true, ldigits)); f.padBytes(f.integer(v, 10, true, ldigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_d32 formats an int32 in decimal. // fmt_d32 formats an int32 in decimal.
func (f *Fmt) Fmt_d32(v int32) { f.Fmt_d64(int64(v)) } func (f *fmt) fmt_d32(v int32) { f.fmt_d64(int64(v)) }
// Fmt_d formats an int in decimal. // fmt_d formats an int in decimal.
func (f *Fmt) Fmt_d(v int) { f.Fmt_d64(int64(v)) } func (f *fmt) fmt_d(v int) { f.fmt_d64(int64(v)) }
// Fmt_ud64 formats a uint64 in decimal. // fmt_ud64 formats a uint64 in decimal.
func (f *Fmt) Fmt_ud64(v uint64) *Fmt { func (f *fmt) fmt_ud64(v uint64) *fmt {
f.padBytes(f.integer(int64(v), 10, false, ldigits)); f.padBytes(f.integer(int64(v), 10, false, ldigits));
f.ClearFlags(); f.clearflags();
return f; return f;
} }
// Fmt_ud32 formats a uint32 in decimal. // fmt_ud32 formats a uint32 in decimal.
func (f *Fmt) Fmt_ud32(v uint32) { f.Fmt_ud64(uint64(v)) } func (f *fmt) fmt_ud32(v uint32) { f.fmt_ud64(uint64(v)) }
// Fmt_ud formats a uint in decimal. // fmt_ud formats a uint in decimal.
func (f *Fmt) Fmt_ud(v uint) { f.Fmt_ud64(uint64(v)) } func (f *fmt) fmt_ud(v uint) { f.fmt_ud64(uint64(v)) }
// Fmt_x64 formats an int64 in hexadecimal. // fmt_x64 formats an int64 in hexadecimal.
func (f *Fmt) Fmt_x64(v int64) { func (f *fmt) fmt_x64(v int64) {
f.padBytes(f.integer(v, 16, true, ldigits)); f.padBytes(f.integer(v, 16, true, ldigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_x32 formats an int32 in hexadecimal. // fmt_x32 formats an int32 in hexadecimal.
func (f *Fmt) Fmt_x32(v int32) { f.Fmt_x64(int64(v)) } func (f *fmt) fmt_x32(v int32) { f.fmt_x64(int64(v)) }
// Fmt_x formats an int in hexadecimal. // fmt_x formats an int in hexadecimal.
func (f *Fmt) Fmt_x(v int) { f.Fmt_x64(int64(v)) } func (f *fmt) fmt_x(v int) { f.fmt_x64(int64(v)) }
// Fmt_ux64 formats a uint64 in hexadecimal. // fmt_ux64 formats a uint64 in hexadecimal.
func (f *Fmt) Fmt_ux64(v uint64) { func (f *fmt) fmt_ux64(v uint64) {
f.padBytes(f.integer(int64(v), 16, false, ldigits)); f.padBytes(f.integer(int64(v), 16, false, ldigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_ux32 formats a uint32 in hexadecimal. // fmt_ux32 formats a uint32 in hexadecimal.
func (f *Fmt) Fmt_ux32(v uint32) { f.Fmt_ux64(uint64(v)) } func (f *fmt) fmt_ux32(v uint32) { f.fmt_ux64(uint64(v)) }
// Fmt_ux formats a uint in hexadecimal. // fmt_ux formats a uint in hexadecimal.
func (f *Fmt) Fmt_ux(v uint) { f.Fmt_ux64(uint64(v)) } func (f *fmt) fmt_ux(v uint) { f.fmt_ux64(uint64(v)) }
// Fmt_X64 formats an int64 in upper case hexadecimal. // fmt_X64 formats an int64 in upper case hexadecimal.
func (f *Fmt) Fmt_X64(v int64) { func (f *fmt) fmt_X64(v int64) {
f.padBytes(f.integer(v, 16, true, udigits)); f.padBytes(f.integer(v, 16, true, udigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_X32 formats an int32 in upper case hexadecimal. // fmt_X32 formats an int32 in upper case hexadecimal.
func (f *Fmt) Fmt_X32(v int32) { f.Fmt_X64(int64(v)) } func (f *fmt) fmt_X32(v int32) { f.fmt_X64(int64(v)) }
// Fmt_X formats an int in upper case hexadecimal. // fmt_X formats an int in upper case hexadecimal.
func (f *Fmt) Fmt_X(v int) { f.Fmt_X64(int64(v)) } func (f *fmt) fmt_X(v int) { f.fmt_X64(int64(v)) }
// Fmt_uX64 formats a uint64 in upper case hexadecimal. // fmt_uX64 formats a uint64 in upper case hexadecimal.
func (f *Fmt) Fmt_uX64(v uint64) { func (f *fmt) fmt_uX64(v uint64) {
f.padBytes(f.integer(int64(v), 16, false, udigits)); f.padBytes(f.integer(int64(v), 16, false, udigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_uX32 formats a uint32 in upper case hexadecimal. // fmt_uX32 formats a uint32 in upper case hexadecimal.
func (f *Fmt) Fmt_uX32(v uint32) { f.Fmt_uX64(uint64(v)) } func (f *fmt) fmt_uX32(v uint32) { f.fmt_uX64(uint64(v)) }
// Fmt_uX formats a uint in upper case hexadecimal. // fmt_uX formats a uint in upper case hexadecimal.
func (f *Fmt) Fmt_uX(v uint) { f.Fmt_uX64(uint64(v)) } func (f *fmt) fmt_uX(v uint) { f.fmt_uX64(uint64(v)) }
// Fmt_o64 formats an int64 in octal. // fmt_o64 formats an int64 in octal.
func (f *Fmt) Fmt_o64(v int64) { func (f *fmt) fmt_o64(v int64) {
f.padBytes(f.integer(v, 8, true, ldigits)); f.padBytes(f.integer(v, 8, true, ldigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_o32 formats an int32 in octal. // fmt_o32 formats an int32 in octal.
func (f *Fmt) Fmt_o32(v int32) { f.Fmt_o64(int64(v)) } func (f *fmt) fmt_o32(v int32) { f.fmt_o64(int64(v)) }
// Fmt_o formats an int in octal. // fmt_o formats an int in octal.
func (f *Fmt) Fmt_o(v int) { f.Fmt_o64(int64(v)) } func (f *fmt) fmt_o(v int) { f.fmt_o64(int64(v)) }
// Fmt_uo64 formats a uint64 in octal. // fmt_uo64 formats a uint64 in octal.
func (f *Fmt) Fmt_uo64(v uint64) { func (f *fmt) fmt_uo64(v uint64) {
f.padBytes(f.integer(int64(v), 8, false, ldigits)); f.padBytes(f.integer(int64(v), 8, false, ldigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_uo32 formats a uint32 in octal. // fmt_uo32 formats a uint32 in octal.
func (f *Fmt) Fmt_uo32(v uint32) { f.Fmt_uo64(uint64(v)) } func (f *fmt) fmt_uo32(v uint32) { f.fmt_uo64(uint64(v)) }
// Fmt_uo formats a uint in octal. // fmt_uo formats a uint in octal.
func (f *Fmt) Fmt_uo(v uint) { f.Fmt_uo64(uint64(v)) } func (f *fmt) fmt_uo(v uint) { f.fmt_uo64(uint64(v)) }
// Fmt_b64 formats a uint64 in binary. // fmt_b64 formats a uint64 in binary.
func (f *Fmt) Fmt_b64(v uint64) { func (f *fmt) fmt_b64(v uint64) {
f.padBytes(f.integer(int64(v), 2, false, ldigits)); f.padBytes(f.integer(int64(v), 2, false, ldigits));
f.ClearFlags(); f.clearflags();
} }
// Fmt_b32 formats a uint32 in binary. // fmt_b32 formats a uint32 in binary.
func (f *Fmt) Fmt_b32(v uint32) { f.Fmt_b64(uint64(v)) } func (f *fmt) fmt_b32(v uint32) { f.fmt_b64(uint64(v)) }
// Fmt_b formats a uint in binary. // fmt_b formats a uint in binary.
func (f *Fmt) Fmt_b(v uint) { f.Fmt_b64(uint64(v)) } func (f *fmt) fmt_b(v uint) { f.fmt_b64(uint64(v)) }
// Fmt_c formats a Unicode character. // fmt_c formats a Unicode character.
func (f *Fmt) Fmt_c(v int) { func (f *fmt) fmt_c(v int) {
f.pad(string(v)); f.pad(string(v));
f.ClearFlags(); f.clearflags();
} }
// Fmt_s formats a string. // fmt_s formats a string.
func (f *Fmt) Fmt_s(s string) { func (f *fmt) fmt_s(s string) {
if f.precPresent { if f.precPresent {
if f.prec < len(s) { if f.prec < len(s) {
s = s[0:f.prec] s = s[0:f.prec]
} }
} }
f.pad(s); f.pad(s);
f.ClearFlags(); f.clearflags();
} }
// Fmt_sx formats a string as a hexadecimal encoding of its bytes. // fmt_sx formats a string as a hexadecimal encoding of its bytes.
func (f *Fmt) Fmt_sx(s string) { func (f *fmt) fmt_sx(s string) {
t := ""; t := "";
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
if i > 0 && f.space { if i > 0 && f.space {
...@@ -374,11 +348,11 @@ func (f *Fmt) Fmt_sx(s string) { ...@@ -374,11 +348,11 @@ func (f *Fmt) Fmt_sx(s string) {
t += string(ldigits[v&0xF]); t += string(ldigits[v&0xF]);
} }
f.pad(t); f.pad(t);
f.ClearFlags(); f.clearflags();
} }
// Fmt_sX formats a string as an uppercase hexadecimal encoding of its bytes. // fmt_sX formats a string as an uppercase hexadecimal encoding of its bytes.
func (f *Fmt) Fmt_sX(s string) { func (f *fmt) fmt_sX(s string) {
t := ""; t := "";
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
v := s[i]; v := s[i];
...@@ -386,11 +360,11 @@ func (f *Fmt) Fmt_sX(s string) { ...@@ -386,11 +360,11 @@ func (f *Fmt) Fmt_sX(s string) {
t += string(udigits[v&0xF]); t += string(udigits[v&0xF]);
} }
f.pad(t); f.pad(t);
f.ClearFlags(); f.clearflags();
} }
// Fmt_q formats a string as a double-quoted, escaped Go string constant. // fmt_q formats a string as a double-quoted, escaped Go string constant.
func (f *Fmt) Fmt_q(s string) { func (f *fmt) fmt_q(s string) {
var quoted string; var quoted string;
if f.sharp && strconv.CanBackquote(s) { if f.sharp && strconv.CanBackquote(s) {
quoted = "`" + s + "`" quoted = "`" + s + "`"
...@@ -398,25 +372,25 @@ func (f *Fmt) Fmt_q(s string) { ...@@ -398,25 +372,25 @@ func (f *Fmt) Fmt_q(s string) {
quoted = strconv.Quote(s) quoted = strconv.Quote(s)
} }
f.pad(quoted); f.pad(quoted);
f.ClearFlags(); f.clearflags();
} }
// floating-point // floating-point
func doPrec(f *Fmt, def int) int { func doPrec(f *fmt, def int) int {
if f.precPresent { if f.precPresent {
return f.prec return f.prec
} }
return def; return def;
} }
func fmtString(f *Fmt, s string) { func fmtString(f *fmt, s string) {
f.pad(s); f.pad(s);
f.ClearFlags(); f.clearflags();
} }
// Add a plus sign or space to the string if missing and required. // Add a plus sign or space to the string if missing and required.
func (f *Fmt) plusSpace(s string) { func (f *fmt) plusSpace(s string) {
if s[0] != '-' { if s[0] != '-' {
if f.plus { if f.plus {
s = "+" + s s = "+" + s
...@@ -427,75 +401,75 @@ func (f *Fmt) plusSpace(s string) { ...@@ -427,75 +401,75 @@ func (f *Fmt) plusSpace(s string) {
fmtString(f, s); fmtString(f, s);
} }
// Fmt_e64 formats a float64 in the form -1.23e+12. // fmt_e64 formats a float64 in the form -1.23e+12.
func (f *Fmt) Fmt_e64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'e', doPrec(f, 6))) } func (f *fmt) fmt_e64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'e', doPrec(f, 6))) }
// Fmt_E64 formats a float64 in the form -1.23E+12. // fmt_E64 formats a float64 in the form -1.23E+12.
func (f *Fmt) Fmt_E64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'E', doPrec(f, 6))) } func (f *fmt) fmt_E64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'E', doPrec(f, 6))) }
// Fmt_f64 formats a float64 in the form -1.23. // fmt_f64 formats a float64 in the form -1.23.
func (f *Fmt) Fmt_f64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'f', doPrec(f, 6))) } func (f *fmt) fmt_f64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'f', doPrec(f, 6))) }
// Fmt_g64 formats a float64 in the 'f' or 'e' form according to size. // fmt_g64 formats a float64 in the 'f' or 'e' form according to size.
func (f *Fmt) Fmt_g64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'g', doPrec(f, -1))) } func (f *fmt) fmt_g64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'g', doPrec(f, -1))) }
// Fmt_g64 formats a float64 in the 'f' or 'E' form according to size. // fmt_g64 formats a float64 in the 'f' or 'E' form according to size.
func (f *Fmt) Fmt_G64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'G', doPrec(f, -1))) } func (f *fmt) fmt_G64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'G', doPrec(f, -1))) }
// Fmt_fb64 formats a float64 in the form -123p3 (exponent is power of 2). // fmt_fb64 formats a float64 in the form -123p3 (exponent is power of 2).
func (f *Fmt) Fmt_fb64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'b', 0)) } func (f *fmt) fmt_fb64(v float64) { f.plusSpace(strconv.Ftoa64(v, 'b', 0)) }
// float32 // float32
// cannot defer to float64 versions // cannot defer to float64 versions
// because it will get rounding wrong in corner cases. // because it will get rounding wrong in corner cases.
// Fmt_e32 formats a float32 in the form -1.23e+12. // fmt_e32 formats a float32 in the form -1.23e+12.
func (f *Fmt) Fmt_e32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'e', doPrec(f, 6))) } func (f *fmt) fmt_e32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'e', doPrec(f, 6))) }
// Fmt_E32 formats a float32 in the form -1.23E+12. // fmt_E32 formats a float32 in the form -1.23E+12.
func (f *Fmt) Fmt_E32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'E', doPrec(f, 6))) } func (f *fmt) fmt_E32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'E', doPrec(f, 6))) }
// Fmt_f32 formats a float32 in the form -1.23. // fmt_f32 formats a float32 in the form -1.23.
func (f *Fmt) Fmt_f32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'f', doPrec(f, 6))) } func (f *fmt) fmt_f32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'f', doPrec(f, 6))) }
// Fmt_g32 formats a float32 in the 'f' or 'e' form according to size. // fmt_g32 formats a float32 in the 'f' or 'e' form according to size.
func (f *Fmt) Fmt_g32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'g', doPrec(f, -1))) } func (f *fmt) fmt_g32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'g', doPrec(f, -1))) }
// Fmt_G32 formats a float32 in the 'f' or 'E' form according to size. // fmt_G32 formats a float32 in the 'f' or 'E' form according to size.
func (f *Fmt) Fmt_G32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'G', doPrec(f, -1))) } func (f *fmt) fmt_G32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'G', doPrec(f, -1))) }
// Fmt_fb32 formats a float32 in the form -123p3 (exponent is power of 2). // fmt_fb32 formats a float32 in the form -123p3 (exponent is power of 2).
func (f *Fmt) Fmt_fb32(v float32) { fmtString(f, strconv.Ftoa32(v, 'b', 0)) } func (f *fmt) fmt_fb32(v float32) { fmtString(f, strconv.Ftoa32(v, 'b', 0)) }
// float // float
func (x *Fmt) f(a float) { func (x *fmt) f(a float) {
if strconv.FloatSize == 32 { if strconv.FloatSize == 32 {
x.Fmt_f32(float32(a)) x.fmt_f32(float32(a))
} else { } else {
x.Fmt_f64(float64(a)) x.fmt_f64(float64(a))
} }
} }
func (x *Fmt) e(a float) { func (x *fmt) e(a float) {
if strconv.FloatSize == 32 { if strconv.FloatSize == 32 {
x.Fmt_e32(float32(a)) x.fmt_e32(float32(a))
} else { } else {
x.Fmt_e64(float64(a)) x.fmt_e64(float64(a))
} }
} }
func (x *Fmt) g(a float) { func (x *fmt) g(a float) {
if strconv.FloatSize == 32 { if strconv.FloatSize == 32 {
x.Fmt_g32(float32(a)) x.fmt_g32(float32(a))
} else { } else {
x.Fmt_g64(float64(a)) x.fmt_g64(float64(a))
} }
} }
func (x *Fmt) fb(a float) { func (x *fmt) fb(a float) {
if strconv.FloatSize == 32 { if strconv.FloatSize == 32 {
x.Fmt_fb32(float32(a)) x.fmt_fb32(float32(a))
} else { } else {
x.Fmt_fb64(float64(a)) x.fmt_fb64(float64(a))
} }
} }
...@@ -143,7 +143,7 @@ type pp struct { ...@@ -143,7 +143,7 @@ type pp struct {
n int; n int;
buf bytes.Buffer; buf bytes.Buffer;
runeBuf [utf8.UTFMax]byte; runeBuf [utf8.UTFMax]byte;
fmt Fmt; fmt fmt;
} }
// A leaky bucket of reusable pp structures. // A leaky bucket of reusable pp structures.
...@@ -155,7 +155,7 @@ func newPrinter() *pp { ...@@ -155,7 +155,7 @@ func newPrinter() *pp {
p = new(pp) p = new(pp)
} }
p.buf.Reset(); p.buf.Reset();
p.fmt.Init(&p.buf); p.fmt.init(&p.buf);
return p; return p;
} }
...@@ -419,22 +419,22 @@ func (p *pp) printField(field reflect.Value, plus, sharp bool, depth int) (was_s ...@@ -419,22 +419,22 @@ func (p *pp) printField(field reflect.Value, plus, sharp bool, depth int) (was_s
BigSwitch: BigSwitch:
switch f := field.(type) { switch f := field.(type) {
case *reflect.BoolValue: case *reflect.BoolValue:
p.fmt.Fmt_boolean(f.Get()) p.fmt.fmt_boolean(f.Get())
case *reflect.Float32Value: case *reflect.Float32Value:
p.fmt.Fmt_g32(f.Get()) p.fmt.fmt_g32(f.Get())
case *reflect.Float64Value: case *reflect.Float64Value:
p.fmt.Fmt_g64(f.Get()) p.fmt.fmt_g64(f.Get())
case *reflect.FloatValue: case *reflect.FloatValue:
if field.Type().Size()*8 == 32 { if field.Type().Size()*8 == 32 {
p.fmt.Fmt_g32(float32(f.Get())) p.fmt.fmt_g32(float32(f.Get()))
} else { } else {
p.fmt.Fmt_g64(float64(f.Get())) p.fmt.fmt_g64(float64(f.Get()))
} }
case *reflect.StringValue: case *reflect.StringValue:
if sharp { if sharp {
p.fmt.Fmt_q(f.Get()) p.fmt.fmt_q(f.Get())
} else { } else {
p.fmt.Fmt_s(f.Get()); p.fmt.fmt_s(f.Get());
was_string = true; was_string = true;
} }
case *reflect.MapValue: case *reflect.MapValue:
...@@ -469,7 +469,7 @@ BigSwitch: ...@@ -469,7 +469,7 @@ BigSwitch:
p.add('{'); p.add('{');
v := f; v := f;
t := v.Type().(*reflect.StructType); t := v.Type().(*reflect.StructType);
p.fmt.ClearFlags(); // clear flags for p.printField p.fmt.clearflags(); // clear flags for p.printField
for i := 0; i < v.NumField(); i++ { for i := 0; i < v.NumField(); i++ {
if i > 0 { if i > 0 {
if sharp { if sharp {
...@@ -546,7 +546,7 @@ BigSwitch: ...@@ -546,7 +546,7 @@ BigSwitch:
p.buf.Write(nilBytes) p.buf.Write(nilBytes)
} else { } else {
p.fmt.sharp = true; p.fmt.sharp = true;
p.fmt.Fmt_ux64(uint64(v)); p.fmt.fmt_ux64(uint64(v));
} }
p.buf.WriteByte(')'); p.buf.WriteByte(')');
break; break;
...@@ -556,7 +556,7 @@ BigSwitch: ...@@ -556,7 +556,7 @@ BigSwitch:
break; break;
} }
p.fmt.sharp = true; // turn 0x on p.fmt.sharp = true; // turn 0x on
p.fmt.Fmt_ux64(uint64(v)); p.fmt.fmt_ux64(uint64(v));
case uintptrGetter: case uintptrGetter:
v := f.Get(); v := f.Get();
if sharp { if sharp {
...@@ -568,24 +568,24 @@ BigSwitch: ...@@ -568,24 +568,24 @@ BigSwitch:
p.buf.Write(nilBytes) p.buf.Write(nilBytes)
} else { } else {
p.fmt.sharp = true; p.fmt.sharp = true;
p.fmt.Fmt_ux64(uint64(v)); p.fmt.fmt_ux64(uint64(v));
} }
p.buf.WriteByte(')'); p.buf.WriteByte(')');
} else { } else {
p.fmt.sharp = true; // turn 0x on p.fmt.sharp = true; // turn 0x on
p.fmt.Fmt_ux64(uint64(f.Get())); p.fmt.fmt_ux64(uint64(f.Get()));
} }
default: default:
v, signed, ok := getInt(field); v, signed, ok := getInt(field);
if ok { if ok {
if signed { if signed {
p.fmt.Fmt_d64(v) p.fmt.fmt_d64(v)
} else { } else {
if sharp { if sharp {
p.fmt.sharp = true; // turn on 0x p.fmt.sharp = true; // turn on 0x
p.fmt.Fmt_ux64(uint64(v)); p.fmt.fmt_ux64(uint64(v));
} else { } else {
p.fmt.Fmt_ud64(uint64(v)) p.fmt.fmt_ud64(uint64(v))
} }
} }
break; break;
...@@ -613,7 +613,7 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) { ...@@ -613,7 +613,7 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
} }
i++; i++;
// flags and widths // flags and widths
p.fmt.ClearFlags(); p.fmt.clearflags();
F: for ; i < end; i++ { F: for ; i < end; i++ {
switch format[i] { switch format[i] {
case '#': case '#':
...@@ -678,26 +678,26 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) { ...@@ -678,26 +678,26 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// int // int
case 'b': case 'b':
if v, _, ok := getInt(field); ok { if v, _, ok := getInt(field); ok {
p.fmt.Fmt_b64(uint64(v)) // always unsigned p.fmt.fmt_b64(uint64(v)) // always unsigned
} else if v, ok := getFloat32(field); ok { } else if v, ok := getFloat32(field); ok {
p.fmt.Fmt_fb32(v) p.fmt.fmt_fb32(v)
} else if v, ok := getFloat64(field); ok { } else if v, ok := getFloat64(field); ok {
p.fmt.Fmt_fb64(v) p.fmt.fmt_fb64(v)
} else { } else {
goto badtype goto badtype
} }
case 'c': case 'c':
if v, _, ok := getInt(field); ok { if v, _, ok := getInt(field); ok {
p.fmt.Fmt_c(int(v)) p.fmt.fmt_c(int(v))
} else { } else {
goto badtype goto badtype
} }
case 'd': case 'd':
if v, signed, ok := getInt(field); ok { if v, signed, ok := getInt(field); ok {
if signed { if signed {
p.fmt.Fmt_d64(v) p.fmt.fmt_d64(v)
} else { } else {
p.fmt.Fmt_ud64(uint64(v)) p.fmt.fmt_ud64(uint64(v))
} }
} else { } else {
goto badtype goto badtype
...@@ -705,9 +705,9 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) { ...@@ -705,9 +705,9 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
case 'o': case 'o':
if v, signed, ok := getInt(field); ok { if v, signed, ok := getInt(field); ok {
if signed { if signed {
p.fmt.Fmt_o64(v) p.fmt.fmt_o64(v)
} else { } else {
p.fmt.Fmt_uo64(uint64(v)) p.fmt.fmt_uo64(uint64(v))
} }
} else { } else {
goto badtype goto badtype
...@@ -715,24 +715,24 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) { ...@@ -715,24 +715,24 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
case 'x': case 'x':
if v, signed, ok := getInt(field); ok { if v, signed, ok := getInt(field); ok {
if signed { if signed {
p.fmt.Fmt_x64(v) p.fmt.fmt_x64(v)
} else { } else {
p.fmt.Fmt_ux64(uint64(v)) p.fmt.fmt_ux64(uint64(v))
} }
} else if v, ok := getString(field); ok { } else if v, ok := getString(field); ok {
p.fmt.Fmt_sx(v) p.fmt.fmt_sx(v)
} else { } else {
goto badtype goto badtype
} }
case 'X': case 'X':
if v, signed, ok := getInt(field); ok { if v, signed, ok := getInt(field); ok {
if signed { if signed {
p.fmt.Fmt_X64(v) p.fmt.fmt_X64(v)
} else { } else {
p.fmt.Fmt_uX64(uint64(v)) p.fmt.fmt_uX64(uint64(v))
} }
} else if v, ok := getString(field); ok { } else if v, ok := getString(field); ok {
p.fmt.Fmt_sX(v) p.fmt.fmt_sX(v)
} else { } else {
goto badtype goto badtype
} }
...@@ -740,41 +740,41 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) { ...@@ -740,41 +740,41 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// float // float
case 'e': case 'e':
if v, ok := getFloat32(field); ok { if v, ok := getFloat32(field); ok {
p.fmt.Fmt_e32(v) p.fmt.fmt_e32(v)
} else if v, ok := getFloat64(field); ok { } else if v, ok := getFloat64(field); ok {
p.fmt.Fmt_e64(v) p.fmt.fmt_e64(v)
} else { } else {
goto badtype goto badtype
} }
case 'E': case 'E':
if v, ok := getFloat32(field); ok { if v, ok := getFloat32(field); ok {
p.fmt.Fmt_E32(v) p.fmt.fmt_E32(v)
} else if v, ok := getFloat64(field); ok { } else if v, ok := getFloat64(field); ok {
p.fmt.Fmt_E64(v) p.fmt.fmt_E64(v)
} else { } else {
goto badtype goto badtype
} }
case 'f': case 'f':
if v, ok := getFloat32(field); ok { if v, ok := getFloat32(field); ok {
p.fmt.Fmt_f32(v) p.fmt.fmt_f32(v)
} else if v, ok := getFloat64(field); ok { } else if v, ok := getFloat64(field); ok {
p.fmt.Fmt_f64(v) p.fmt.fmt_f64(v)
} else { } else {
goto badtype goto badtype
} }
case 'g': case 'g':
if v, ok := getFloat32(field); ok { if v, ok := getFloat32(field); ok {
p.fmt.Fmt_g32(v) p.fmt.fmt_g32(v)
} else if v, ok := getFloat64(field); ok { } else if v, ok := getFloat64(field); ok {
p.fmt.Fmt_g64(v) p.fmt.fmt_g64(v)
} else { } else {
goto badtype goto badtype
} }
case 'G': case 'G':
if v, ok := getFloat32(field); ok { if v, ok := getFloat32(field); ok {
p.fmt.Fmt_G32(v) p.fmt.fmt_G32(v)
} else if v, ok := getFloat64(field); ok { } else if v, ok := getFloat64(field); ok {
p.fmt.Fmt_G64(v) p.fmt.fmt_G64(v)
} else { } else {
goto badtype goto badtype
} }
...@@ -784,18 +784,18 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) { ...@@ -784,18 +784,18 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
if inter != nil { if inter != nil {
// if object implements String, use the result. // if object implements String, use the result.
if stringer, ok := inter.(Stringer); ok { if stringer, ok := inter.(Stringer); ok {
p.fmt.Fmt_s(stringer.String()); p.fmt.fmt_s(stringer.String());
break; break;
} }
} }
if v, ok := getString(field); ok { if v, ok := getString(field); ok {
p.fmt.Fmt_s(v) p.fmt.fmt_s(v)
} else { } else {
goto badtype goto badtype
} }
case 'q': case 'q':
if v, ok := getString(field); ok { if v, ok := getString(field); ok {
p.fmt.Fmt_q(v) p.fmt.fmt_q(v)
} else { } else {
goto badtype goto badtype
} }
...@@ -806,8 +806,8 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) { ...@@ -806,8 +806,8 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
if v == 0 { if v == 0 {
p.buf.Write(nilAngleBytes) p.buf.Write(nilAngleBytes)
} else { } else {
p.fmt.Fmt_s("0x"); p.fmt.fmt_s("0x");
p.fmt.Fmt_uX64(uint64(v)); p.fmt.fmt_uX64(uint64(v));
} }
} else { } else {
goto badtype goto badtype
......
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