//go:build go1.27 && goexperiment.jsonv2

package decoder

import (
	
	
	
	

	
)

// 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  {
	case whereKey:
		return "looking for beginning of object key string"
	case whereAfterKey:
		return "after object key"
	case whereAfterPair:
		return "after object key:value pair"
	case whereAfterElement:
		return "after array element"
	case whereAfterTop:
		return "after top-level value"
	case whereString:
		return "in string"
	case whereNumber, 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) + `'`
	}
	return errors.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 {
	return endError()
}

// 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 {
	 :=  + 2
	if  > +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  {
			return endError()
		}
		 = int64(len())
	}
	 := string([:])
	var  string
	if strings.ContainsFunc(, func( rune) bool {
		return  == '`' ||  == utf8.RuneError || unicode.IsSpace() || !unicode.IsPrint()
	}) {
		 = strconv.Quote()
	} else {
		 = "`" +  + "`"
	}
	return errors.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 {
	return errors.ErrSyntax("exceeded max depth", +1)
}