//go:build go1.27 && goexperiment.jsonv2package decoderimport ()// text returns the words of the message of a syntax error which tell where the byte is, as encoding/json of Go 1.27// has them: the ones of encoding/json/jsontext, which are made the ones of encoding/json.func ( syntaxWhere) () string {switch {casewhereKey:return"looking for beginning of object key string"casewhereAfterKey:return"after object key"casewhereAfterPair:return"after object key:value pair"casewhereAfterElement:return"after array element"casewhereAfterTop:return"after top-level value"casewhereString:return"in string"casewhereNumber, whereFraction, whereExponent:return"in numeric literal" }return"looking for beginning of value"}// invalidCharacterError returns the syntax error of the character at cursor, which the offset is after: the// character of the UTF-8 sequence at cursor, or its byte if it is not one.func invalidCharacterError( []byte, int64, string) *errors.SyntaxError { , := utf8.DecodeRune([ : len()-1]) := strconv.QuoteRune()if == utf8.RuneError && == 1 { = `'\x` + strconv.FormatUint(uint64([]), 16) + `'` }returnerrors.ErrSyntax("invalid character "++" "+, +int64())}// scalarEndError returns the syntax error of the end of the input at cursor in a number, a literal or an escape,// which starts at start: encoding/json of Go 1.27 reports it at the start of the number or of the escape, and at// the end of the input for a literal.func scalarEndError( []byte, , int64, string) error {returnendError()}// escapeSyntaxError returns the syntax error of the byte at cursor, in the escape which the backslash at backslash// starts: encoding/json of Go 1.27 reports the escape, which is 6 bytes for \u.func escapeSyntaxError( []byte, , int64) error { := + 2if > +1 { = + 6 } := [:len()-1]if > int64(len()) {// the escape is cut by the end of the input: the end of the input if what it has may start an escape, // and else what it has := [:] := len() < 2 || [1] == 'u'for := 2; && < len(); ++ { = isHexDigit([]) }if {returnendError() } = int64(len()) } := string([:])varstringifstrings.ContainsFunc(, func( rune) bool {return == '`' || == utf8.RuneError || unicode.IsSpace() || !unicode.IsPrint() }) { = strconv.Quote() } else { = "`" + + "`" }returnerrors.ErrSyntax("invalid escape sequence "++" in string", )}// depthSyntaxError returns the syntax error of the object or the array at cursor, which is nested deeper than the// limit.func depthSyntaxError( []byte, int64) error {returnerrors.ErrSyntax("exceeded max depth", +1)}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.