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
} }
......
...@@ -21,7 +21,7 @@ func checkValid(data []byte, scan *scanner) error { ...@@ -21,7 +21,7 @@ func checkValid(data []byte, scan *scanner) error {
scan.reset() scan.reset()
for _, c := range data { for _, c := range data {
scan.bytes++ scan.bytes++
if scan.step(scan, int(c)) == scanError { if scan.step(scan, c) == scanError {
return scan.err return scan.err
} }
} }
...@@ -37,7 +37,7 @@ func checkValid(data []byte, scan *scanner) error { ...@@ -37,7 +37,7 @@ func checkValid(data []byte, scan *scanner) error {
func nextValue(data []byte, scan *scanner) (value, rest []byte, err error) { func nextValue(data []byte, scan *scanner) (value, rest []byte, err error) {
scan.reset() scan.reset()
for i, c := range data { for i, c := range data {
v := scan.step(scan, int(c)) v := scan.step(scan, c)
if v >= scanEndObject { if v >= scanEndObject {
switch v { switch v {
// probe the scanner with a space to determine whether we will // probe the scanner with a space to determine whether we will
...@@ -50,7 +50,7 @@ func nextValue(data []byte, scan *scanner) (value, rest []byte, err error) { ...@@ -50,7 +50,7 @@ func nextValue(data []byte, scan *scanner) (value, rest []byte, err error) {
case scanError: case scanError:
return nil, nil, scan.err return nil, nil, scan.err
case scanEnd: case scanEnd:
return data[0:i], data[i:], nil return data[:i], data[i:], nil
} }
} }
} }
...@@ -85,7 +85,7 @@ type scanner struct { ...@@ -85,7 +85,7 @@ type scanner struct {
// Also tried using an integer constant and a single func // Also tried using an integer constant and a single func
// with a switch, but using the func directly was 10% faster // with a switch, but using the func directly was 10% faster
// on a 64-bit Mac Mini, and it's nicer to read. // on a 64-bit Mac Mini, and it's nicer to read.
step func(*scanner, int) int step func(*scanner, byte) int
// Reached end of top-level value. // Reached end of top-level value.
endTop bool endTop bool
...@@ -99,7 +99,7 @@ type scanner struct { ...@@ -99,7 +99,7 @@ type scanner struct {
// 1-byte redo (see undo method) // 1-byte redo (see undo method)
redo bool redo bool
redoCode int redoCode int
redoState func(*scanner, int) int redoState func(*scanner, byte) int
// total bytes consumed, updated by decoder.Decode // total bytes consumed, updated by decoder.Decode
bytes int64 bytes int64
...@@ -188,13 +188,13 @@ func (s *scanner) popParseState() { ...@@ -188,13 +188,13 @@ func (s *scanner) popParseState() {
} }
} }
func isSpace(c rune) bool { func isSpace(c byte) bool {
return c == ' ' || c == '\t' || c == '\r' || c == '\n' return c == ' ' || c == '\t' || c == '\r' || c == '\n'
} }
// stateBeginValueOrEmpty is the state after reading `[`. // stateBeginValueOrEmpty is the state after reading `[`.
func stateBeginValueOrEmpty(s *scanner, c int) int { func stateBeginValueOrEmpty(s *scanner, c byte) int {
if c <= ' ' && isSpace(rune(c)) { if c <= ' ' && isSpace(c) {
return scanSkipSpace return scanSkipSpace
} }
if c == ']' { if c == ']' {
...@@ -204,8 +204,8 @@ func stateBeginValueOrEmpty(s *scanner, c int) int { ...@@ -204,8 +204,8 @@ func stateBeginValueOrEmpty(s *scanner, c int) int {
} }
// stateBeginValue is the state at the beginning of the input. // stateBeginValue is the state at the beginning of the input.
func stateBeginValue(s *scanner, c int) int { func stateBeginValue(s *scanner, c byte) int {
if c <= ' ' && isSpace(rune(c)) { if c <= ' ' && isSpace(c) {
return scanSkipSpace return scanSkipSpace
} }
switch c { switch c {
...@@ -244,8 +244,8 @@ func stateBeginValue(s *scanner, c int) int { ...@@ -244,8 +244,8 @@ func stateBeginValue(s *scanner, c int) int {
} }
// stateBeginStringOrEmpty is the state after reading `{`. // stateBeginStringOrEmpty is the state after reading `{`.
func stateBeginStringOrEmpty(s *scanner, c int) int { func stateBeginStringOrEmpty(s *scanner, c byte) int {
if c <= ' ' && isSpace(rune(c)) { if c <= ' ' && isSpace(c) {
return scanSkipSpace return scanSkipSpace
} }
if c == '}' { if c == '}' {
...@@ -257,8 +257,8 @@ func stateBeginStringOrEmpty(s *scanner, c int) int { ...@@ -257,8 +257,8 @@ func stateBeginStringOrEmpty(s *scanner, c int) int {
} }
// stateBeginString is the state after reading `{"key": value,`. // stateBeginString is the state after reading `{"key": value,`.
func stateBeginString(s *scanner, c int) int { func stateBeginString(s *scanner, c byte) int {
if c <= ' ' && isSpace(rune(c)) { if c <= ' ' && isSpace(c) {
return scanSkipSpace return scanSkipSpace
} }
if c == '"' { if c == '"' {
...@@ -270,7 +270,7 @@ func stateBeginString(s *scanner, c int) int { ...@@ -270,7 +270,7 @@ func stateBeginString(s *scanner, c int) int {
// stateEndValue is the state after completing a value, // stateEndValue is the state after completing a value,
// such as after reading `{}` or `true` or `["x"`. // such as after reading `{}` or `true` or `["x"`.
func stateEndValue(s *scanner, c int) int { func stateEndValue(s *scanner, c byte) int {
n := len(s.parseState) n := len(s.parseState)
if n == 0 { if n == 0 {
// Completed top-level before the current byte. // Completed top-level before the current byte.
...@@ -278,7 +278,7 @@ func stateEndValue(s *scanner, c int) int { ...@@ -278,7 +278,7 @@ func stateEndValue(s *scanner, c int) int {
s.endTop = true s.endTop = true
return stateEndTop(s, c) return stateEndTop(s, c)
} }
if c <= ' ' && isSpace(rune(c)) { if c <= ' ' && isSpace(c) {
s.step = stateEndValue s.step = stateEndValue
return scanSkipSpace return scanSkipSpace
} }
...@@ -319,7 +319,7 @@ func stateEndValue(s *scanner, c int) int { ...@@ -319,7 +319,7 @@ func stateEndValue(s *scanner, c int) int {
// stateEndTop is the state after finishing the top-level value, // stateEndTop is the state after finishing the top-level value,
// such as after reading `{}` or `[1,2,3]`. // such as after reading `{}` or `[1,2,3]`.
// Only space characters should be seen now. // Only space characters should be seen now.
func stateEndTop(s *scanner, c int) int { func stateEndTop(s *scanner, c byte) int {
if c != ' ' && c != '\t' && c != '\r' && c != '\n' { if c != ' ' && c != '\t' && c != '\r' && c != '\n' {
// Complain about non-space byte on next call. // Complain about non-space byte on next call.
s.error(c, "after top-level value") s.error(c, "after top-level value")
...@@ -328,7 +328,7 @@ func stateEndTop(s *scanner, c int) int { ...@@ -328,7 +328,7 @@ func stateEndTop(s *scanner, c int) int {
} }
// stateInString is the state after reading `"`. // stateInString is the state after reading `"`.
func stateInString(s *scanner, c int) int { func stateInString(s *scanner, c byte) int {
if c == '"' { if c == '"' {
s.step = stateEndValue s.step = stateEndValue
return scanContinue return scanContinue
...@@ -344,13 +344,12 @@ func stateInString(s *scanner, c int) int { ...@@ -344,13 +344,12 @@ func stateInString(s *scanner, c int) int {
} }
// stateInStringEsc is the state after reading `"\` during a quoted string. // stateInStringEsc is the state after reading `"\` during a quoted string.
func stateInStringEsc(s *scanner, c int) int { func stateInStringEsc(s *scanner, c byte) int {
switch c { switch c {
case 'b', 'f', 'n', 'r', 't', '\\', '/', '"': case 'b', 'f', 'n', 'r', 't', '\\', '/', '"':
s.step = stateInString s.step = stateInString
return scanContinue return scanContinue
} case 'u':
if c == 'u' {
s.step = stateInStringEscU s.step = stateInStringEscU
return scanContinue return scanContinue
} }
...@@ -358,7 +357,7 @@ func stateInStringEsc(s *scanner, c int) int { ...@@ -358,7 +357,7 @@ func stateInStringEsc(s *scanner, c int) int {
} }
// stateInStringEscU is the state after reading `"\u` during a quoted string. // stateInStringEscU is the state after reading `"\u` during a quoted string.
func stateInStringEscU(s *scanner, c int) int { func stateInStringEscU(s *scanner, c byte) int {
if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' { if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
s.step = stateInStringEscU1 s.step = stateInStringEscU1
return scanContinue return scanContinue
...@@ -368,7 +367,7 @@ func stateInStringEscU(s *scanner, c int) int { ...@@ -368,7 +367,7 @@ func stateInStringEscU(s *scanner, c int) int {
} }
// stateInStringEscU1 is the state after reading `"\u1` during a quoted string. // stateInStringEscU1 is the state after reading `"\u1` during a quoted string.
func stateInStringEscU1(s *scanner, c int) int { func stateInStringEscU1(s *scanner, c byte) int {
if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' { if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
s.step = stateInStringEscU12 s.step = stateInStringEscU12
return scanContinue return scanContinue
...@@ -378,7 +377,7 @@ func stateInStringEscU1(s *scanner, c int) int { ...@@ -378,7 +377,7 @@ func stateInStringEscU1(s *scanner, c int) int {
} }
// stateInStringEscU12 is the state after reading `"\u12` during a quoted string. // stateInStringEscU12 is the state after reading `"\u12` during a quoted string.
func stateInStringEscU12(s *scanner, c int) int { func stateInStringEscU12(s *scanner, c byte) int {
if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' { if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
s.step = stateInStringEscU123 s.step = stateInStringEscU123
return scanContinue return scanContinue
...@@ -388,7 +387,7 @@ func stateInStringEscU12(s *scanner, c int) int { ...@@ -388,7 +387,7 @@ func stateInStringEscU12(s *scanner, c int) int {
} }
// stateInStringEscU123 is the state after reading `"\u123` during a quoted string. // stateInStringEscU123 is the state after reading `"\u123` during a quoted string.
func stateInStringEscU123(s *scanner, c int) int { func stateInStringEscU123(s *scanner, c byte) int {
if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' { if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
s.step = stateInString s.step = stateInString
return scanContinue return scanContinue
...@@ -398,7 +397,7 @@ func stateInStringEscU123(s *scanner, c int) int { ...@@ -398,7 +397,7 @@ func stateInStringEscU123(s *scanner, c int) int {
} }
// stateNeg is the state after reading `-` during a number. // stateNeg is the state after reading `-` during a number.
func stateNeg(s *scanner, c int) int { func stateNeg(s *scanner, c byte) int {
if c == '0' { if c == '0' {
s.step = state0 s.step = state0
return scanContinue return scanContinue
...@@ -412,7 +411,7 @@ func stateNeg(s *scanner, c int) int { ...@@ -412,7 +411,7 @@ func stateNeg(s *scanner, c int) int {
// state1 is the state after reading a non-zero integer during a number, // state1 is the state after reading a non-zero integer during a number,
// such as after reading `1` or `100` but not `0`. // such as after reading `1` or `100` but not `0`.
func state1(s *scanner, c int) int { func state1(s *scanner, c byte) int {
if '0' <= c && c <= '9' { if '0' <= c && c <= '9' {
s.step = state1 s.step = state1
return scanContinue return scanContinue
...@@ -421,7 +420,7 @@ func state1(s *scanner, c int) int { ...@@ -421,7 +420,7 @@ func state1(s *scanner, c int) int {
} }
// state0 is the state after reading `0` during a number. // state0 is the state after reading `0` during a number.
func state0(s *scanner, c int) int { func state0(s *scanner, c byte) int {
if c == '.' { if c == '.' {
s.step = stateDot s.step = stateDot
return scanContinue return scanContinue
...@@ -435,7 +434,7 @@ func state0(s *scanner, c int) int { ...@@ -435,7 +434,7 @@ func state0(s *scanner, c int) int {
// stateDot is the state after reading the integer and decimal point in a number, // stateDot is the state after reading the integer and decimal point in a number,
// such as after reading `1.`. // such as after reading `1.`.
func stateDot(s *scanner, c int) int { func stateDot(s *scanner, c byte) int {
if '0' <= c && c <= '9' { if '0' <= c && c <= '9' {
s.step = stateDot0 s.step = stateDot0
return scanContinue return scanContinue
...@@ -445,9 +444,8 @@ func stateDot(s *scanner, c int) int { ...@@ -445,9 +444,8 @@ func stateDot(s *scanner, c int) int {
// stateDot0 is the state after reading the integer, decimal point, and subsequent // stateDot0 is the state after reading the integer, decimal point, and subsequent
// digits of a number, such as after reading `3.14`. // digits of a number, such as after reading `3.14`.
func stateDot0(s *scanner, c int) int { func stateDot0(s *scanner, c byte) int {
if '0' <= c && c <= '9' { if '0' <= c && c <= '9' {
s.step = stateDot0
return scanContinue return scanContinue
} }
if c == 'e' || c == 'E' { if c == 'e' || c == 'E' {
...@@ -459,12 +457,8 @@ func stateDot0(s *scanner, c int) int { ...@@ -459,12 +457,8 @@ func stateDot0(s *scanner, c int) int {
// stateE is the state after reading the mantissa and e in a number, // stateE is the state after reading the mantissa and e in a number,
// such as after reading `314e` or `0.314e`. // such as after reading `314e` or `0.314e`.
func stateE(s *scanner, c int) int { func stateE(s *scanner, c byte) int {
if c == '+' { if c == '+' || c == '-' {
s.step = stateESign
return scanContinue
}
if c == '-' {
s.step = stateESign s.step = stateESign
return scanContinue return scanContinue
} }
...@@ -473,7 +467,7 @@ func stateE(s *scanner, c int) int { ...@@ -473,7 +467,7 @@ func stateE(s *scanner, c int) int {
// stateESign is the state after reading the mantissa, e, and sign in a number, // stateESign is the state after reading the mantissa, e, and sign in a number,
// such as after reading `314e-` or `0.314e+`. // such as after reading `314e-` or `0.314e+`.
func stateESign(s *scanner, c int) int { func stateESign(s *scanner, c byte) int {
if '0' <= c && c <= '9' { if '0' <= c && c <= '9' {
s.step = stateE0 s.step = stateE0
return scanContinue return scanContinue
...@@ -484,16 +478,15 @@ func stateESign(s *scanner, c int) int { ...@@ -484,16 +478,15 @@ func stateESign(s *scanner, c int) int {
// stateE0 is the state after reading the mantissa, e, optional sign, // stateE0 is the state after reading the mantissa, e, optional sign,
// and at least one digit of the exponent in a number, // and at least one digit of the exponent in a number,
// such as after reading `314e-2` or `0.314e+1` or `3.14e0`. // such as after reading `314e-2` or `0.314e+1` or `3.14e0`.
func stateE0(s *scanner, c int) int { func stateE0(s *scanner, c byte) int {
if '0' <= c && c <= '9' { if '0' <= c && c <= '9' {
s.step = stateE0
return scanContinue return scanContinue
} }
return stateEndValue(s, c) return stateEndValue(s, c)
} }
// stateT is the state after reading `t`. // stateT is the state after reading `t`.
func stateT(s *scanner, c int) int { func stateT(s *scanner, c byte) int {
if c == 'r' { if c == 'r' {
s.step = stateTr s.step = stateTr
return scanContinue return scanContinue
...@@ -502,7 +495,7 @@ func stateT(s *scanner, c int) int { ...@@ -502,7 +495,7 @@ func stateT(s *scanner, c int) int {
} }
// stateTr is the state after reading `tr`. // stateTr is the state after reading `tr`.
func stateTr(s *scanner, c int) int { func stateTr(s *scanner, c byte) int {
if c == 'u' { if c == 'u' {
s.step = stateTru s.step = stateTru
return scanContinue return scanContinue
...@@ -511,7 +504,7 @@ func stateTr(s *scanner, c int) int { ...@@ -511,7 +504,7 @@ func stateTr(s *scanner, c int) int {
} }
// stateTru is the state after reading `tru`. // stateTru is the state after reading `tru`.
func stateTru(s *scanner, c int) int { func stateTru(s *scanner, c byte) int {
if c == 'e' { if c == 'e' {
s.step = stateEndValue s.step = stateEndValue
return scanContinue return scanContinue
...@@ -520,7 +513,7 @@ func stateTru(s *scanner, c int) int { ...@@ -520,7 +513,7 @@ func stateTru(s *scanner, c int) int {
} }
// stateF is the state after reading `f`. // stateF is the state after reading `f`.
func stateF(s *scanner, c int) int { func stateF(s *scanner, c byte) int {
if c == 'a' { if c == 'a' {
s.step = stateFa s.step = stateFa
return scanContinue return scanContinue
...@@ -529,7 +522,7 @@ func stateF(s *scanner, c int) int { ...@@ -529,7 +522,7 @@ func stateF(s *scanner, c int) int {
} }
// stateFa is the state after reading `fa`. // stateFa is the state after reading `fa`.
func stateFa(s *scanner, c int) int { func stateFa(s *scanner, c byte) int {
if c == 'l' { if c == 'l' {
s.step = stateFal s.step = stateFal
return scanContinue return scanContinue
...@@ -538,7 +531,7 @@ func stateFa(s *scanner, c int) int { ...@@ -538,7 +531,7 @@ func stateFa(s *scanner, c int) int {
} }
// stateFal is the state after reading `fal`. // stateFal is the state after reading `fal`.
func stateFal(s *scanner, c int) int { func stateFal(s *scanner, c byte) int {
if c == 's' { if c == 's' {
s.step = stateFals s.step = stateFals
return scanContinue return scanContinue
...@@ -547,7 +540,7 @@ func stateFal(s *scanner, c int) int { ...@@ -547,7 +540,7 @@ func stateFal(s *scanner, c int) int {
} }
// stateFals is the state after reading `fals`. // stateFals is the state after reading `fals`.
func stateFals(s *scanner, c int) int { func stateFals(s *scanner, c byte) int {
if c == 'e' { if c == 'e' {
s.step = stateEndValue s.step = stateEndValue
return scanContinue return scanContinue
...@@ -556,7 +549,7 @@ func stateFals(s *scanner, c int) int { ...@@ -556,7 +549,7 @@ func stateFals(s *scanner, c int) int {
} }
// stateN is the state after reading `n`. // stateN is the state after reading `n`.
func stateN(s *scanner, c int) int { func stateN(s *scanner, c byte) int {
if c == 'u' { if c == 'u' {
s.step = stateNu s.step = stateNu
return scanContinue return scanContinue
...@@ -565,7 +558,7 @@ func stateN(s *scanner, c int) int { ...@@ -565,7 +558,7 @@ func stateN(s *scanner, c int) int {
} }
// stateNu is the state after reading `nu`. // stateNu is the state after reading `nu`.
func stateNu(s *scanner, c int) int { func stateNu(s *scanner, c byte) int {
if c == 'l' { if c == 'l' {
s.step = stateNul s.step = stateNul
return scanContinue return scanContinue
...@@ -574,7 +567,7 @@ func stateNu(s *scanner, c int) int { ...@@ -574,7 +567,7 @@ func stateNu(s *scanner, c int) int {
} }
// stateNul is the state after reading `nul`. // stateNul is the state after reading `nul`.
func stateNul(s *scanner, c int) int { func stateNul(s *scanner, c byte) int {
if c == 'l' { if c == 'l' {
s.step = stateEndValue s.step = stateEndValue
return scanContinue return scanContinue
...@@ -584,19 +577,19 @@ func stateNul(s *scanner, c int) int { ...@@ -584,19 +577,19 @@ func stateNul(s *scanner, c int) int {
// stateError is the state after reaching a syntax error, // stateError is the state after reaching a syntax error,
// such as after reading `[1}` or `5.1.2`. // such as after reading `[1}` or `5.1.2`.
func stateError(s *scanner, c int) int { func stateError(s *scanner, c byte) int {
return scanError return scanError
} }
// error records an error and switches to the error state. // error records an error and switches to the error state.
func (s *scanner) error(c int, context string) int { func (s *scanner) error(c byte, context string) int {
s.step = stateError s.step = stateError
s.err = &SyntaxError{"invalid character " + quoteChar(c) + " " + context, s.bytes} s.err = &SyntaxError{"invalid character " + quoteChar(c) + " " + context, s.bytes}
return scanError return scanError
} }
// quoteChar formats c as a quoted character literal // quoteChar formats c as a quoted character literal
func quoteChar(c int) string { func quoteChar(c byte) string {
// special cases - different from quoted strings // special cases - different from quoted strings
if c == '\'' { if c == '\'' {
return `'\''` return `'\''`
...@@ -623,7 +616,7 @@ func (s *scanner) undo(scanCode int) { ...@@ -623,7 +616,7 @@ func (s *scanner) undo(scanCode int) {
} }
// stateRedo helps implement the scanner's 1-byte undo. // stateRedo helps implement the scanner's 1-byte undo.
func stateRedo(s *scanner, c int) int { func stateRedo(s *scanner, c byte) int {
s.redo = false s.redo = false
s.step = s.redoState s.step = s.redoState
return s.redoCode return s.redoCode
......
...@@ -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