summaryrefslogtreecommitdiff
path: root/src/pkg/fmt
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-12-15 15:27:16 -0800
committerRobert Griesemer <gri@golang.org>2009-12-15 15:27:16 -0800
commit881d6064d23d9da5c7ff368bc7d41d271290deff (patch)
tree44d5d948e3f27cc7eff15ec8cd7ee5165d9a7e90 /src/pkg/fmt
parentd9dfea3ebd51cea89fef8afc6b2377c2958b24f1 (diff)
downloadgolang-881d6064d23d9da5c7ff368bc7d41d271290deff.tar.gz
1) Change default gofmt default settings for
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 2nd set of files. R=rsc CC=golang-dev http://codereview.appspot.com/179067
Diffstat (limited to 'src/pkg/fmt')
-rw-r--r--src/pkg/fmt/fmt_test.go132
-rw-r--r--src/pkg/fmt/format.go276
-rw-r--r--src/pkg/fmt/print.go410
3 files changed, 409 insertions, 409 deletions
diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go
index 51a159ff1..78d4cf29a 100644
--- a/src/pkg/fmt/fmt_test.go
+++ b/src/pkg/fmt/fmt_test.go
@@ -5,27 +5,27 @@
package fmt_test
import (
- . "fmt";
- "io";
- "malloc"; // for the malloc count test only
- "math";
- "strings";
- "testing";
+ . "fmt"
+ "io"
+ "malloc" // for the malloc count test only
+ "math"
+ "strings"
+ "testing"
)
func TestFmtInterface(t *testing.T) {
var i1 interface{}
- i1 = "abc";
- s := Sprintf("%s", i1);
+ i1 = "abc"
+ s := Sprintf("%s", i1)
if s != "abc" {
t.Errorf(`Sprintf("%%s", empty("abc")) = %q want %q`, s, "abc")
}
}
type fmtTest struct {
- fmt string;
- val interface{};
- out string;
+ fmt string
+ val interface{}
+ out string
}
const b32 uint32 = 1<<32 - 1
@@ -35,24 +35,24 @@ var array = []int{1, 2, 3, 4, 5}
var iarray = []interface{}{1, "hello", 2.5, nil}
type A struct {
- i int;
- j uint;
- s string;
- x []int;
+ i int
+ j uint
+ s string
+ x []int
}
type I int
-func (i I) String() string { return Sprintf("<%d>", i) }
+func (i I) String() string { return Sprintf("<%d>", i) }
type B struct {
- i I;
- j int;
+ i I
+ j int
}
type C struct {
- i int;
- B;
+ i int
+ B
}
var b byte
@@ -228,16 +228,16 @@ var fmttests = []fmtTest{
func TestSprintf(t *testing.T) {
for _, tt := range fmttests {
- s := Sprintf(tt.fmt, tt.val);
+ s := Sprintf(tt.fmt, tt.val)
if i := strings.Index(s, "0x"); i >= 0 && strings.Index(tt.out, "PTR") >= 0 {
- j := i + 2;
+ j := i + 2
for ; j < len(s); j++ {
- c := s[j];
+ c := s[j]
if (c < '0' || c > '9') && (c < 'a' || c > 'f') {
break
}
}
- s = s[0:i] + "PTR" + s[j:];
+ s = s[0:i] + "PTR" + s[j:]
}
if s != tt.out {
if _, ok := tt.val.(string); ok {
@@ -276,36 +276,36 @@ func BenchmarkSprintfIntInt(b *testing.B) {
}
func TestCountMallocs(t *testing.T) {
- mallocs := 0 - malloc.GetStats().Mallocs;
+ mallocs := 0 - malloc.GetStats().Mallocs
for i := 0; i < 100; i++ {
Sprintf("")
}
- mallocs += malloc.GetStats().Mallocs;
- Printf("mallocs per Sprintf(\"\"): %d\n", mallocs/100);
- mallocs = 0 - malloc.GetStats().Mallocs;
+ mallocs += malloc.GetStats().Mallocs
+ Printf("mallocs per Sprintf(\"\"): %d\n", mallocs/100)
+ mallocs = 0 - malloc.GetStats().Mallocs
for i := 0; i < 100; i++ {
Sprintf("xxx")
}
- mallocs += malloc.GetStats().Mallocs;
- Printf("mallocs per Sprintf(\"xxx\"): %d\n", mallocs/100);
- mallocs = 0 - malloc.GetStats().Mallocs;
+ mallocs += malloc.GetStats().Mallocs
+ Printf("mallocs per Sprintf(\"xxx\"): %d\n", mallocs/100)
+ mallocs = 0 - malloc.GetStats().Mallocs
for i := 0; i < 100; i++ {
Sprintf("%x", i)
}
- mallocs += malloc.GetStats().Mallocs;
- Printf("mallocs per Sprintf(\"%%x\"): %d\n", mallocs/100);
- mallocs = 0 - malloc.GetStats().Mallocs;
+ mallocs += malloc.GetStats().Mallocs
+ Printf("mallocs per Sprintf(\"%%x\"): %d\n", mallocs/100)
+ mallocs = 0 - malloc.GetStats().Mallocs
for i := 0; i < 100; i++ {
Sprintf("%x %x", i, i)
}
- mallocs += malloc.GetStats().Mallocs;
- Printf("mallocs per Sprintf(\"%%x %%x\"): %d\n", mallocs/100);
+ mallocs += malloc.GetStats().Mallocs
+ Printf("mallocs per Sprintf(\"%%x %%x\"): %d\n", mallocs/100)
}
type flagPrinter struct{}
func (*flagPrinter) Format(f State, c int) {
- s := "%";
+ s := "%"
for i := 0; i < 128; i++ {
if f.Flag(i) {
s += string(i)
@@ -317,13 +317,13 @@ func (*flagPrinter) Format(f State, c int) {
if p, ok := f.Precision(); ok {
s += Sprintf(".%d", p)
}
- s += string(c);
- io.WriteString(f, "["+s+"]");
+ s += string(c)
+ io.WriteString(f, "["+s+"]")
}
type flagTest struct {
- in string;
- out string;
+ in string
+ out string
}
var flagtests = []flagTest{
@@ -342,9 +342,9 @@ var flagtests = []flagTest{
}
func TestFlagParser(t *testing.T) {
- var flagprinter flagPrinter;
+ var flagprinter flagPrinter
for _, tt := range flagtests {
- s := Sprintf(tt.in, &flagprinter);
+ s := Sprintf(tt.in, &flagprinter)
if s != tt.out {
t.Errorf("Sprintf(%q, &flagprinter) => %q, want %q", tt.in, s, tt.out)
}
@@ -353,23 +353,23 @@ func TestFlagParser(t *testing.T) {
func TestStructPrinter(t *testing.T) {
var s struct {
- a string;
- b string;
- c int;
+ a string
+ b string
+ c int
}
- s.a = "abc";
- s.b = "def";
- s.c = 123;
+ s.a = "abc"
+ s.b = "def"
+ s.c = 123
type Test struct {
- fmt string;
- out string;
+ fmt string
+ out string
}
var tests = []Test{
Test{"%v", "{abc def 123}"},
Test{"%+v", "{a:abc b:def c:123}"},
- };
+ }
for _, tt := range tests {
- out := Sprintf(tt.fmt, s);
+ out := Sprintf(tt.fmt, s)
if out != tt.out {
t.Errorf("Sprintf(%q, &s) = %q, want %q", tt.fmt, out, tt.out)
}
@@ -379,12 +379,12 @@ func TestStructPrinter(t *testing.T) {
// Check map printing using substrings so we don't depend on the print order.
func presentInMap(s string, a []string, t *testing.T) {
for i := 0; i < len(a); i++ {
- loc := strings.Index(s, a[i]);
+ loc := strings.Index(s, a[i])
if loc < 0 {
t.Errorf("map print: expected to find %q in %q", a[i], s)
}
// make sure the match ends here
- loc += len(a[i]);
+ loc += len(a[i])
if loc >= len(s) || (s[loc] != ' ' && s[loc] != ']') {
t.Errorf("map print: %q not properly terminated in %q", a[i], s)
}
@@ -392,26 +392,26 @@ func presentInMap(s string, a []string, t *testing.T) {
}
func TestMapPrinter(t *testing.T) {
- m0 := make(map[int]string);
- s := Sprint(m0);
+ m0 := make(map[int]string)
+ s := Sprint(m0)
if s != "map[]" {
t.Errorf("empty map printed as %q not %q", s, "map[]")
}
- m1 := map[int]string{1: "one", 2: "two", 3: "three"};
- a := []string{"1:one", "2:two", "3:three"};
- presentInMap(Sprintf("%v", m1), a, t);
- presentInMap(Sprint(m1), a, t);
+ m1 := map[int]string{1: "one", 2: "two", 3: "three"}
+ a := []string{"1:one", "2:two", "3:three"}
+ presentInMap(Sprintf("%v", m1), a, t)
+ presentInMap(Sprint(m1), a, t)
}
func TestEmptyMap(t *testing.T) {
- const emptyMapStr = "map[]";
- var m map[string]int;
- s := Sprint(m);
+ const emptyMapStr = "map[]"
+ var m map[string]int
+ s := Sprint(m)
if s != emptyMapStr {
t.Errorf("nil map printed as %q not %q", s, emptyMapStr)
}
- m = make(map[string]int);
- s = Sprint(m);
+ m = make(map[string]int)
+ s = Sprint(m)
if s != emptyMapStr {
t.Errorf("empty map printed as %q not %q", s, emptyMapStr)
}
diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go
index b53bcc5a6..38b234414 100644
--- a/src/pkg/fmt/format.go
+++ b/src/pkg/fmt/format.go
@@ -5,20 +5,20 @@
package fmt
import (
- "bytes";
- "strconv";
+ "bytes"
+ "strconv"
)
const (
- nByte = 64;
+ nByte = 64
- ldigits = "0123456789abcdef";
- udigits = "0123456789ABCDEF";
+ ldigits = "0123456789abcdef"
+ udigits = "0123456789ABCDEF"
)
const (
- signed = true;
- unsigned = false;
+ signed = true
+ unsigned = false
)
var padZeroBytes = make([]byte, nByte)
@@ -28,55 +28,55 @@ var newline = []byte{'\n'}
func init() {
for i := 0; i < nByte; i++ {
- padZeroBytes[i] = '0';
- padSpaceBytes[i] = ' ';
+ padZeroBytes[i] = '0'
+ padSpaceBytes[i] = ' '
}
}
// A fmt is the raw formatter used by Printf etc.
// It prints into a bytes.Buffer that must be set up externally.
type fmt struct {
- intbuf [nByte]byte;
- buf *bytes.Buffer;
+ intbuf [nByte]byte
+ buf *bytes.Buffer
// width, precision
- wid int;
- prec int;
+ wid int
+ prec int
// flags
- widPresent bool;
- precPresent bool;
- minus bool;
- plus bool;
- sharp bool;
- space bool;
- zero bool;
+ widPresent bool
+ precPresent bool
+ minus bool
+ plus bool
+ sharp bool
+ space bool
+ zero bool
}
func (f *fmt) clearflags() {
- f.wid = 0;
- f.widPresent = false;
- f.prec = 0;
- f.precPresent = false;
- f.minus = false;
- f.plus = false;
- f.sharp = false;
- f.space = false;
- f.zero = false;
+ f.wid = 0
+ f.widPresent = false
+ f.prec = 0
+ f.precPresent = false
+ f.minus = false
+ f.plus = false
+ f.sharp = false
+ f.space = false
+ f.zero = false
}
func (f *fmt) init(buf *bytes.Buffer) {
- f.buf = buf;
- f.clearflags();
+ f.buf = buf
+ f.clearflags()
}
// Compute left and right padding widths (only one will be non-zero).
func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth int) {
- left := !f.minus;
- w := f.wid;
+ left := !f.minus
+ w := f.wid
if w < 0 {
- left = false;
- w = -w;
+ left = false
+ w = -w
}
- w -= width;
+ w -= width
if w > 0 {
if left && f.zero {
return padZeroBytes, w, 0
@@ -88,66 +88,66 @@ func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth i
return padSpaceBytes, 0, w
}
}
- return;
+ return
}
// Generate n bytes of padding.
func (f *fmt) writePadding(n int, padding []byte) {
for n > 0 {
- m := n;
+ m := n
if m > nByte {
m = nByte
}
- f.buf.Write(padding[0:m]);
- n -= m;
+ f.buf.Write(padding[0:m])
+ n -= m
}
}
// Append b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus)
// clear flags aftewards.
func (f *fmt) pad(b []byte) {
- var padding []byte;
- var left, right int;
+ var padding []byte
+ var left, right int
if f.widPresent && f.wid != 0 {
padding, left, right = f.computePadding(len(b))
}
if left > 0 {
f.writePadding(left, padding)
}
- f.buf.Write(b);
+ f.buf.Write(b)
if right > 0 {
f.writePadding(right, padding)
}
- f.clearflags();
+ f.clearflags()
}
// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus).
// clear flags aftewards.
func (f *fmt) padString(s string) {
- var padding []byte;
- var left, right int;
+ var padding []byte
+ var left, right int
if f.widPresent && f.wid != 0 {
padding, left, right = f.computePadding(len(s))
}
if left > 0 {
f.writePadding(left, padding)
}
- f.buf.WriteString(s);
+ f.buf.WriteString(s)
if right > 0 {
f.writePadding(right, padding)
}
- f.clearflags();
+ f.clearflags()
}
func putint(buf []byte, base, val uint64, digits string) int {
- i := len(buf) - 1;
+ i := len(buf) - 1
for val >= base {
- buf[i] = digits[val%base];
- i--;
- val /= base;
+ buf[i] = digits[val%base]
+ i--
+ val /= base
}
- buf[i] = digits[val];
- return i - 1;
+ buf[i] = digits[val]
+ return i - 1
}
// fmt_boolean formats a boolean.
@@ -162,22 +162,22 @@ func (f *fmt) fmt_boolean(v bool) {
// integer; interprets prec but not wid. Once formatted, result is sent to pad()
// and then flags are cleared.
func (f *fmt) integer(a int64, base uint64, signedness bool, digits string) {
- var buf []byte = &f.intbuf;
- negative := signedness == signed && a < 0;
+ var buf []byte = &f.intbuf
+ negative := signedness == signed && a < 0
if negative {
a = -a
}
// two ways to ask for extra leading zero digits: %.3d or %03d.
// apparently the first cancels the second.
- prec := 0;
+ prec := 0
if f.precPresent {
- prec = f.prec;
- f.zero = false;
+ prec = f.prec
+ f.zero = false
} else if f.zero && f.widPresent && !f.minus && f.wid > 0 {
- prec = f.wid;
+ prec = f.wid
if negative || f.plus || f.space {
- prec-- // leave room for sign
+ prec-- // leave room for sign
}
}
@@ -185,18 +185,18 @@ func (f *fmt) integer(a int64, base uint64, signedness bool, digits string) {
// a is made into unsigned ua. we could make things
// marginally faster by splitting the 32-bit case out into a separate
// block but it's not worth the duplication, so ua has 64 bits.
- i := len(f.intbuf);
- ua := uint64(a);
+ i := len(f.intbuf)
+ ua := uint64(a)
for ua >= base {
- i--;
- buf[i] = digits[ua%base];
- ua /= base;
+ i--
+ buf[i] = digits[ua%base]
+ ua /= base
}
- i--;
- buf[i] = digits[ua];
+ i--
+ buf[i] = digits[ua]
for i > 0 && prec > nByte-i {
- i--;
- buf[i] = '0';
+ i--
+ buf[i] = '0'
}
// Various prefixes: 0x, -, etc.
@@ -204,113 +204,113 @@ func (f *fmt) integer(a int64, base uint64, signedness bool, digits string) {
switch base {
case 8:
if buf[i] != '0' {
- i--;
- buf[i] = '0';
+ i--
+ buf[i] = '0'
}
case 16:
- i--;
- buf[i] = 'x' + digits[10] - 'a';
- i--;
- buf[i] = '0';
+ i--
+ buf[i] = 'x' + digits[10] - 'a'
+ i--
+ buf[i] = '0'
}
}
if negative {
- i--;
- buf[i] = '-';
+ i--
+ buf[i] = '-'
} else if f.plus {
- i--;
- buf[i] = '+';
+ i--
+ buf[i] = '+'
} else if f.space {
- i--;
- buf[i] = ' ';
+ i--
+ buf[i] = ' '
}
- f.pad(buf[i:]);
+ f.pad(buf[i:])
}
// fmt_d64 formats an int64 in decimal.
-func (f *fmt) fmt_d64(v int64) { f.integer(v, 10, signed, ldigits) }
+func (f *fmt) fmt_d64(v int64) { f.integer(v, 10, signed, ldigits) }
// fmt_d32 formats an int32 in decimal.
-func (f *fmt) fmt_d32(v int32) { f.integer(int64(v), 10, signed, ldigits) }
+func (f *fmt) fmt_d32(v int32) { f.integer(int64(v), 10, signed, ldigits) }
// fmt_d formats an int in decimal.
-func (f *fmt) fmt_d(v int) { f.integer(int64(v), 10, signed, ldigits) }
+func (f *fmt) fmt_d(v int) { f.integer(int64(v), 10, signed, ldigits) }
// fmt_ud64 formats a uint64 in decimal.
-func (f *fmt) fmt_ud64(v uint64) { f.integer(int64(v), 10, unsigned, ldigits) }
+func (f *fmt) fmt_ud64(v uint64) { f.integer(int64(v), 10, unsigned, ldigits) }
// fmt_ud32 formats a uint32 in decimal.
-func (f *fmt) fmt_ud32(v uint32) { f.integer(int64(v), 10, unsigned, ldigits) }
+func (f *fmt) fmt_ud32(v uint32) { f.integer(int64(v), 10, unsigned, ldigits) }
// fmt_ud formats a uint in decimal.
-func (f *fmt) fmt_ud(v uint) { f.integer(int64(v), 10, unsigned, ldigits) }
+func (f *fmt) fmt_ud(v uint) { f.integer(int64(v), 10, unsigned, ldigits) }
// fmt_x64 formats an int64 in hexadecimal.
-func (f *fmt) fmt_x64(v int64) { f.integer(v, 16, signed, ldigits) }
+func (f *fmt) fmt_x64(v int64) { f.integer(v, 16, signed, ldigits) }
// fmt_x32 formats an int32 in hexadecimal.
-func (f *fmt) fmt_x32(v int32) { f.integer(int64(v), 16, signed, ldigits) }
+func (f *fmt) fmt_x32(v int32) { f.integer(int64(v), 16, signed, ldigits) }
// fmt_x formats an int in hexadecimal.
-func (f *fmt) fmt_x(v int) { f.integer(int64(v), 16, signed, ldigits) }
+func (f *fmt) fmt_x(v int) { f.integer(int64(v), 16, signed, ldigits) }
// fmt_ux64 formats a uint64 in hexadecimal.
-func (f *fmt) fmt_ux64(v uint64) { f.integer(int64(v), 16, unsigned, ldigits) }
+func (f *fmt) fmt_ux64(v uint64) { f.integer(int64(v), 16, unsigned, ldigits) }
// fmt_ux32 formats a uint32 in hexadecimal.
-func (f *fmt) fmt_ux32(v uint32) { f.integer(int64(v), 16, unsigned, ldigits) }
+func (f *fmt) fmt_ux32(v uint32) { f.integer(int64(v), 16, unsigned, ldigits) }
// fmt_ux formats a uint in hexadecimal.
-func (f *fmt) fmt_ux(v uint) { f.integer(int64(v), 16, unsigned, ldigits) }
+func (f *fmt) fmt_ux(v uint) { f.integer(int64(v), 16, unsigned, ldigits) }
// fmt_X64 formats an int64 in upper case hexadecimal.
-func (f *fmt) fmt_X64(v int64) { f.integer(v, 16, signed, udigits) }
+func (f *fmt) fmt_X64(v int64) { f.integer(v, 16, signed, udigits) }
// fmt_X32 formats an int32 in upper case hexadecimal.
-func (f *fmt) fmt_X32(v int32) { f.integer(int64(v), 16, signed, udigits) }
+func (f *fmt) fmt_X32(v int32) { f.integer(int64(v), 16, signed, udigits) }
// fmt_X formats an int in upper case hexadecimal.
-func (f *fmt) fmt_X(v int) { f.integer(int64(v), 16, signed, udigits) }
+func (f *fmt) fmt_X(v int) { f.integer(int64(v), 16, signed, udigits) }
// fmt_uX64 formats a uint64 in upper case hexadecimal.
-func (f *fmt) fmt_uX64(v uint64) { f.integer(int64(v), 16, unsigned, udigits) }
+func (f *fmt) fmt_uX64(v uint64) { f.integer(int64(v), 16, unsigned, udigits) }
// fmt_uX32 formats a uint32 in upper case hexadecimal.
-func (f *fmt) fmt_uX32(v uint32) { f.integer(int64(v), 16, unsigned, udigits) }
+func (f *fmt) fmt_uX32(v uint32) { f.integer(int64(v), 16, unsigned, udigits) }
// fmt_uX formats a uint in upper case hexadecimal.
-func (f *fmt) fmt_uX(v uint) { f.integer(int64(v), 16, unsigned, udigits) }
+func (f *fmt) fmt_uX(v uint) { f.integer(int64(v), 16, unsigned, udigits) }
// fmt_o64 formats an int64 in octal.
-func (f *fmt) fmt_o64(v int64) { f.integer(v, 8, signed, ldigits) }
+func (f *fmt) fmt_o64(v int64) { f.integer(v, 8, signed, ldigits) }
// fmt_o32 formats an int32 in octal.
-func (f *fmt) fmt_o32(v int32) { f.integer(int64(v), 8, signed, ldigits) }
+func (f *fmt) fmt_o32(v int32) { f.integer(int64(v), 8, signed, ldigits) }
// fmt_o formats an int in octal.
-func (f *fmt) fmt_o(v int) { f.integer(int64(v), 8, signed, ldigits) }
+func (f *fmt) fmt_o(v int) { f.integer(int64(v), 8, signed, ldigits) }
// fmt_uo64 formats a uint64 in octal.
-func (f *fmt) fmt_uo64(v uint64) { f.integer(int64(v), 8, unsigned, ldigits) }
+func (f *fmt) fmt_uo64(v uint64) { f.integer(int64(v), 8, unsigned, ldigits) }
// fmt_uo32 formats a uint32 in octal.
-func (f *fmt) fmt_uo32(v uint32) { f.integer(int64(v), 8, unsigned, ldigits) }
+func (f *fmt) fmt_uo32(v uint32) { f.integer(int64(v), 8, unsigned, ldigits) }
// fmt_uo formats a uint in octal.
-func (f *fmt) fmt_uo(v uint) { f.integer(int64(v), 8, unsigned, ldigits) }
+func (f *fmt) fmt_uo(v uint) { f.integer(int64(v), 8, unsigned, ldigits) }
// fmt_b64 formats a uint64 in binary.
-func (f *fmt) fmt_b64(v uint64) { f.integer(int64(v), 2, unsigned, ldigits) }
+func (f *fmt) fmt_b64(v uint64) { f.integer(int64(v), 2, unsigned, ldigits) }
// fmt_b32 formats a uint32 in binary.
-func (f *fmt) fmt_b32(v uint32) { f.integer(int64(v), 2, unsigned, ldigits) }
+func (f *fmt) fmt_b32(v uint32) { f.integer(int64(v), 2, unsigned, ldigits) }
// fmt_b formats a uint in binary.
-func (f *fmt) fmt_b(v uint) { f.integer(int64(v), 2, unsigned, ldigits) }
+func (f *fmt) fmt_b(v uint) { f.integer(int64(v), 2, unsigned, ldigits) }
// fmt_c formats a Unicode character.
-func (f *fmt) fmt_c(v int) { f.padString(string(v)) }
+func (f *fmt) fmt_c(v int) { f.padString(string(v)) }
// fmt_s formats a string.
func (f *fmt) fmt_s(s string) {
@@ -319,43 +319,43 @@ func (f *fmt) fmt_s(s string) {
s = s[0:f.prec]
}
}
- f.padString(s);
+ f.padString(s)
}
// fmt_sx formats a string as a hexadecimal encoding of its bytes.
func (f *fmt) fmt_sx(s string) {
- t := "";
+ t := ""
for i := 0; i < len(s); i++ {
if i > 0 && f.space {
t += " "
}
- v := s[i];
- t += string(ldigits[v>>4]);
- t += string(ldigits[v&0xF]);
+ v := s[i]
+ t += string(ldigits[v>>4])
+ t += string(ldigits[v&0xF])
}
- f.padString(t);
+ f.padString(t)
}
// fmt_sX formats a string as an uppercase hexadecimal encoding of its bytes.
func (f *fmt) fmt_sX(s string) {
- t := "";
+ t := ""
for i := 0; i < len(s); i++ {
- v := s[i];
- t += string(udigits[v>>4]);
- t += string(udigits[v&0xF]);
+ v := s[i]
+ t += string(udigits[v>>4])
+ t += string(udigits[v&0xF])
}
- f.padString(t);
+ f.padString(t)
}
// fmt_q formats a string as a double-quoted, escaped Go string constant.
func (f *fmt) fmt_q(s string) {
- var quoted string;
+ var quoted string
if f.sharp && strconv.CanBackquote(s) {
quoted = "`" + s + "`"
} else {
quoted = strconv.Quote(s)
}
- f.padString(quoted);
+ f.padString(quoted)
}
// floating-point
@@ -364,7 +364,7 @@ func doPrec(f *fmt, def int) int {
if f.precPresent {
return f.prec
}
- return def;
+ return def
}
// Add a plus sign or space to the floating-point string representation if missing and required.
@@ -376,48 +376,48 @@ func (f *fmt) plusSpace(s string) {
s = " " + s
}
}
- f.padString(s);
+ f.padString(s)
}
// 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.
-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.
-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.
-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.
-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).
-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
// cannot defer to float64 versions
// because it will get rounding wrong in corner cases.
// 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.
-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.
-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.
-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.
-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).
-func (f *fmt) fmt_fb32(v float32) { f.padString(strconv.Ftoa32(v, 'b', 0)) }
+func (f *fmt) fmt_fb32(v float32) { f.padString(strconv.Ftoa32(v, 'b', 0)) }
// float
func (x *fmt) f(a float) {
diff --git a/src/pkg/fmt/print.go b/src/pkg/fmt/print.go
index 6fa747c29..d4ef3c62f 100644
--- a/src/pkg/fmt/print.go
+++ b/src/pkg/fmt/print.go
@@ -77,25 +77,25 @@ package fmt
import (
- "bytes";
- "io";
- "os";
- "reflect";
- "utf8";
+ "bytes"
+ "io"
+ "os"
+ "reflect"
+ "utf8"
)
// Some constants in the form of bytes, to avoid string overhead.
// Needlessly fastidious, I suppose.
var (
- trueBytes = []byte{'t', 'r', 'u', 'e'};
- falseBytes = []byte{'f', 'a', 'l', 's', 'e'};
- commaSpaceBytes = []byte{',', ' '};
- nilAngleBytes = []byte{'<', 'n', 'i', 'l', '>'};
- nilParenBytes = []byte{'(', 'n', 'i', 'l', ')'};
- nilBytes = []byte{'n', 'i', 'l'};
- mapBytes = []byte{'m', 'a', 'p', '['};
- missingBytes = []byte{'m', 'i', 's', 's', 'i', 'n', 'g'};
- extraBytes = []byte{'?', '(', 'e', 'x', 't', 'r', 'a', ' '};
+ trueBytes = []byte{'t', 'r', 'u', 'e'}
+ falseBytes = []byte{'f', 'a', 'l', 's', 'e'}
+ commaSpaceBytes = []byte{',', ' '}
+ nilAngleBytes = []byte{'<', 'n', 'i', 'l', '>'}
+ nilParenBytes = []byte{'(', 'n', 'i', 'l', ')'}
+ nilBytes = []byte{'n', 'i', 'l'}
+ mapBytes = []byte{'m', 'a', 'p', '['}
+ missingBytes = []byte{'m', 'i', 's', 's', 'i', 'n', 'g'}
+ extraBytes = []byte{'?', '(', 'e', 'x', 't', 'r', 'a', ' '}
)
// State represents the printer state passed to custom formatters.
@@ -103,21 +103,21 @@ var (
// the flags and options for the operand's format specifier.
type State interface {
// Write is the function to call to emit formatted output to be printed.
- Write(b []byte) (ret int, err os.Error);
+ Write(b []byte) (ret int, err os.Error)
// Width returns the value of the width option and whether it has been set.
- Width() (wid int, ok bool);
+ Width() (wid int, ok bool)
// Precision returns the value of the precision option and whether it has been set.
- Precision() (prec int, ok bool);
+ Precision() (prec int, ok bool)
// Flag returns whether the flag c, a character, has been set.
- Flag(int) bool;
+ Flag(int) bool
}
// Formatter is the interface implemented by values with a custom formatter.
// The implementation of Format may call Sprintf or Fprintf(f) etc.
// to generate its output.
type Formatter interface {
- Format(f State, c int);
+ Format(f State, c int)
}
// Stringer is implemented by any value that has a String method(),
@@ -125,7 +125,7 @@ type Formatter interface {
// The String method is used to print values passed as an operand
// to a %s or %v format or to an unformatted printer such as Print.
type Stringer interface {
- String() string;
+ String() string
}
// GoStringer is implemented by any value that has a GoString() method,
@@ -133,16 +133,16 @@ type Stringer interface {
// The GoString method is used to print values passed as an operand
// to a %#v format.
type GoStringer interface {
- GoString() string;
+ GoString() string
}
const allocSize = 32
type pp struct {
- n int;
- buf bytes.Buffer;
- runeBuf [utf8.UTFMax]byte;
- fmt fmt;
+ n int
+ buf bytes.Buffer
+ runeBuf [utf8.UTFMax]byte
+ fmt fmt
}
// A leaky bucket of reusable pp structures.
@@ -150,12 +150,12 @@ var ppFree = make(chan *pp, 100)
// Allocate a new pp struct. Probably can grab the previous one from ppFree.
func newPrinter() *pp {
- p, ok := <-ppFree;
+ p, ok := <-ppFree
if !ok {
p = new(pp)
}
- p.fmt.init(&p.buf);
- return p;
+ p.fmt.init(&p.buf)
+ return p
}
// Save used pp structs in ppFree; avoids an allocation per invocation.
@@ -164,13 +164,13 @@ func (p *pp) free() {
if cap(p.buf.Bytes()) > 1024 {
return
}
- p.buf.Reset();
- _ = ppFree <- p;
+ p.buf.Reset()
+ _ = ppFree <- p
}
-func (p *pp) Width() (wid int, ok bool) { return p.fmt.wid, p.fmt.widPresent }
+func (p *pp) Width() (wid int, ok bool) { return p.fmt.wid, p.fmt.widPresent }
-func (p *pp) Precision() (prec int, ok bool) { return p.fmt.prec, p.fmt.precPresent }
+func (p *pp) Precision() (prec int, ok bool) { return p.fmt.prec, p.fmt.precPresent }
func (p *pp) Flag(b int) bool {
switch b {
@@ -185,15 +185,15 @@ func (p *pp) Flag(b int) bool {
case '0':
return p.fmt.zero
}
- return false;
+ return false
}
func (p *pp) add(c int) {
if c < utf8.RuneSelf {
p.buf.WriteByte(byte(c))
} else {
- w := utf8.EncodeRune(c, &p.runeBuf);
- p.buf.Write(p.runeBuf[0:w]);
+ w := utf8.EncodeRune(c, &p.runeBuf)
+ p.buf.Write(p.runeBuf[0:w])
}
}
@@ -207,28 +207,28 @@ func (p *pp) Write(b []byte) (ret int, err os.Error) {
// Fprintf formats according to a format specifier and writes to w.
func Fprintf(w io.Writer, format string, a ...) (n int, error os.Error) {
- v := reflect.NewValue(a).(*reflect.StructValue);
- p := newPrinter();
- p.doprintf(format, v);
- n64, error := p.buf.WriteTo(w);
- p.free();
- return int(n64), error;
+ v := reflect.NewValue(a).(*reflect.StructValue)
+ p := newPrinter()
+ p.doprintf(format, v)
+ n64, error := p.buf.WriteTo(w)
+ p.free()
+ return int(n64), error
}
// Printf formats according to a format specifier and writes to standard output.
func Printf(format string, v ...) (n int, errno os.Error) {
- n, errno = Fprintf(os.Stdout, format, v);
- return n, errno;
+ n, errno = Fprintf(os.Stdout, format, v)
+ return n, errno
}
// Sprintf formats according to a format specifier and returns the resulting string.
func Sprintf(format string, a ...) string {
- v := reflect.NewValue(a).(*reflect.StructValue);
- p := newPrinter();
- p.doprintf(format, v);
- s := p.buf.String();
- p.free();
- return s;
+ v := reflect.NewValue(a).(*reflect.StructValue)
+ p := newPrinter()
+ p.doprintf(format, v)
+ s := p.buf.String()
+ p.free()
+ return s
}
// These routines do not take a format string
@@ -236,30 +236,30 @@ func Sprintf(format string, a ...) string {
// Fprint formats using the default formats for its operands and writes to w.
// Spaces are added between operands when neither is a string.
func Fprint(w io.Writer, a ...) (n int, error os.Error) {
- v := reflect.NewValue(a).(*reflect.StructValue);
- p := newPrinter();
- p.doprint(v, false, false);
- n64, error := p.buf.WriteTo(w);
- p.free();
- return int(n64), error;
+ v := reflect.NewValue(a).(*reflect.StructValue)
+ p := newPrinter()
+ p.doprint(v, false, false)
+ n64, error := p.buf.WriteTo(w)
+ p.free()
+ return int(n64), error
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
func Print(v ...) (n int, errno os.Error) {
- n, errno = Fprint(os.Stdout, v);
- return n, errno;
+ n, errno = Fprint(os.Stdout, v)
+ return n, errno
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func Sprint(a ...) string {
- v := reflect.NewValue(a).(*reflect.StructValue);
- p := newPrinter();
- p.doprint(v, false, false);
- s := p.buf.String();
- p.free();
- return s;
+ v := reflect.NewValue(a).(*reflect.StructValue)
+ p := newPrinter()
+ p.doprint(v, false, false)
+ s := p.buf.String()
+ p.free()
+ return s
}
// These routines end in 'ln', do not take a format string,
@@ -269,30 +269,30 @@ func Sprint(a ...) string {
// Fprintln formats using the default formats for its operands and writes to w.
// Spaces are always added between operands and a newline is appended.
func Fprintln(w io.Writer, a ...) (n int, error os.Error) {
- v := reflect.NewValue(a).(*reflect.StructValue);
- p := newPrinter();
- p.doprint(v, true, true);
- n64, error := p.buf.WriteTo(w);
- p.free();
- return int(n64), error;
+ v := reflect.NewValue(a).(*reflect.StructValue)
+ p := newPrinter()
+ p.doprint(v, true, true)
+ n64, error := p.buf.WriteTo(w)
+ p.free()
+ return int(n64), error
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
func Println(v ...) (n int, errno os.Error) {
- n, errno = Fprintln(os.Stdout, v);
- return n, errno;
+ n, errno = Fprintln(os.Stdout, v)
+ return n, errno
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func Sprintln(a ...) string {
- v := reflect.NewValue(a).(*reflect.StructValue);
- p := newPrinter();
- p.doprint(v, true, true);
- s := p.buf.String();
- p.free();
- return s;
+ v := reflect.NewValue(a).(*reflect.StructValue)
+ p := newPrinter()
+ p.doprint(v, true, true)
+ s := p.buf.String()
+ p.free()
+ return s
}
@@ -300,13 +300,13 @@ func Sprintln(a ...) string {
// If the arg itself is an interface, return a value for
// the thing inside the interface, not the interface itself.
func getField(v *reflect.StructValue, i int) reflect.Value {
- val := v.Field(i);
+ val := v.Field(i)
if i, ok := val.(*reflect.InterfaceValue); ok {
if inter := i.Interface(); inter != nil {
return reflect.NewValue(inter)
}
}
- return val;
+ return val
}
// Getters for the fields of the argument structure.
@@ -315,7 +315,7 @@ func getBool(v reflect.Value) (val bool, ok bool) {
if b, ok := v.(*reflect.BoolValue); ok {
return b.Get(), true
}
- return;
+ return
}
func getInt(v reflect.Value) (val int64, signed, ok bool) {
@@ -343,7 +343,7 @@ func getInt(v reflect.Value) (val int64, signed, ok bool) {
case *reflect.UintptrValue:
return int64(v.Get()), false, true
}
- return;
+ return
}
func getString(v reflect.Value) (val string, ok bool) {
@@ -353,7 +353,7 @@ func getString(v reflect.Value) (val string, ok bool) {
if bytes, ok := v.Interface().([]byte); ok {
return string(bytes), true
}
- return;
+ return
}
func getFloat32(v reflect.Value) (val float32, ok bool) {
@@ -365,7 +365,7 @@ func getFloat32(v reflect.Value) (val float32, ok bool) {
return float32(v.Get()), true
}
}
- return;
+ return
}
func getFloat64(v reflect.Value) (val float64, ok bool) {
@@ -377,7 +377,7 @@ func getFloat64(v reflect.Value) (val float64, ok bool) {
case *reflect.Float64Value:
return float64(v.Get()), true
}
- return;
+ return
}
func getPtr(v reflect.Value) (val uintptr, ok bool) {
@@ -385,7 +385,7 @@ func getPtr(v reflect.Value) (val uintptr, ok bool) {
case *reflect.PtrValue:
return uintptr(v.Get()), true
}
- return;
+ return
}
// Convert ASCII to integer. n is 0 (and got is false) if no number present.
@@ -394,33 +394,33 @@ func parsenum(s string, start, end int) (n int, got bool, newi int) {
if start >= end {
return 0, false, end
}
- isnum := false;
- num := 0;
+ isnum := false
+ num := 0
for '0' <= s[start] && s[start] <= '9' {
- num = num*10 + int(s[start]-'0');
- start++;
- isnum = true;
+ num = num*10 + int(s[start]-'0')
+ start++
+ isnum = true
}
- return num, isnum, start;
+ return num, isnum, start
}
type uintptrGetter interface {
- Get() uintptr;
+ Get() uintptr
}
func (p *pp) printField(field reflect.Value, plus, sharp bool, depth int) (was_string bool) {
- inter := field.Interface();
+ inter := field.Interface()
if inter != nil {
switch {
default:
if stringer, ok := inter.(Stringer); ok {
- p.buf.WriteString(stringer.String());
- return false; // this value is not a string
+ p.buf.WriteString(stringer.String())
+ return false // this value is not a string
}
case sharp:
if stringer, ok := inter.(GoStringer); ok {
- p.buf.WriteString(stringer.GoString());
- return false; // this value is not a string
+ p.buf.WriteString(stringer.GoString())
+ return false // this value is not a string
}
}
}
@@ -442,17 +442,17 @@ BigSwitch:
if sharp {
p.fmt.fmt_q(f.Get())
} else {
- p.fmt.fmt_s(f.Get());
- was_string = true;
+ p.fmt.fmt_s(f.Get())
+ was_string = true
}
case *reflect.MapValue:
if sharp {
- p.buf.WriteString(field.Type().String());
- p.buf.WriteByte('{');
+ p.buf.WriteString(field.Type().String())
+ p.buf.WriteByte('{')
} else {
p.buf.Write(mapBytes)
}
- keys := f.Keys();
+ keys := f.Keys()
for i, key := range keys {
if i > 0 {
if sharp {
@@ -461,9 +461,9 @@ BigSwitch:
p.buf.WriteByte(' ')
}
}
- p.printField(key, plus, sharp, depth+1);
- p.buf.WriteByte(':');
- p.printField(f.Elem(key), plus, sharp, depth+1);
+ p.printField(key, plus, sharp, depth+1)
+ p.buf.WriteByte(':')
+ p.printField(f.Elem(key), plus, sharp, depth+1)
}
if sharp {
p.buf.WriteByte('}')
@@ -474,10 +474,10 @@ BigSwitch:
if sharp {
p.buf.WriteString(field.Type().String())
}
- p.add('{');
- v := f;
- t := v.Type().(*reflect.StructType);
- p.fmt.clearflags(); // clear flags for p.printField
+ p.add('{')
+ v := f
+ t := v.Type().(*reflect.StructType)
+ p.fmt.clearflags() // clear flags for p.printField
for i := 0; i < v.NumField(); i++ {
if i > 0 {
if sharp {
@@ -488,19 +488,19 @@ BigSwitch:
}
if plus || sharp {
if f := t.Field(i); f.Name != "" {
- p.buf.WriteString(f.Name);
- p.buf.WriteByte(':');
+ p.buf.WriteString(f.Name)
+ p.buf.WriteByte(':')
}
}
- p.printField(getField(v, i), plus, sharp, depth+1);
+ p.printField(getField(v, i), plus, sharp, depth+1)
}
- p.buf.WriteByte('}');
+ p.buf.WriteByte('}')
case *reflect.InterfaceValue:
- value := f.Elem();
+ value := f.Elem()
if value == nil {
if sharp {
- p.buf.WriteString(field.Type().String());
- p.buf.Write(nilParenBytes);
+ p.buf.WriteString(field.Type().String())
+ p.buf.Write(nilParenBytes)
} else {
p.buf.Write(nilAngleBytes)
}
@@ -509,8 +509,8 @@ BigSwitch:
}
case reflect.ArrayOrSliceValue:
if sharp {
- p.buf.WriteString(field.Type().String());
- p.buf.WriteByte('{');
+ p.buf.WriteString(field.Type().String())
+ p.buf.WriteByte('{')
} else {
p.buf.WriteByte('[')
}
@@ -522,7 +522,7 @@ BigSwitch:
p.buf.WriteByte(' ')
}
}
- p.printField(f.Elem(i), plus, sharp, depth+1);
+ p.printField(f.Elem(i), plus, sharp, depth+1)
}
if sharp {
p.buf.WriteByte('}')
@@ -530,99 +530,99 @@ BigSwitch:
p.buf.WriteByte(']')
}
case *reflect.PtrValue:
- v := f.Get();
+ v := f.Get()
// pointer to array or slice or struct? ok at top level
// but not embedded (avoid loops)
if v != 0 && depth == 0 {
switch a := f.Elem().(type) {
case reflect.ArrayOrSliceValue:
- p.buf.WriteByte('&');
- p.printField(a, plus, sharp, depth+1);
- break BigSwitch;
+ p.buf.WriteByte('&')
+ p.printField(a, plus, sharp, depth+1)
+ break BigSwitch
case *reflect.StructValue:
- p.buf.WriteByte('&');
- p.printField(a, plus, sharp, depth+1);
- break BigSwitch;
+ p.buf.WriteByte('&')
+ p.printField(a, plus, sharp, depth+1)
+ break BigSwitch
}
}
if sharp {
- p.buf.WriteByte('(');
- p.buf.WriteString(field.Type().String());
- p.buf.WriteByte(')');
- p.buf.WriteByte('(');
+ p.buf.WriteByte('(')
+ p.buf.WriteString(field.Type().String())
+ p.buf.WriteByte(')')
+ p.buf.WriteByte('(')
if v == 0 {
p.buf.Write(nilBytes)
} else {
- p.fmt.sharp = true;
- p.fmt.fmt_ux64(uint64(v));
+ p.fmt.sharp = true
+ p.fmt.fmt_ux64(uint64(v))
}
- p.buf.WriteByte(')');
- break;
+ p.buf.WriteByte(')')
+ break
}
if v == 0 {
- p.buf.Write(nilAngleBytes);
- break;
+ p.buf.Write(nilAngleBytes)
+ break
}
- p.fmt.sharp = true; // turn 0x on
- p.fmt.fmt_ux64(uint64(v));
+ p.fmt.sharp = true // turn 0x on
+ p.fmt.fmt_ux64(uint64(v))
case uintptrGetter:
- v := f.Get();
+ v := f.Get()
if sharp {
- p.buf.WriteByte('(');
- p.buf.WriteString(field.Type().String());
- p.buf.WriteByte(')');
- p.buf.WriteByte('(');
+ p.buf.WriteByte('(')
+ p.buf.WriteString(field.Type().String())
+ p.buf.WriteByte(')')
+ p.buf.WriteByte('(')
if v == 0 {
p.buf.Write(nilBytes)
} else {
- p.fmt.sharp = true;
- p.fmt.fmt_ux64(uint64(v));
+ p.fmt.sharp = true
+ p.fmt.fmt_ux64(uint64(v))
}
- p.buf.WriteByte(')');
+ p.buf.WriteByte(')')
} else {
- p.fmt.sharp = true; // turn 0x on
- p.fmt.fmt_ux64(uint64(f.Get()));
+ p.fmt.sharp = true // turn 0x on
+ p.fmt.fmt_ux64(uint64(f.Get()))
}
default:
- v, signed, ok := getInt(field);
+ v, signed, ok := getInt(field)
if ok {
if signed {
p.fmt.fmt_d64(v)
} else {
if sharp {
- p.fmt.sharp = true; // turn on 0x
- p.fmt.fmt_ux64(uint64(v));
+ p.fmt.sharp = true // turn on 0x
+ p.fmt.fmt_ux64(uint64(v))
} else {
p.fmt.fmt_ud64(uint64(v))
}
}
- break;
+ break
}
- p.buf.WriteByte('?');
- p.buf.WriteString(field.Type().String());
- p.buf.WriteByte('?');
+ p.buf.WriteByte('?')
+ p.buf.WriteString(field.Type().String())
+ p.buf.WriteByte('?')
}
- return was_string;
+ return was_string
}
func (p *pp) doprintf(format string, v *reflect.StructValue) {
- end := len(format) - 1;
- fieldnum := 0; // we process one field per non-trivial format
+ end := len(format) - 1
+ fieldnum := 0 // we process one field per non-trivial format
for i := 0; i <= end; {
- c, w := utf8.DecodeRuneInString(format[i:]);
+ c, w := utf8.DecodeRuneInString(format[i:])
if c != '%' || i == end {
if w == 1 {
p.buf.WriteByte(byte(c))
} else {
p.buf.WriteString(format[i : i+w])
}
- i += w;
- continue;
+ i += w
+ continue
}
- i++;
+ i++
// flags and widths
- p.fmt.clearflags();
- F: for ; i < end; i++ {
+ p.fmt.clearflags()
+ F: for ; i < end; i++ {
switch format[i] {
case '#':
p.fmt.sharp = true
@@ -639,34 +639,34 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
}
}
// do we have 20 (width)?
- p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end);
+ p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end)
// do we have .20 (precision)?
if i < end && format[i] == '.' {
p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i+1, end)
}
- c, w = utf8.DecodeRuneInString(format[i:]);
- i += w;
+ c, w = utf8.DecodeRuneInString(format[i:])
+ i += w
// percent is special - absorbs no operand
if c == '%' {
- p.buf.WriteByte('%'); // TODO: should we bother with width & prec?
- continue;
+ p.buf.WriteByte('%') // TODO: should we bother with width & prec?
+ continue
}
- if fieldnum >= v.NumField() { // out of operands
- p.buf.WriteByte('%');
- p.add(c);
- p.buf.Write(missingBytes);
- continue;
+ if fieldnum >= v.NumField() { // out of operands
+ p.buf.WriteByte('%')
+ p.add(c)
+ p.buf.Write(missingBytes)
+ continue
}
- field := getField(v, fieldnum);
- fieldnum++;
+ field := getField(v, fieldnum)
+ fieldnum++
// Try formatter except for %T,
// which is special and handled internally.
- inter := field.Interface();
+ inter := field.Interface()
if inter != nil && c != 'T' {
if formatter, ok := inter.(Formatter); ok {
- formatter.Format(p, c);
- continue;
+ formatter.Format(p, c)
+ continue
}
}
@@ -686,7 +686,7 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// int
case 'b':
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 {
p.fmt.fmt_fb32(v)
} else if v, ok := getFloat64(field); ok {
@@ -792,8 +792,8 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
if inter != nil {
// if object implements String, use the result.
if stringer, ok := inter.(Stringer); ok {
- p.fmt.fmt_s(stringer.String());
- break;
+ p.fmt.fmt_s(stringer.String())
+ break
}
}
if v, ok := getString(field); ok {
@@ -814,8 +814,8 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
if v == 0 {
p.buf.Write(nilAngleBytes)
} else {
- p.fmt.fmt_s("0x");
- p.fmt.fmt_uX64(uint64(v));
+ p.fmt.fmt_s("0x")
+ p.fmt.fmt_uX64(uint64(v))
}
} else {
goto badtype
@@ -823,10 +823,10 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// arbitrary value; do your best
case 'v':
- plus, sharp := p.fmt.plus, p.fmt.sharp;
- p.fmt.plus = false;
- p.fmt.sharp = false;
- p.printField(field, plus, sharp, 0);
+ plus, sharp := p.fmt.plus, p.fmt.sharp
+ p.fmt.plus = false
+ p.fmt.sharp = false
+ p.printField(field, plus, sharp, 0)
// the value's type
case 'T':
@@ -834,42 +834,42 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
default:
badtype:
- p.buf.WriteByte('%');
- p.add(c);
- p.buf.WriteByte('(');
- p.buf.WriteString(field.Type().String());
- p.buf.WriteByte('=');
- p.printField(field, false, false, 0);
- p.buf.WriteByte(')');
+ p.buf.WriteByte('%')
+ p.add(c)
+ p.buf.WriteByte('(')
+ p.buf.WriteString(field.Type().String())
+ p.buf.WriteByte('=')
+ p.printField(field, false, false, 0)
+ p.buf.WriteByte(')')
}
}
if fieldnum < v.NumField() {
- p.buf.Write(extraBytes);
+ p.buf.Write(extraBytes)
for ; fieldnum < v.NumField(); fieldnum++ {
- field := getField(v, fieldnum);
- p.buf.WriteString(field.Type().String());
- p.buf.WriteByte('=');
- p.printField(field, false, false, 0);
+ field := getField(v, fieldnum)
+ p.buf.WriteString(field.Type().String())
+ p.buf.WriteByte('=')
+ p.printField(field, false, false, 0)
if fieldnum+1 < v.NumField() {
p.buf.Write(commaSpaceBytes)
}
}
- p.buf.WriteByte(')');
+ p.buf.WriteByte(')')
}
}
func (p *pp) doprint(v *reflect.StructValue, addspace, addnewline bool) {
- prev_string := false;
+ prev_string := false
for fieldnum := 0; fieldnum < v.NumField(); fieldnum++ {
// always add spaces if we're doing println
- field := getField(v, fieldnum);
+ field := getField(v, fieldnum)
if fieldnum > 0 {
- _, is_string := field.(*reflect.StringValue);
+ _, is_string := field.(*reflect.StringValue)
if addspace || !is_string && !prev_string {
p.buf.WriteByte(' ')
}
}
- prev_string = p.printField(field, false, false, 0);
+ prev_string = p.printField(field, false, false, 0)
}
if addnewline {
p.buf.WriteByte('\n')