Commit fcf8143d authored by Marvin Stenger's avatar Marvin Stenger Committed by Andrew Gerrand

encoding/json: scanner: use byte, more consistent

The fields step and redoState of struct scanner are now defined as
`func(s *scanner, c byte) int` instead of
`func(s *scanner, c int) int`, since bytes are sufficient.
Further changes improve the consistency in the scanner.go file.

Change-Id: Ifb85f2130d728d2b936d79914d87a1f0b5c6ee7d
Reviewed-on: https://go-review.googlesource.com/14801Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
Run-TryBot: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 6d017835
...@@ -241,7 +241,7 @@ func (d *decodeState) scanWhile(op int) int { ...@@ -241,7 +241,7 @@ func (d *decodeState) scanWhile(op int) int {
newOp = d.scan.eof() newOp = d.scan.eof()
d.off = len(d.data) + 1 // mark processed EOF with len+1 d.off = len(d.data) + 1 // mark processed EOF with len+1
} else { } else {
c := int(d.data[d.off]) c := d.data[d.off]
d.off++ d.off++
newOp = d.scan.step(&d.scan, c) newOp = d.scan.step(&d.scan, c)
} }
......
...@@ -716,7 +716,7 @@ func TestErrorMessageFromMisusedString(t *testing.T) { ...@@ -716,7 +716,7 @@ func TestErrorMessageFromMisusedString(t *testing.T) {
} }
func noSpace(c rune) rune { func noSpace(c rune) rune {
if isSpace(c) { if isSpace(byte(c)) { //only used for ascii
return -1 return -1
} }
return c return c
......
...@@ -36,7 +36,7 @@ func compact(dst *bytes.Buffer, src []byte, escape bool) error { ...@@ -36,7 +36,7 @@ func compact(dst *bytes.Buffer, src []byte, escape bool) error {
dst.WriteByte(hex[src[i+2]&0xF]) dst.WriteByte(hex[src[i+2]&0xF])
start = i + 3 start = i + 3
} }
v := scan.step(&scan, int(c)) v := scan.step(&scan, c)
if v >= scanSkipSpace { if v >= scanSkipSpace {
if v == scanError { if v == scanError {
break break
...@@ -80,7 +80,7 @@ func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error { ...@@ -80,7 +80,7 @@ func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
depth := 0 depth := 0
for _, c := range src { for _, c := range src {
scan.bytes++ scan.bytes++
v := scan.step(&scan, int(c)) v := scan.step(&scan, c)
if v == scanSkipSpace { if v == scanSkipSpace {
continue continue
} }
......
This diff is collapsed.
...@@ -90,7 +90,7 @@ Input: ...@@ -90,7 +90,7 @@ Input:
// Look in the buffer for a new value. // Look in the buffer for a new value.
for i, c := range dec.buf[scanp:] { for i, c := range dec.buf[scanp:] {
dec.scan.bytes++ dec.scan.bytes++
v := dec.scan.step(&dec.scan, int(c)) v := dec.scan.step(&dec.scan, c)
if v == scanEnd { if v == scanEnd {
scanp += i scanp += i
break Input break Input
...@@ -157,7 +157,7 @@ func (dec *Decoder) refill() error { ...@@ -157,7 +157,7 @@ func (dec *Decoder) refill() error {
func nonSpace(b []byte) bool { func nonSpace(b []byte) bool {
for _, c := range b { for _, c := range b {
if !isSpace(rune(c)) { if !isSpace(c) {
return true return true
} }
} }
...@@ -433,7 +433,7 @@ func (dec *Decoder) tokenError(c byte) (Token, error) { ...@@ -433,7 +433,7 @@ func (dec *Decoder) tokenError(c byte) (Token, error) {
case tokenObjectComma: case tokenObjectComma:
context = " after object key:value pair" context = " after object key:value pair"
} }
return nil, &SyntaxError{"invalid character " + quoteChar(int(c)) + " " + context, 0} return nil, &SyntaxError{"invalid character " + quoteChar(c) + " " + context, 0}
} }
// More reports whether there is another element in the // More reports whether there is another element in the
...@@ -448,7 +448,7 @@ func (dec *Decoder) peek() (byte, error) { ...@@ -448,7 +448,7 @@ func (dec *Decoder) peek() (byte, error) {
for { for {
for i := dec.scanp; i < len(dec.buf); i++ { for i := dec.scanp; i < len(dec.buf); i++ {
c := dec.buf[i] c := dec.buf[i]
if isSpace(rune(c)) { if isSpace(c) {
continue continue
} }
dec.scanp = i dec.scanp = i
......
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