Commit ecb863a9 authored by Russ Cox's avatar Russ Cox

apply gofmt to datafmt, ebnf, exec, expvar, flag, fmt

R=gri
DELTA=456  (6 added, 3 deleted, 447 changed)
OCL=35398
CL=35406
parent 2c2e2c5d
......@@ -23,8 +23,8 @@ type parser struct {
tok token.Token; // one token look-ahead
lit []byte; // token literal
packs map [string] string; // PackageName -> ImportPath
rules map [string] expr; // RuleName -> Expression
packs map[string]string; // PackageName -> ImportPath
rules map[string]expr; // RuleName -> Expression
}
......@@ -43,8 +43,8 @@ func (p *parser) init(filename string, src []byte) {
p.ErrorVector.Init();
p.scanner.Init(filename, src, p, scanner.AllowIllegalChars); // return '@' as token.ILLEGAL w/o error message
p.next(); // initializes pos, tok, lit
p.packs = make(map [string] string);
p.rules = make(map [string] expr);
p.packs = make(map[string]string);
p.rules = make(map[string]expr);
}
......@@ -151,7 +151,7 @@ func (p *parser) parseLiteral() literal {
// the next segment starts with a % format
if i0 < i {
// the current segment is not empty, split it off
list.Push(s[i0 : i]);
list.Push(s[i0:i]);
i0 = i;
}
i++; // skip %; let loop skip over char after %
......@@ -159,7 +159,7 @@ func (p *parser) parseLiteral() literal {
}
// the final segment may start with any character
// (it is empty iff the string is empty)
list.Push(s[i0 : len(s)]);
list.Push(s[i0:len(s)]);
// convert list into a literal
lit := make(literal, list.Len());
......@@ -248,8 +248,10 @@ func (p *parser) parseSequence() expr {
// no need for a sequence if list.Len() < 2
switch list.Len() {
case 0: return nil;
case 1: return list.At(0).(expr);
case 0:
return nil;
case 1:
return list.At(0).(expr);
}
// convert list into a sequence
......@@ -278,8 +280,10 @@ func (p *parser) parseExpression() expr {
// no need for an alternatives if list.Len() < 2
switch list.Len() {
case 0: return nil;
case 1: return list.At(0).(expr);
case 0:
return nil;
case 1:
return list.At(0).(expr);
}
// convert list into a alternatives
......@@ -340,10 +344,10 @@ func (p *parser) parseFormat() {
func remap(p *parser, name string) string {
i := strings.Index(name, ".");
if i >= 0 {
packageName, suffix := name[0 : i], name[i : len(name)];
packageName, suffix := name[0:i], name[i:len(name)];
// lookup package
if importPath, found := p.packs[packageName]; found {
name = importPath + suffix;
name = importPath+suffix;
} else {
var invalidPos token.Position;
p.Error(invalidPos, "package not declared: " + packageName);
......
......@@ -78,8 +78,7 @@ func modeToFiles(mode, fd int) (*os.File, *os.File, os.Error) {
// If a parameter is Pipe, then the corresponding field (Stdin, Stdout, Stderr)
// of the returned Cmd is the other end of the pipe.
// Otherwise the field in Cmd is nil.
func Run(argv0 string, argv, envv []string, stdin, stdout, stderr int) (p *Cmd, err os.Error)
{
func Run(argv0 string, argv, envv []string, stdin, stdout, stderr int) (p *Cmd, err os.Error) {
p = new(Cmd);
var fd [3]*os.File;
......@@ -184,7 +183,7 @@ func (p *Cmd) Close() os.Error {
return err;
}
func canExec(file string) bool{
func canExec(file string) bool {
d, err := os.Stat(file);
if err != nil {
return false;
......@@ -220,4 +219,3 @@ func LookPath(file string) (string, os.Error) {
}
return "", os.ENOENT;
}
......@@ -28,7 +28,7 @@ type Int struct {
}
func (v *Int) String() string {
return strconv.Itoa64(v.i)
return strconv.Itoa64(v.i);
}
func (v *Int) Add(delta int64) {
......@@ -39,7 +39,7 @@ func (v *Int) Add(delta int64) {
// Map is a string-to-Var map variable, and satisfies the Var interface.
type Map struct {
m map[string] Var;
m map[string]Var;
mu sync.Mutex;
}
......@@ -63,21 +63,21 @@ func (v *Map) String() string {
first = false;
}
fmt.Fprintf(b, "}");
return b.String()
return b.String();
}
func (v *Map) Init() *Map {
v.m = make(map[string] Var);
return v
v.m = make(map[string]Var);
return v;
}
func (v *Map) Get(key string) Var {
v.mu.Lock();
defer v.mu.Unlock();
if av, ok := v.m[key]; ok {
return av
return av;
}
return nil
return nil;
}
func (v *Map) Set(key string, av Var) {
......@@ -104,7 +104,7 @@ func (v *Map) Add(key string, delta int64) {
// TODO(rsc): Make sure map access in separate thread is safe.
func (v *Map) iterate(c chan<- KeyValue) {
for k, v := range v.m {
c <- KeyValue{ k, v };
c <- KeyValue{k, v};
}
close(c);
}
......@@ -112,7 +112,7 @@ func (v *Map) iterate(c chan<- KeyValue) {
func (v *Map) Iter() <-chan KeyValue {
c := make(chan KeyValue);
go v.iterate(c);
return c
return c;
}
// String is a string variable, and satisfies the Var interface.
......@@ -121,7 +121,7 @@ type String struct {
}
func (v *String) String() string {
return strconv.Quote(v.s)
return strconv.Quote(v.s);
}
func (v *String) Set(value string) {
......@@ -130,16 +130,16 @@ func (v *String) Set(value string) {
// IntFunc wraps a func() int64 to create a value that satisfies the Var interface.
// The function will be called each time the Var is evaluated.
type IntFunc func() int64;
type IntFunc func() int64
func (v IntFunc) String() string {
return strconv.Itoa64(v())
return strconv.Itoa64(v());
}
// All published variables.
var vars map[string] Var = make(map[string] Var);
var mutex sync.Mutex;
var vars map[string]Var = make(map[string]Var)
var mutex sync.Mutex
// Publish declares an named exported variable. This should be called from a
// package's init function when it creates its Vars. If the name is already
......@@ -156,9 +156,9 @@ func Publish(name string, v Var) {
// Get retrieves a named exported variable.
func Get(name string) Var {
if v, ok := vars[name]; ok {
return v
return v;
}
return nil
return nil;
}
// RemoveAll removes all exported variables.
......@@ -166,7 +166,7 @@ func Get(name string) Var {
func RemoveAll() {
mutex.Lock();
defer mutex.Unlock();
vars = make(map[string] Var);
vars = make(map[string]Var);
}
// Convenience functions for creating new exported variables.
......@@ -174,25 +174,25 @@ func RemoveAll() {
func NewInt(name string) *Int {
v := new(Int);
Publish(name, v);
return v
return v;
}
func NewMap(name string) *Map {
v := new(Map).Init();
Publish(name, v);
return v
return v;
}
func NewString(name string) *String {
v := new(String);
Publish(name, v);
return v
return v;
}
// TODO(rsc): Make sure map access in separate thread is safe.
func iterate(c chan<- KeyValue) {
for k, v := range vars {
c <- KeyValue{ k, v };
c <- KeyValue{k, v};
}
close(c);
}
......@@ -200,7 +200,7 @@ func iterate(c chan<- KeyValue) {
func Iter() <-chan KeyValue {
c := make(chan KeyValue);
go iterate(c);
return c
return c;
}
func expvarHandler(c *http.Conn, req *http.Request) {
......
......@@ -45,7 +45,7 @@ package flag
import (
"fmt";
"os";
"strconv"
"strconv";
)
// TODO(r): BUG: atob belongs elsewhere
......@@ -54,9 +54,9 @@ func atob(str string) (value bool, ok bool) {
case "1", "t", "T", "true", "TRUE", "True":
return true, true;
case "0", "f", "F", "false", "FALSE", "False":
return false, true
return false, true;
}
return false, false
return false, false;
}
// -- Bool Value
......@@ -66,17 +66,17 @@ type boolValue struct {
func newBoolValue(val bool, p *bool) *boolValue {
*p = val;
return &boolValue{p}
return &boolValue{p};
}
func (b *boolValue) set(s string) bool {
v, ok := atob(s);
*b.p = v;
return ok
return ok;
}
func (b *boolValue) String() string {
return fmt.Sprintf("%v", *b.p)
return fmt.Sprintf("%v", *b.p);
}
// -- Int Value
......@@ -86,17 +86,17 @@ type intValue struct {
func newIntValue(val int, p *int) *intValue {
*p = val;
return &intValue{p}
return &intValue{p};
}
func (i *intValue) set(s string) bool {
v, err := strconv.Atoi(s);
*i.p = int(v);
return err == nil
return err == nil;
}
func (i *intValue) String() string {
return fmt.Sprintf("%v", *i.p)
return fmt.Sprintf("%v", *i.p);
}
// -- Int64 Value
......@@ -106,7 +106,7 @@ type int64Value struct {
func newInt64Value(val int64, p *int64) *int64Value {
*p = val;
return &int64Value{p}
return &int64Value{p};
}
func (i *int64Value) set(s string) bool {
......@@ -116,7 +116,7 @@ func (i *int64Value) set(s string) bool {
}
func (i *int64Value) String() string {
return fmt.Sprintf("%v", *i.p)
return fmt.Sprintf("%v", *i.p);
}
// -- Uint Value
......@@ -126,7 +126,7 @@ type uintValue struct {
func newUintValue(val uint, p *uint) *uintValue {
*p = val;
return &uintValue{p}
return &uintValue{p};
}
func (i *uintValue) set(s string) bool {
......@@ -136,7 +136,7 @@ func (i *uintValue) set(s string) bool {
}
func (i *uintValue) String() string {
return fmt.Sprintf("%v", *i.p)
return fmt.Sprintf("%v", *i.p);
}
// -- uint64 Value
......@@ -146,7 +146,7 @@ type uint64Value struct {
func newUint64Value(val uint64, p *uint64) *uint64Value {
*p = val;
return &uint64Value{p}
return &uint64Value{p};
}
func (i *uint64Value) set(s string) bool {
......@@ -156,7 +156,7 @@ func (i *uint64Value) set(s string) bool {
}
func (i *uint64Value) String() string {
return fmt.Sprintf("%v", *i.p)
return fmt.Sprintf("%v", *i.p);
}
// -- string Value
......@@ -166,7 +166,7 @@ type stringValue struct {
func newStringValue(val string, p *string) *stringValue {
*p = val;
return &stringValue{p}
return &stringValue{p};
}
func (s *stringValue) set(val string) bool {
......@@ -175,7 +175,7 @@ func (s *stringValue) set(val string) bool {
}
func (s *stringValue) String() string {
return fmt.Sprintf("%s", *s.p)
return fmt.Sprintf("%s", *s.p);
}
// FlagValue is the interface to the dynamic value stored in a flag.
......@@ -194,24 +194,24 @@ type Flag struct {
}
type allFlags struct {
actual map[string] *Flag;
formal map[string] *Flag;
actual map[string]*Flag;
formal map[string]*Flag;
first_arg int; // 0 is the program name, 1 is first arg
}
var flags *allFlags = &allFlags{make(map[string] *Flag), make(map[string] *Flag), 1}
var flags *allFlags = &allFlags{make(map[string]*Flag), make(map[string]*Flag), 1}
// VisitAll visits the flags, calling fn for each. It visits all flags, even those not set.
func VisitAll(fn func(*Flag)) {
for _, f := range flags.formal {
fn(f)
fn(f);
}
}
// Visit visits the flags, calling fn for each. It visits only those flags that have been set.
func Visit(fn func(*Flag)) {
for _, f := range flags.actual {
fn(f)
fn(f);
}
}
......@@ -219,9 +219,9 @@ func Visit(fn func(*Flag)) {
func Lookup(name string) *Flag {
f, ok := flags.formal[name];
if !ok {
return nil
return nil;
}
return f
return f;
}
// Set sets the value of the named flag. It returns true if the set succeeded; false if
......@@ -229,11 +229,11 @@ func Lookup(name string) *Flag {
func Set(name, value string) bool {
f, ok := flags.formal[name];
if !ok {
return false
return false;
}
ok = f.Value.set(value);
if !ok {
return false
return false;
}
flags.actual[name] = f;
return true;
......@@ -248,7 +248,7 @@ func PrintDefaults() {
format = " -%s=%q: %s\n";
}
fmt.Fprintf(os.Stderr, format, f.Name, f.DefValue, f.Usage);
})
});
}
// Usage prints to standard error a default usage message documenting all defined flags.
......@@ -259,7 +259,7 @@ var Usage = func() {
}
func NFlag() int {
return len(flags.actual)
return len(flags.actual);
}
// Arg returns the i'th command-line argument. Arg(0) is the first remaining argument
......@@ -269,17 +269,17 @@ func Arg(i int) string {
if i < 0 || i >= len(os.Args) {
return "";
}
return os.Args[i]
return os.Args[i];
}
// NArg is the number of arguments remaining after flags have been processed.
func NArg() int {
return len(os.Args) - flags.first_arg
return len(os.Args) - flags.first_arg;
}
// Args returns the non-flag command-line arguments.
func Args() []string {
return os.Args[flags.first_arg:len(os.Args)];
return os.Args[flags.first_arg : len(os.Args)];
}
func add(name string, value FlagValue, usage string) {
......@@ -377,27 +377,26 @@ func String(name, value string, usage string) *string {
return p;
}
func (f *allFlags) parseOne(index int) (ok bool, next int)
{
func (f *allFlags) parseOne(index int) (ok bool, next int) {
s := os.Args[index];
f.first_arg = index; // until proven otherwise
if len(s) == 0 {
return false, -1
return false, -1;
}
if s[0] != '-' {
return false, -1
return false, -1;
}
num_minuses := 1;
if len(s) == 1 {
return false, index
return false, index;
}
if s[1] == '-' {
num_minuses++;
if len(s) == 2 { // "--" terminates the flags
return false, index + 1
return false, index+1;
}
}
name := s[num_minuses : len(s)];
name := s[num_minuses:len(s)];
if len(name) == 0 || name[0] == '-' || name[0] == '=' {
fmt.Fprintln(os.Stderr, "bad flag syntax:", s);
Usage();
......@@ -411,7 +410,7 @@ func (f *allFlags) parseOne(index int) (ok bool, next int)
if name[i] == '=' {
value = name[i+1 : len(name)];
has_value = true;
name = name[0 : i];
name = name[0:i];
break;
}
}
......@@ -436,11 +435,11 @@ func (f *allFlags) parseOne(index int) (ok bool, next int)
os.Exit(2);
}
} else {
f.set("true")
f.set("true");
}
} else {
// It must have a value, which might be the next argument.
if !has_value && index < len(os.Args)-1 {
if !has_value && index < len(os.Args) - 1 {
// value is the next arg
has_value = true;
index++;
......@@ -459,7 +458,7 @@ func (f *allFlags) parseOne(index int) (ok bool, next int)
}
}
flags.actual[name] = flag;
return true, index + 1
return true, index+1;
}
// Parse parses the command-line flags. Must be called after all flags are defined
......@@ -472,7 +471,7 @@ func Parse() {
i = next;
}
if !ok {
break
break;
}
}
}
......@@ -20,13 +20,13 @@ var (
func boolString(s string) string {
if s == "0" {
return "false"
return "false";
}
return "true"
return "true";
}
func TestEverything(t *testing.T) {
m := make(map[string] *Flag);
m := make(map[string]*Flag);
desired := "0";
visitor := func(f *Flag) {
if len(f.Name) > 5 && f.Name[0:5] == "test_" {
......@@ -47,15 +47,15 @@ func TestEverything(t *testing.T) {
if len(m) != 6 {
t.Error("VisitAll misses some flags");
for k, v := range m {
t.Log(k, *v)
t.Log(k, *v);
}
}
m = make(map[string] *Flag);
m = make(map[string]*Flag);
Visit(visitor);
if len(m) != 0 {
t.Errorf("Visit sees unset flags");
for k, v := range m {
t.Log(k, *v)
t.Log(k, *v);
}
}
// Now set all flags
......@@ -70,7 +70,7 @@ func TestEverything(t *testing.T) {
if len(m) != 6 {
t.Error("Visit fails after set");
for k, v := range m {
t.Log(k, *v)
t.Log(k, *v);
}
}
}
This diff is collapsed.
......@@ -9,8 +9,8 @@ import (
)
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"
......@@ -140,9 +140,9 @@ func (f *Fmt) pad(s string) {
buf[i] = padchar;
}
if left {
s = string(buf) + s;
s = string(buf)+s;
} else {
s = s + string(buf);
s = s+string(buf);
}
}
}
......@@ -155,7 +155,7 @@ func (f *Fmt) pad(s string) {
// 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 []byte, base, val uint64, digits string) int {
i := len(buf) - 1;
i := len(buf)-1;
for val >= base {
buf[i] = digits[val%base];
i--;
......@@ -190,7 +190,7 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) string
if f.prec_present {
prec = f.prec;
f.zero = false;
} else if f.zero && f.wid_present && !f.minus && f.wid > 0{
} else if f.zero && f.wid_present && !f.minus && f.wid > 0 {
prec = f.wid;
if negative || f.plus || f.space {
prec--; // leave room for sign
......@@ -211,7 +211,7 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits string) string
i--;
}
case 16:
buf[i] = 'x' + digits[10]-'a';
buf[i] = 'x'+digits[10]-'a';
i--;
buf[i] = '0';
i--;
......@@ -228,7 +228,7 @@ 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]);
}
// Fmt_d64 formats an int64 in decimal.
......@@ -395,7 +395,7 @@ func (f *Fmt) Fmt_c(v int) *Fmt {
func (f *Fmt) Fmt_s(s string) *Fmt {
if f.prec_present {
if f.prec < len(s) {
s = s[0:f.prec];
s = s[0 : f.prec];
}
}
f.pad(s);
......@@ -527,28 +527,28 @@ func (f *Fmt) Fmt_fb32(v float32) *Fmt {
// float
func (x *Fmt) f(a float) *Fmt {
if strconv.FloatSize == 32 {
return x.Fmt_f32(float32(a))
return x.Fmt_f32(float32(a));
}
return x.Fmt_f64(float64(a))
return x.Fmt_f64(float64(a));
}
func (x *Fmt) e(a float) *Fmt {
if strconv.FloatSize == 32 {
return x.Fmt_e32(float32(a))
return x.Fmt_e32(float32(a));
}
return x.Fmt_e64(float64(a))
return x.Fmt_e64(float64(a));
}
func (x *Fmt) g(a float) *Fmt {
if strconv.FloatSize == 32 {
return x.Fmt_g32(float32(a))
return x.Fmt_g32(float32(a));
}
return x.Fmt_g64(float64(a))
return x.Fmt_g64(float64(a));
}
func (x *Fmt) fb(a float) *Fmt {
if strconv.FloatSize == 32 {
return x.Fmt_fb32(float32(a))
return x.Fmt_fb32(float32(a));
}
return x.Fmt_fb64(float64(a))
return x.Fmt_fb64(float64(a));
}
......@@ -110,7 +110,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,
......@@ -118,7 +118,7 @@ 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 runeSelf = utf8.RuneSelf
......@@ -137,11 +137,11 @@ func newPrinter() *pp {
}
func (p *pp) Width() (wid int, ok bool) {
return p.fmt.wid, p.fmt.wid_present
return p.fmt.wid, p.fmt.wid_present;
}
func (p *pp) Precision() (prec int, ok bool) {
return p.fmt.prec, p.fmt.prec_present
return p.fmt.prec, p.fmt.prec_present;
}
func (p *pp) Flag(b int) bool {
......@@ -157,14 +157,14 @@ func (p *pp) Flag(b int) bool {
case '0':
return p.fmt.zero;
}
return false
return false;
}
func (p *pp) ensure(n int) {
if len(p.buf) < n {
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++ {
......@@ -184,7 +184,7 @@ func (p *pp) addstr(s string) {
}
func (p *pp) addbytes(b []byte, start, end int) {
p.ensure(p.n + end-start);
p.ensure(p.n + end - start);
for i := start; i < end; i++ {
p.buf[p.n] = b[i];
p.n++;
......@@ -215,7 +215,7 @@ 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);
n, error = w.Write(p.buf[0:p.n]);
n, error = w.Write(p.buf[0 : p.n]);
return n, error;
}
......@@ -242,7 +242,7 @@ func Fprint(w io.Writer, a ...) (n int, error os.Error) {
v := reflect.NewValue(a).(*reflect.StructValue);
p := newPrinter();
p.doprint(v, false, false);
n, error = w.Write(p.buf[0:p.n]);
n, error = w.Write(p.buf[0 : p.n]);
return n, error;
}
......@@ -273,7 +273,7 @@ func Fprintln(w io.Writer, a ...) (n int, error os.Error) {
v := reflect.NewValue(a).(*reflect.StructValue);
p := newPrinter();
p.doprint(v, true, true);
n, error = w.Write(p.buf[0:p.n]);
n, error = w.Write(p.buf[0 : p.n]);
return n, error;
}
......@@ -360,7 +360,7 @@ func getFloat32(v reflect.Value) (val float32, ok bool) {
case *reflect.Float32Value:
return float32(v.Get()), true;
case *reflect.FloatValue:
if v.Type().Size()*8 == 32 {
if v.Type().Size() * 8 == 32 {
return float32(v.Get()), true;
}
}
......@@ -370,7 +370,7 @@ func getFloat32(v reflect.Value) (val float32, ok bool) {
func getFloat64(v reflect.Value) (val float64, ok bool) {
switch v := v.(type) {
case *reflect.FloatValue:
if v.Type().Size()*8 == 64 {
if v.Type().Size() * 8 == 64 {
return float64(v.Get()), true;
}
case *reflect.Float64Value:
......@@ -391,12 +391,12 @@ func getPtr(v reflect.Value) (val uintptr, ok bool) {
func parsenum(s string, start, end int) (n int, got bool, newi int) {
if start >= end {
return 0, false, end
return 0, false, end;
}
isnum := false;
num := 0;
for '0' <= s[start] && s[start] <= '9' {
num = num*10 + int(s[start] - '0');
num = num*10 + int(s[start]-'0');
start++;
isnum = true;
}
......@@ -433,7 +433,7 @@ BigSwitch:
case *reflect.Float64Value:
s = p.fmt.Fmt_g64(f.Get()).Str();
case *reflect.FloatValue:
if field.Type().Size()*8 == 32 {
if field.Type().Size() * 8 == 32 {
s = p.fmt.Fmt_g32(float32(f.Get())).Str();
} else {
s = p.fmt.Fmt_g64(float64(f.Get())).Str();
......@@ -502,7 +502,7 @@ BigSwitch:
p.addstr(field.Type().String());
p.addstr("(nil)");
} else {
s = "<nil>"
s = "<nil>";
}
} else {
return p.printField(value, plus, sharp, depth+1);
......@@ -604,7 +604,7 @@ BigSwitch:
func (p *pp) doprintf(format string, v *reflect.StructValue) {
p.ensure(len(format)); // a good starting size
end := len(format) - 1;
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:len(format)]);
......@@ -681,105 +681,105 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// int
case 'b':
if v, _, ok := getInt(field); ok {
s = p.fmt.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.Fmt_fb32(v).Str()
s = p.fmt.Fmt_fb32(v).Str();
} else if v, ok := getFloat64(field); ok {
s = p.fmt.Fmt_fb64(v).Str()
s = p.fmt.Fmt_fb64(v).Str();
} else {
goto badtype
goto badtype;
}
case 'c':
if v, _, ok := getInt(field); ok {
s = p.fmt.Fmt_c(int(v)).Str()
s = p.fmt.Fmt_c(int(v)).Str();
} else {
goto badtype
goto badtype;
}
case 'd':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.Fmt_d64(v).Str()
s = p.fmt.Fmt_d64(v).Str();
} else {
s = p.fmt.Fmt_ud64(uint64(v)).Str()
s = p.fmt.Fmt_ud64(uint64(v)).Str();
}
} else {
goto badtype
goto badtype;
}
case 'o':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.Fmt_o64(v).Str()
s = p.fmt.Fmt_o64(v).Str();
} else {
s = p.fmt.Fmt_uo64(uint64(v)).Str()
s = p.fmt.Fmt_uo64(uint64(v)).Str();
}
} else {
goto badtype
goto badtype;
}
case 'x':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.Fmt_x64(v).Str()
s = p.fmt.Fmt_x64(v).Str();
} else {
s = p.fmt.Fmt_ux64(uint64(v)).Str()
s = p.fmt.Fmt_ux64(uint64(v)).Str();
}
} else if v, ok := getString(field); ok {
s = p.fmt.Fmt_sx(v).Str();
} else {
goto badtype
goto badtype;
}
case 'X':
if v, signed, ok := getInt(field); ok {
if signed {
s = p.fmt.Fmt_X64(v).Str()
s = p.fmt.Fmt_X64(v).Str();
} else {
s = p.fmt.Fmt_uX64(uint64(v)).Str()
s = p.fmt.Fmt_uX64(uint64(v)).Str();
}
} else if v, ok := getString(field); ok {
s = p.fmt.Fmt_sX(v).Str();
} else {
goto badtype
goto badtype;
}
// float
case 'e':
if v, ok := getFloat32(field); ok {
s = p.fmt.Fmt_e32(v).Str()
s = p.fmt.Fmt_e32(v).Str();
} else if v, ok := getFloat64(field); ok {
s = p.fmt.Fmt_e64(v).Str()
s = p.fmt.Fmt_e64(v).Str();
} else {
goto badtype
goto badtype;
}
case 'E':
if v, ok := getFloat32(field); ok {
s = p.fmt.Fmt_E32(v).Str()
s = p.fmt.Fmt_E32(v).Str();
} else if v, ok := getFloat64(field); ok {
s = p.fmt.Fmt_E64(v).Str()
s = p.fmt.Fmt_E64(v).Str();
} else {
goto badtype
goto badtype;
}
case 'f':
if v, ok := getFloat32(field); ok {
s = p.fmt.Fmt_f32(v).Str()
s = p.fmt.Fmt_f32(v).Str();
} else if v, ok := getFloat64(field); ok {
s = p.fmt.Fmt_f64(v).Str()
s = p.fmt.Fmt_f64(v).Str();
} else {
goto badtype
goto badtype;
}
case 'g':
if v, ok := getFloat32(field); ok {
s = p.fmt.Fmt_g32(v).Str()
s = p.fmt.Fmt_g32(v).Str();
} else if v, ok := getFloat64(field); ok {
s = p.fmt.Fmt_g64(v).Str()
s = p.fmt.Fmt_g64(v).Str();
} else {
goto badtype
goto badtype;
}
case 'G':
if v, ok := getFloat32(field); ok {
s = p.fmt.Fmt_G32(v).Str()
s = p.fmt.Fmt_G32(v).Str();
} else if v, ok := getFloat64(field); ok {
s = p.fmt.Fmt_G64(v).Str()
s = p.fmt.Fmt_G64(v).Str();
} else {
goto badtype
goto badtype;
}
// string
......@@ -792,27 +792,27 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
}
}
if v, ok := getString(field); ok {
s = p.fmt.Fmt_s(v).Str()
s = p.fmt.Fmt_s(v).Str();
} else {
goto badtype
goto badtype;
}
case 'q':
if v, ok := getString(field); ok {
s = p.fmt.Fmt_q(v).Str()
s = p.fmt.Fmt_q(v).Str();
} else {
goto badtype
goto badtype;
}
// pointer
case 'p':
if v, ok := getPtr(field); ok {
if v == 0 {
s = "<nil>"
s = "<nil>";
} else {
s = "0x" + p.fmt.Fmt_uX64(uint64(v)).Str()
s = "0x" + p.fmt.Fmt_uX64(uint64(v)).Str();
}
} else {
goto badtype
goto badtype;
}
// arbitrary value; do your best
......@@ -842,7 +842,7 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
p.addstr(field.Type().String());
p.addstr("=");
p.printField(field, false, false, 0);
if fieldnum + 1 < v.NumField() {
if fieldnum+1 < v.NumField() {
p.addstr(", ");
}
}
......@@ -864,6 +864,6 @@ func (p *pp) doprint(v *reflect.StructValue, addspace, addnewline bool) {
prev_string = p.printField(field, false, false, 0);
}
if addnewline {
p.add('\n')
p.add('\n');
}
}
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