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: 's 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 {
newOp = d.scan.eof()
d.off = len(d.data) + 1 // mark processed EOF with len+1
} else {
c := int(d.data[d.off])
c := d.data[d.off]
d.off++
newOp = d.scan.step(&d.scan, c)
}
......
......@@ -716,7 +716,7 @@ func TestErrorMessageFromMisusedString(t *testing.T) {
}
func noSpace(c rune) rune {
if isSpace(c) {
if isSpace(byte(c)) { //only used for ascii
return -1
}
return c
......
......@@ -36,7 +36,7 @@ func compact(dst *bytes.Buffer, src []byte, escape bool) error {
dst.WriteByte(hex[src[i+2]&0xF])
start = i + 3
}
v := scan.step(&scan, int(c))
v := scan.step(&scan, c)
if v >= scanSkipSpace {
if v == scanError {
break
......@@ -80,7 +80,7 @@ func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
depth := 0
for _, c := range src {
scan.bytes++
v := scan.step(&scan, int(c))
v := scan.step(&scan, c)
if v == scanSkipSpace {
continue
}
......
This diff is collapsed.
......@@ -90,7 +90,7 @@ Input:
// Look in the buffer for a new value.
for i, c := range dec.buf[scanp:] {
dec.scan.bytes++
v := dec.scan.step(&dec.scan, int(c))
v := dec.scan.step(&dec.scan, c)
if v == scanEnd {
scanp += i
break Input
......@@ -157,7 +157,7 @@ func (dec *Decoder) refill() error {
func nonSpace(b []byte) bool {
for _, c := range b {
if !isSpace(rune(c)) {
if !isSpace(c) {
return true
}
}
......@@ -433,7 +433,7 @@ func (dec *Decoder) tokenError(c byte) (Token, error) {
case tokenObjectComma:
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
......@@ -448,7 +448,7 @@ func (dec *Decoder) peek() (byte, error) {
for {
for i := dec.scanp; i < len(dec.buf); i++ {
c := dec.buf[i]
if isSpace(rune(c)) {
if isSpace(c) {
continue
}
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