diff options
author | Robert Griesemer <gri@golang.org> | 2009-11-09 12:07:39 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-11-09 12:07:39 -0800 |
commit | e940edc7a026293153ba09ece40e8092a2fc2463 (patch) | |
tree | c94a425c84b7a48f91a5d76a222effad70c9a88c /src/pkg/json | |
parent | e067f862f1774ab89a2096a88571a94e3b9cd353 (diff) | |
download | golang-e940edc7a026293153ba09ece40e8092a2fc2463.tar.gz |
remove semis after statements in one-statement statement lists
R=rsc, r
http://go/go-review/1025029
Diffstat (limited to 'src/pkg/json')
-rw-r--r-- | src/pkg/json/generic.go | 64 | ||||
-rw-r--r-- | src/pkg/json/generic_test.go | 12 | ||||
-rw-r--r-- | src/pkg/json/parse.go | 48 | ||||
-rw-r--r-- | src/pkg/json/struct.go | 86 | ||||
-rw-r--r-- | src/pkg/json/struct_test.go | 8 |
5 files changed, 109 insertions, 109 deletions
diff --git a/src/pkg/json/generic.go b/src/pkg/json/generic.go index a8ee83664..fb97edc19 100644 --- a/src/pkg/json/generic.go +++ b/src/pkg/json/generic.go @@ -43,10 +43,10 @@ type Json interface { // j.String() == `abc`, but JsonToString(j) == `"abc"`. func JsonToString(j Json) string { if j == nil { - return "null"; + return "null" } if j.Kind() == StringKind { - return Quote(j.String()); + return Quote(j.String()) } return j.String(); } @@ -81,7 +81,7 @@ func (j *_Number) Kind() int { return NumberKind } func (j *_Number) Number() float64 { return j.f } func (j *_Number) String() string { if math.Floor(j.f) == j.f { - return fmt.Sprintf("%.0f", j.f); + return fmt.Sprintf("%.0f", j.f) } return fmt.Sprintf("%g", j.f); } @@ -95,7 +95,7 @@ func (j *_Array) Kind() int { return ArrayKind } func (j *_Array) Len() int { return j.a.Len() } func (j *_Array) Elem(i int) Json { if i < 0 || i >= j.a.Len() { - return Null; + return Null } return j.a.At(i).(Json); } @@ -103,7 +103,7 @@ func (j *_Array) String() string { s := "["; for i := 0; i < j.a.Len(); i++ { if i > 0 { - s += ","; + s += "," } s += JsonToString(j.a.At(i).(Json)); } @@ -120,7 +120,7 @@ func (j *_Bool) Kind() int { return BoolKind } func (j *_Bool) Bool() bool { return j.b } func (j *_Bool) String() string { if j.b { - return "true"; + return "true" } return "false"; } @@ -134,11 +134,11 @@ func (j *_Map) Kind() int { return MapKind } func (j *_Map) Len() int { return len(j.m) } func (j *_Map) Get(s string) Json { if j.m == nil { - return Null; + return Null } v, ok := j.m[s]; if !ok { - return Null; + return Null } return v; } @@ -147,9 +147,9 @@ func (j *_Map) String() string { first := true; for k, v := range j.m { if first { - first = false; + first = false } else { - s += ","; + s += "," } s += Quote(k); s += ":"; @@ -181,13 +181,13 @@ func Walk(j Json, path string) Json { case ArrayKind: indx, err := strconv.Atoi(elem); if err != nil { - return Null; + return Null } j = j.Elem(indx); case MapKind: - j = j.Get(elem); + j = j.Get(elem) default: - return Null; + return Null } } return j; @@ -197,40 +197,40 @@ func Walk(j Json, path string) Json { func Equal(a, b Json) bool { switch { case a == nil && b == nil: - return true; + return true case a == nil || b == nil: - return false; + return false case a.Kind() != b.Kind(): - return false; + return false } switch a.Kind() { case NullKind: - return true; + return true case StringKind: - return a.String() == b.String(); + return a.String() == b.String() case NumberKind: - return a.Number() == b.Number(); + return a.Number() == b.Number() case BoolKind: - return a.Bool() == b.Bool(); + return a.Bool() == b.Bool() case ArrayKind: if a.Len() != b.Len() { - return false; + return false } for i := 0; i < a.Len(); i++ { if !Equal(a.Elem(i), b.Elem(i)) { - return false; + return false } } return true; case MapKind: m := a.(*_Map).m; if len(m) != len(b.(*_Map).m) { - return false; + return false } for k, v := range m { if !Equal(v, b.Get(k)) { - return false; + return false } } return true; @@ -259,22 +259,22 @@ type _JsonBuilder struct { func (b *_JsonBuilder) Put(j Json) { switch { case b.ptr != nil: - *b.ptr = j; + *b.ptr = j case b.a != nil: - b.a.Set(b.i, j); + b.a.Set(b.i, j) case b.m != nil: - b.m[b.k] = j; + b.m[b.k] = j } } func (b *_JsonBuilder) Get() Json { switch { case b.ptr != nil: - return *b.ptr; + return *b.ptr case b.a != nil: - return b.a.At(b.i).(Json); + return b.a.At(b.i).(Json) case b.m != nil: - return b.m[b.k]; + return b.m[b.k] } return nil; } @@ -301,7 +301,7 @@ func (b *_JsonBuilder) Elem(i int) Builder { bb.a = b.Get().(*_Array).a; bb.i = i; for i >= bb.a.Len() { - bb.a.Push(Null); + bb.a.Push(Null) } return bb; } @@ -327,7 +327,7 @@ func StringToJson(s string) (json Json, ok bool, errtok string) { b.ptr = &j; ok, _, errtok = Parse(s, b); if !ok { - return nil, false, errtok; + return nil, false, errtok } return j, true, ""; } diff --git a/src/pkg/json/generic_test.go b/src/pkg/json/generic_test.go index 522d82dcd..ce78a39ee 100644 --- a/src/pkg/json/generic_test.go +++ b/src/pkg/json/generic_test.go @@ -44,10 +44,10 @@ func TestJsonMap(t *testing.T) { for i := 0; i < len(jsontests); i++ { val, ok, errtok := StringToJson(jsontests[i]); if !ok { - t.Errorf("StringToJson(%#q) => error near %v", jsontests[i], errtok); + t.Errorf("StringToJson(%#q) => error near %v", jsontests[i], errtok) } if i > 0 { - mapstr += ","; + mapstr += "," } values[jsontests[i]] = val; mapstr += Quote(jsontests[i]); @@ -58,18 +58,18 @@ func TestJsonMap(t *testing.T) { mapv, ok, errtok := StringToJson(mapstr); if !ok { - t.Fatalf("StringToJson(%#q) => error near %v", mapstr, errtok); + t.Fatalf("StringToJson(%#q) => error near %v", mapstr, errtok) } if mapv == nil { - t.Fatalf("StringToJson(%#q) => nil, %v, %v", mapstr, ok, errtok); + t.Fatalf("StringToJson(%#q) => nil, %v, %v", mapstr, ok, errtok) } if cnt := mapv.Len(); cnt != len(jsontests) { t.Errorf("StringToJson(%#q).Len() => %v, want %v", mapstr, cnt, - len(jsontests)); + len(jsontests)) } for k, v := range values { if v1 := mapv.Get(k); !Equal(v1, v) { - t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v); + t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v) } } } diff --git a/src/pkg/json/parse.go b/src/pkg/json/parse.go index 26c01fe85..74208824b 100644 --- a/src/pkg/json/parse.go +++ b/src/pkg/json/parse.go @@ -26,18 +26,18 @@ func _UnHex(p string, r, l int) (v int, ok bool) { v = 0; for i := r; i < l; i++ { if i >= len(p) { - return 0, false; + return 0, false } v *= 16; switch { case '0' <= p[i] && p[i] <= '9': - v += int(p[i]-'0'); + v += int(p[i]-'0') case 'a' <= p[i] && p[i] <= 'f': - v += int(p[i]-'a'+10); + v += int(p[i]-'a'+10) case 'A' <= p[i] && p[i] <= 'F': - v += int(p[i]-'A'+10); + v += int(p[i]-'A'+10) default: - return 0, false; + return 0, false } } return v, true; @@ -48,7 +48,7 @@ func _UnHex(p string, r, l int) (v int, ok bool) { // JSON-quoted string, Unquote returns with ok set to false. func Unquote(s string) (t string, ok bool) { if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' { - return; + return } b := make([]byte, len(s)); w := 0; @@ -57,11 +57,11 @@ func Unquote(s string) (t string, ok bool) { case s[r] == '\\': r++; if r >= len(s)-1 { - return; + return } switch s[r] { default: - return; + return case '"', '\\', '/', '\'': b[w] = s[r]; r++; @@ -90,7 +90,7 @@ func Unquote(s string) (t string, ok bool) { r++; rune, ok := _UnHex(s, r, 4); if !ok { - return; + return } r += 4; w += utf8.EncodeRune(rune, b[w:len(b)]); @@ -180,21 +180,21 @@ type _Lexer struct { } func punct(c byte) bool { - return c == '"' || c == '[' || c == ']' || c == ':' || c == '{' || c == '}' || c == ','; + return c == '"' || c == '[' || c == ']' || c == ':' || c == '{' || c == '}' || c == ',' } func white(c byte) bool { return c == ' ' || c == '\t' || c == '\n' || c == '\v' } func skipwhite(p string, i int) int { for i < len(p) && white(p[i]) { - i++; + i++ } return i; } func skiptoken(p string, i int) int { for i < len(p) && !punct(p[i]) && !white(p[i]) { - i++; + i++ } return i; } @@ -202,11 +202,11 @@ func skiptoken(p string, i int) int { func skipstring(p string, i int) int { for i++; i < len(p) && p[i] != '"'; i++ { if p[i] == '\\' { - i++; + i++ } } if i >= len(p) { - return i; + return i } return i+1; } @@ -304,7 +304,7 @@ func parse(lex *_Lexer, build Builder) bool { Switch: switch lex.kind { case 0: - break; + break case '1': // If the number is exactly an integer, use that. if i, err := strconv.Atoi64(lex.token); err == nil { @@ -347,12 +347,12 @@ Switch: for lex.kind != ']' { if n > 0 { if lex.kind != ',' { - break Switch; + break Switch } lex.Next(); } if !parse(lex, build.Elem(n)) { - break Switch; + break Switch } n++; } @@ -366,24 +366,24 @@ Switch: for lex.kind != '}' { if n > 0 { if lex.kind != ',' { - break Switch; + break Switch } lex.Next(); } if lex.kind != '"' { - break Switch; + break Switch } key, ok := Unquote(lex.token); if !ok { - break Switch; + break Switch } lex.Next(); if lex.kind != ':' { - break Switch; + break Switch } lex.Next(); if !parse(lex, build.Key(key)) { - break Switch; + break Switch } n++; } @@ -391,7 +391,7 @@ Switch: } if ok { - lex.Next(); + lex.Next() } build.Flush(); return ok; @@ -409,7 +409,7 @@ func Parse(s string, builder Builder) (ok bool, errindx int, errtok string) { lex.Next(); if parse(lex, builder) { if lex.kind == 0 { // EOF - return true, 0, ""; + return true, 0, "" } } return false, lex.i, lex.token; diff --git a/src/pkg/json/struct.go b/src/pkg/json/struct.go index 37728d38b..11aaccee9 100644 --- a/src/pkg/json/struct.go +++ b/src/pkg/json/struct.go @@ -25,7 +25,7 @@ var nobuilder *structBuilder func isfloat(v reflect.Value) bool { switch v.(type) { case *reflect.FloatValue, *reflect.Float32Value, *reflect.Float64Value: - return true; + return true } return false; } @@ -33,36 +33,36 @@ func isfloat(v reflect.Value) bool { func setfloat(v reflect.Value, f float64) { switch v := v.(type) { case *reflect.FloatValue: - v.Set(float(f)); + v.Set(float(f)) case *reflect.Float32Value: - v.Set(float32(f)); + v.Set(float32(f)) case *reflect.Float64Value: - v.Set(float64(f)); + v.Set(float64(f)) } } func setint(v reflect.Value, i int64) { switch v := v.(type) { case *reflect.IntValue: - v.Set(int(i)); + v.Set(int(i)) case *reflect.Int8Value: - v.Set(int8(i)); + v.Set(int8(i)) case *reflect.Int16Value: - v.Set(int16(i)); + v.Set(int16(i)) case *reflect.Int32Value: - v.Set(int32(i)); + v.Set(int32(i)) case *reflect.Int64Value: - v.Set(int64(i)); + v.Set(int64(i)) case *reflect.UintValue: - v.Set(uint(i)); + v.Set(uint(i)) case *reflect.Uint8Value: - v.Set(uint8(i)); + v.Set(uint8(i)) case *reflect.Uint16Value: - v.Set(uint16(i)); + v.Set(uint16(i)) case *reflect.Uint32Value: - v.Set(uint32(i)); + v.Set(uint32(i)) case *reflect.Uint64Value: - v.Set(uint64(i)); + v.Set(uint64(i)) } } @@ -70,46 +70,46 @@ func setint(v reflect.Value, i int64) { // copy a changed b.val out to the original. func (b *structBuilder) Flush() { if b == nil { - return; + return } if b.map_ != nil { - b.map_.SetElem(b.key, b.val); + b.map_.SetElem(b.key, b.val) } } func (b *structBuilder) Int64(i int64) { if b == nil { - return; + return } v := b.val; if isfloat(v) { - setfloat(v, float64(i)); + setfloat(v, float64(i)) } else { - setint(v, i); + setint(v, i) } } func (b *structBuilder) Uint64(i uint64) { if b == nil { - return; + return } v := b.val; if isfloat(v) { - setfloat(v, float64(i)); + setfloat(v, float64(i)) } else { - setint(v, int64(i)); + setint(v, int64(i)) } } func (b *structBuilder) Float64(f float64) { if b == nil { - return; + return } v := b.val; if isfloat(v) { - setfloat(v, f); + setfloat(v, f) } else { - setint(v, int64(f)); + setint(v, int64(f)) } } @@ -117,60 +117,60 @@ func (b *structBuilder) Null() {} func (b *structBuilder) String(s string) { if b == nil { - return; + return } if v, ok := b.val.(*reflect.StringValue); ok { - v.Set(s); + v.Set(s) } } func (b *structBuilder) Bool(tf bool) { if b == nil { - return; + return } if v, ok := b.val.(*reflect.BoolValue); ok { - v.Set(tf); + v.Set(tf) } } func (b *structBuilder) Array() { if b == nil { - return; + return } if v, ok := b.val.(*reflect.SliceValue); ok { if v.IsNil() { - v.Set(reflect.MakeSlice(v.Type().(*reflect.SliceType), 0, 8)); + v.Set(reflect.MakeSlice(v.Type().(*reflect.SliceType), 0, 8)) } } } func (b *structBuilder) Elem(i int) Builder { if b == nil || i < 0 { - return nobuilder; + return nobuilder } switch v := b.val.(type) { case *reflect.ArrayValue: if i < v.Len() { - return &structBuilder{val: v.Elem(i)}; + return &structBuilder{val: v.Elem(i)} } case *reflect.SliceValue: if i > v.Cap() { n := v.Cap(); if n < 8 { - n = 8; + n = 8 } for n <= i { - n *= 2; + n *= 2 } nv := reflect.MakeSlice(v.Type().(*reflect.SliceType), v.Len(), n); reflect.ArrayCopy(nv, v); v.Set(nv); } if v.Len() <= i && i < v.Cap() { - v.SetLen(i+1); + v.SetLen(i+1) } if i < v.Len() { - return &structBuilder{val: v.Elem(i)}; + return &structBuilder{val: v.Elem(i)} } } return nobuilder; @@ -178,7 +178,7 @@ func (b *structBuilder) Elem(i int) Builder { func (b *structBuilder) Map() { if b == nil { - return; + return } if v, ok := b.val.(*reflect.PtrValue); ok && v.IsNil() { if v.IsNil() { @@ -189,13 +189,13 @@ func (b *structBuilder) Map() { b.val = v.Elem(); } if v, ok := b.val.(*reflect.MapValue); ok && v.IsNil() { - v.Set(reflect.MakeMap(v.Type().(*reflect.MapType))); + v.Set(reflect.MakeMap(v.Type().(*reflect.MapType))) } } func (b *structBuilder) Key(k string) Builder { if b == nil { - return nobuilder; + return nobuilder } switch v := reflect.Indirect(b.val).(type) { case *reflect.StructValue: @@ -204,13 +204,13 @@ func (b *structBuilder) Key(k string) Builder { k = strings.ToLower(k); for i := 0; i < t.NumField(); i++ { if strings.ToLower(t.Field(i).Name) == k { - return &structBuilder{val: v.Field(i)}; + return &structBuilder{val: v.Field(i)} } } case *reflect.MapValue: t := v.Type().(*reflect.MapType); if t.Key() != reflect.Typeof(k) { - break; + break } key := reflect.NewValue(k); elem := v.Elem(key); @@ -286,7 +286,7 @@ func Unmarshal(s string, val interface{}) (ok bool, errtok string) { b := &structBuilder{val: reflect.NewValue(val)}; ok, _, errtok = Parse(s, b); if !ok { - return false, errtok; + return false, errtok } return true, ""; } diff --git a/src/pkg/json/struct_test.go b/src/pkg/json/struct_test.go index ad86d493f..95a3eb2a4 100644 --- a/src/pkg/json/struct_test.go +++ b/src/pkg/json/struct_test.go @@ -58,9 +58,9 @@ var decodedMapPtrStruct = map[string]*myStruct{ func check(t *testing.T, ok bool, name string, v interface{}) { if !ok { - t.Errorf("%s = %v (BAD)", name, v); + t.Errorf("%s = %v (BAD)", name, v) } else { - t.Logf("%s = %v (good)", name, v); + t.Logf("%s = %v (good)", name, v) } } @@ -69,7 +69,7 @@ func TestUnmarshal(t *testing.T) { m.F = true; ok, errtok := Unmarshal(encoded, &m); if !ok { - t.Fatalf("Unmarshal failed near %s", errtok); + t.Fatalf("Unmarshal failed near %s", errtok) } check(t, m.T == true, "t", m.T); check(t, m.F == false, "f", m.F); @@ -95,7 +95,7 @@ func TestUnmarshal(t *testing.T) { } check(t, m.My != nil, "my", m.My); if m.My != nil { - check(t, m.My.S == "subguy", "my.s", m.My.S); + check(t, m.My.S == "subguy", "my.s", m.My.S) } check(t, reflect.DeepEqual(m.Map, decodedMap), "map", m.Map); check(t, reflect.DeepEqual(m.MapStruct, decodedMapStruct), "mapstruct", m.MapStruct); |