$64 GRAYBYTE WORDPRESS FILE MANAGER $85

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/usr/lib/golang/src/encoding/json/

HOME
Current File : /usr/lib/golang/src/encoding/json//v2_scanner.go
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build goexperiment.jsonv2

package json

import (
	"errors"
	"io"
	"strings"

	"encoding/json/internal"
	"encoding/json/internal/jsonflags"
	"encoding/json/jsontext"
)

// export exposes internal functionality of the "jsontext" package.
var export = jsontext.Internal.Export(&internal.AllowInternalUse)

// Valid reports whether data is a valid JSON encoding.
func Valid(data []byte) bool {
	return checkValid(data) == nil
}

func checkValid(data []byte) error {
	d := export.GetBufferedDecoder(data)
	defer export.PutBufferedDecoder(d)
	xd := export.Decoder(d)
	xd.Struct.Flags.Set(jsonflags.AllowDuplicateNames | jsonflags.AllowInvalidUTF8 | 1)
	if _, err := d.ReadValue(); err != nil {
		if err == io.EOF {
			offset := d.InputOffset() + int64(len(d.UnreadBuffer()))
			err = &jsontext.SyntacticError{ByteOffset: offset, Err: io.ErrUnexpectedEOF}
		}
		return transformSyntacticError(err)
	}
	if err := xd.CheckEOF(); err != nil {
		return transformSyntacticError(err)
	}
	return nil
}

// A SyntaxError is a description of a JSON syntax error.
// [Unmarshal] will return a SyntaxError if the JSON can't be parsed.
type SyntaxError struct {
	msg    string // description of error
	Offset int64  // error occurred after reading Offset bytes
}

func (e *SyntaxError) Error() string { return e.msg }

var errUnexpectedEnd = errors.New("unexpected end of JSON input")

func transformSyntacticError(err error) error {
	switch serr, ok := err.(*jsontext.SyntacticError); {
	case serr != nil:
		if serr.Err == io.ErrUnexpectedEOF {
			serr.Err = errUnexpectedEnd
		}
		msg := serr.Err.Error()
		if i := strings.Index(msg, " (expecting"); i >= 0 && !strings.Contains(msg, " in literal") {
			msg = msg[:i]
		}
		return &SyntaxError{Offset: serr.ByteOffset, msg: syntaxErrorReplacer.Replace(msg)}
	case ok:
		return (*SyntaxError)(nil)
	case export.IsIOError(err):
		return errors.Unwrap(err) // v1 historically did not wrap IO errors
	default:
		return err
	}
}

// syntaxErrorReplacer replaces certain string literals in the v2 error
// to better match the historical string rendering of syntax errors.
// In particular, v2 uses the terminology "object name" to match RFC 8259,
// while v1 uses "object key", which is not a term found in JSON literature.
var syntaxErrorReplacer = strings.NewReplacer(
	"object name", "object key",
	"at start of value", "looking for beginning of value",
	"at start of string", "looking for beginning of object key string",
	"after object value", "after object key:value pair",
	"in number", "in numeric literal",
)

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
16 Dec 2025 9.30 PM
root / root
0755
internal
--
16 Dec 2025 9.30 PM
root / root
0755
jsontext
--
16 Dec 2025 9.30 PM
root / root
0755
v2
--
16 Dec 2025 9.30 PM
root / root
0755
decode.go
35.482 KB
4 Dec 2025 6.06 PM
root / root
0644
encode.go
39.913 KB
4 Dec 2025 6.06 PM
root / root
0644
fold.go
1.096 KB
4 Dec 2025 6.06 PM
root / root
0644
indent.go
5.394 KB
4 Dec 2025 6.06 PM
root / root
0644
scanner.go
16.181 KB
4 Dec 2025 6.06 PM
root / root
0644
stream.go
12.947 KB
4 Dec 2025 6.06 PM
root / root
0644
tables.go
4.192 KB
4 Dec 2025 6.06 PM
root / root
0644
tags.go
0.981 KB
4 Dec 2025 6.06 PM
root / root
0644
v2_decode.go
8.626 KB
4 Dec 2025 6.06 PM
root / root
0644
v2_encode.go
9.581 KB
4 Dec 2025 6.06 PM
root / root
0644
v2_indent.go
4.64 KB
4 Dec 2025 6.06 PM
root / root
0644
v2_inject.go
5.008 KB
4 Dec 2025 6.06 PM
root / root
0644
v2_options.go
24.666 KB
4 Dec 2025 6.06 PM
root / root
0644
v2_scanner.go
2.646 KB
4 Dec 2025 6.06 PM
root / root
0644
v2_stream.go
6.74 KB
4 Dec 2025 6.06 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF