Bump go-connections and canonical go dependencies to the latest version

Logging bugfix for github.com/docker/go-connections
github.com/docker/go rebased to go 1.6

Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
Ying Li 2016-03-08 11:16:57 -08:00
parent 40a24c3793
commit dc377b3ceb
7 changed files with 163 additions and 92 deletions

8
Godeps/Godeps.json generated
View File

@ -97,13 +97,13 @@
}, },
{ {
"ImportPath": "github.com/docker/go-connections/tlsconfig", "ImportPath": "github.com/docker/go-connections/tlsconfig",
"Comment": "v0.1.2-7-g6e4c13d", "Comment": "v0.1.2-16-gf549a93",
"Rev": "6e4c13dc022344c3623c9eacbaf7cfd0fa9fcae3" "Rev": "f549a9393d05688dff0992ef3efd8bbe6c628aeb"
}, },
{ {
"ImportPath": "github.com/docker/go/canonical/json", "ImportPath": "github.com/docker/go/canonical/json",
"Comment": "v1.5.1-1-1-gbaf439e", "Comment": "v1.5.1-1-6-gd30aec9",
"Rev": "baf439e6c161bd2106346fc8022b74ac2444e311" "Rev": "d30aec9fd63c35133f8f79c3412ad91a3b08be06"
}, },
{ {
"ImportPath": "github.com/docker/libtrust", "ImportPath": "github.com/docker/libtrust",

View File

@ -72,12 +72,7 @@ func certPool(caFile string) (*x509.CertPool, error) {
if !certPool.AppendCertsFromPEM(pem) { if !certPool.AppendCertsFromPEM(pem) {
return nil, fmt.Errorf("failed to append certificates from PEM file: %q", caFile) return nil, fmt.Errorf("failed to append certificates from PEM file: %q", caFile)
} }
s := certPool.Subjects() logrus.Debugf("Trusting %d certs", len(certPool.Subjects()))
subjects := make([]string, len(s))
for i, subject := range s {
subjects[i] = string(subject)
}
logrus.Debugf("Trusting certs with subjects: %v", subjects)
return certPool, nil return certPool, nil
} }

View File

@ -37,6 +37,7 @@ import (
// To unmarshal JSON into a struct, Unmarshal matches incoming object // To unmarshal JSON into a struct, Unmarshal matches incoming object
// keys to the keys used by Marshal (either the struct field name or its tag), // keys to the keys used by Marshal (either the struct field name or its tag),
// preferring an exact match but also accepting a case-insensitive match. // preferring an exact match but also accepting a case-insensitive match.
// Unmarshal will only set exported fields of the struct.
// //
// To unmarshal JSON into an interface value, // To unmarshal JSON into an interface value,
// Unmarshal stores one of these in the interface value: // Unmarshal stores one of these in the interface value:
@ -48,16 +49,26 @@ import (
// map[string]interface{}, for JSON objects // map[string]interface{}, for JSON objects
// nil for JSON null // nil for JSON null
// //
// To unmarshal a JSON array into a slice, Unmarshal resets the slice to nil // To unmarshal a JSON array into a slice, Unmarshal resets the slice length
// and then appends each element to the slice. // to zero and then appends each element to the slice.
// As a special case, to unmarshal an empty JSON array into a slice,
// Unmarshal replaces the slice with a new empty slice.
// //
// To unmarshal a JSON object into a map, Unmarshal replaces the map // To unmarshal a JSON array into a Go array, Unmarshal decodes
// with an empty map and then adds key-value pairs from the object to // JSON array elements into corresponding Go array elements.
// the map. // If the Go array is smaller than the JSON array,
// the additional JSON array elements are discarded.
// If the JSON array is smaller than the Go array,
// the additional Go array elements are set to zero values.
//
// To unmarshal a JSON object into a string-keyed map, Unmarshal first
// establishes a map to use, If the map is nil, Unmarshal allocates a new map.
// Otherwise Unmarshal reuses the existing map, keeping existing entries.
// Unmarshal then stores key-value pairs from the JSON object into the map.
// //
// If a JSON value is not appropriate for a given target type, // If a JSON value is not appropriate for a given target type,
// or if a JSON number overflows the target type, Unmarshal // or if a JSON number overflows the target type, Unmarshal
// skips that field and completes the unmarshalling as best it can. // skips that field and completes the unmarshaling as best it can.
// If no more serious errors are encountered, Unmarshal returns // If no more serious errors are encountered, Unmarshal returns
// an UnmarshalTypeError describing the earliest such error. // an UnmarshalTypeError describing the earliest such error.
// //
@ -174,6 +185,66 @@ func (n Number) Int64() (int64, error) {
return strconv.ParseInt(string(n), 10, 64) return strconv.ParseInt(string(n), 10, 64)
} }
// isValidNumber reports whether s is a valid JSON number literal.
func isValidNumber(s string) bool {
// This function implements the JSON numbers grammar.
// See https://tools.ietf.org/html/rfc7159#section-6
// and http://json.org/number.gif
if s == "" {
return false
}
// Optional -
if s[0] == '-' {
s = s[1:]
if s == "" {
return false
}
}
// Digits
switch {
default:
return false
case s[0] == '0':
s = s[1:]
case '1' <= s[0] && s[0] <= '9':
s = s[1:]
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
s = s[1:]
}
}
// . followed by 1 or more digits.
if len(s) >= 2 && s[0] == '.' && '0' <= s[1] && s[1] <= '9' {
s = s[2:]
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
s = s[1:]
}
}
// e or E followed by an optional - or + and
// 1 or more digits.
if len(s) >= 2 && (s[0] == 'e' || s[0] == 'E') {
s = s[1:]
if s[0] == '+' || s[0] == '-' {
s = s[1:]
if s == "" {
return false
}
}
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
s = s[1:]
}
}
// Make sure we are at the end.
return s == ""
}
// decodeState represents the state while decoding a JSON value. // decodeState represents the state while decoding a JSON value.
type decodeState struct { type decodeState struct {
data []byte data []byte
@ -242,7 +313,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)
} }
@ -758,7 +829,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
d.saveError(err) d.saveError(err)
break break
} }
v.Set(reflect.ValueOf(b[0:n])) v.SetBytes(b[:n])
case reflect.String: case reflect.String:
v.SetString(string(s)) v.SetString(string(s))
case reflect.Interface: case reflect.Interface:
@ -782,6 +853,9 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
default: default:
if v.Kind() == reflect.String && v.Type() == numberType { if v.Kind() == reflect.String && v.Type() == numberType {
v.SetString(s) v.SetString(s)
if !isValidNumber(s) {
d.error(fmt.Errorf("json: invalid number literal, trying to unmarshal %q into Number", item))
}
break break
} }
if fromQuoted { if fromQuoted {

View File

@ -14,6 +14,7 @@ import (
"bytes" "bytes"
"encoding" "encoding"
"encoding/base64" "encoding/base64"
"fmt"
"math" "math"
"reflect" "reflect"
"runtime" "runtime"
@ -30,7 +31,10 @@ import (
// Marshal traverses the value v recursively. // Marshal traverses the value v recursively.
// If an encountered value implements the Marshaler interface // If an encountered value implements the Marshaler interface
// and is not a nil pointer, Marshal calls its MarshalJSON method // and is not a nil pointer, Marshal calls its MarshalJSON method
// to produce JSON. The nil pointer exception is not strictly necessary // to produce JSON. If no MarshalJSON method is present but the
// value implements encoding.TextMarshaler instead, Marshal calls
// its MarshalText method.
// The nil pointer exception is not strictly necessary
// but mimics a similar, necessary exception in the behavior of // but mimics a similar, necessary exception in the behavior of
// UnmarshalJSON. // UnmarshalJSON.
// //
@ -457,12 +461,10 @@ func textMarshalerEncoder(e *encodeState, v reflect.Value, quoted bool) {
} }
m := v.Interface().(encoding.TextMarshaler) m := v.Interface().(encoding.TextMarshaler)
b, err := m.MarshalText() b, err := m.MarshalText()
if err == nil {
_, err = e.stringBytes(b)
}
if err != nil { if err != nil {
e.error(&MarshalerError{v.Type(), err}) e.error(&MarshalerError{v.Type(), err})
} }
e.stringBytes(b)
} }
func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, quoted bool) { func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, quoted bool) {
@ -473,12 +475,10 @@ func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, quoted bool) {
} }
m := va.Interface().(encoding.TextMarshaler) m := va.Interface().(encoding.TextMarshaler)
b, err := m.MarshalText() b, err := m.MarshalText()
if err == nil {
_, err = e.stringBytes(b)
}
if err != nil { if err != nil {
e.error(&MarshalerError{v.Type(), err}) e.error(&MarshalerError{v.Type(), err})
} }
e.stringBytes(b)
} }
func boolEncoder(e *encodeState, v reflect.Value, quoted bool) { func boolEncoder(e *encodeState, v reflect.Value, quoted bool) {
@ -548,9 +548,14 @@ var (
func stringEncoder(e *encodeState, v reflect.Value, quoted bool) { func stringEncoder(e *encodeState, v reflect.Value, quoted bool) {
if v.Type() == numberType { if v.Type() == numberType {
numStr := v.String() numStr := v.String()
// In Go1.5 the empty string encodes to "0", while this is not a valid number literal
// we keep compatibility so check validity after this.
if numStr == "" { if numStr == "" {
numStr = "0" // Number's zero-val numStr = "0" // Number's zero-val
} }
if !isValidNumber(numStr) {
e.error(fmt.Errorf("json: invalid number literal %q", numStr))
}
e.WriteString(numStr) e.WriteString(numStr)
return return
} }
@ -798,7 +803,7 @@ func (sv stringValues) Less(i, j int) bool { return sv.get(i) < sv.get(j) }
func (sv stringValues) get(i int) string { return sv[i].String() } func (sv stringValues) get(i int) string { return sv[i].String() }
// NOTE: keep in sync with stringBytes below. // NOTE: keep in sync with stringBytes below.
func (e *encodeState) string(s string) (int, error) { func (e *encodeState) string(s string) int {
len0 := e.Len() len0 := e.Len()
e.WriteByte('"') e.WriteByte('"')
start := 0 start := 0
@ -876,11 +881,11 @@ func (e *encodeState) string(s string) (int, error) {
e.WriteString(s[start:]) e.WriteString(s[start:])
} }
e.WriteByte('"') e.WriteByte('"')
return e.Len() - len0, nil return e.Len() - len0
} }
// NOTE: keep in sync with string above. // NOTE: keep in sync with string above.
func (e *encodeState) stringBytes(s []byte) (int, error) { func (e *encodeState) stringBytes(s []byte) int {
len0 := e.Len() len0 := e.Len()
e.WriteByte('"') e.WriteByte('"')
start := 0 start := 0
@ -958,7 +963,7 @@ func (e *encodeState) stringBytes(s []byte) (int, error) {
e.Write(s[start:]) e.Write(s[start:])
} }
e.WriteByte('"') e.WriteByte('"')
return e.Len() - len0, nil return e.Len() - len0
} }
// A field represents a single field found in a struct. // A field represents a single field found in a struct.
@ -1052,7 +1057,7 @@ func typeFields(t reflect.Type) []field {
// Scan f.typ for fields to include. // Scan f.typ for fields to include.
for i := 0; i < f.typ.NumField(); i++ { for i := 0; i < f.typ.NumField(); i++ {
sf := f.typ.Field(i) sf := f.typ.Field(i)
if sf.PkgPath != "" { // unexported if sf.PkgPath != "" && !sf.Anonymous { // unexported
continue continue
} }
tag := sf.Tag.Get("json") tag := sf.Tag.Get("json")

View File

@ -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
@ -70,8 +70,12 @@ func newline(dst *bytes.Buffer, prefix, indent string, depth int) {
// indented line beginning with prefix followed by one or more // indented line beginning with prefix followed by one or more
// copies of indent according to the indentation nesting. // copies of indent according to the indentation nesting.
// The data appended to dst does not begin with the prefix nor // The data appended to dst does not begin with the prefix nor
// any indentation, and has no trailing newline, to make it // any indentation, to make it easier to embed inside other formatted JSON data.
// easier to embed inside other formatted JSON data. // Although leading space characters (space, tab, carriage return, newline)
// at the beginning of src are dropped, trailing space characters
// at the end of src are preserved and copied to dst.
// For example, if src has no trailing spaces, neither will dst;
// if src ends in a trailing newline, so will dst.
func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error { func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
origLen := dst.Len() origLen := dst.Len()
var scan scanner var scan scanner
@ -80,7 +84,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
} }

View File

@ -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 {
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) {
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 {
// 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 {
// 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() {
} }
} }
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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
// 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 {
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 {
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
// 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 {
} }
// 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 {
// 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 {
// 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 {
// 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 {
// 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 {
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
} }
// 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 {
// 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) {
} }
// 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

View File

@ -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 {
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
} }
} }
@ -440,7 +440,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
@ -455,7 +455,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