func (p *parser) decodeHex(input []byte, start int, hexLen int) []byte {
	// Length must be a power of two and no larger that size of uint32.
	if hexLen <= 0 || hexLen > 8 || hexLen%2 != 0 {
		// calling code must give us a proper slice...
		p.panicf("hex escape is invalid length (%d)", hexLen)
	}
	// Construct a working slice to decode with.
	inLen := len(input)
	if start < 0 || start >= inLen {
		p.panicf("start of hex escape (%d) is negative or greater than or equal to input length (%d)", start, inLen)
	}
	end := start + hexLen
	if end > inLen {
		p.panicf("end of hex escape (%d) is greater than input length (%d)", end, inLen)
	}
	hex := input[start:end]

	// Decode the hex string into a UTF-32 scalar.
	buf := make([]byte, utf8.UTFMax)
	var cp uint64
	for i := 0; i < hexLen; i += 2 {
		octet, errParse := strconv.ParseUint(string(hex[i:i+2]), 16, 8)
		if errParse != nil {
			p.panicf("invalid hex escape (%q) was not caught by lexer: %v", hex, errParse)
		}
		cp = (cp << 8) | octet
	}

	// Now serialize back as UTF-8 code units.
	encodeLen := utf8.EncodeRune(buf, rune(cp))

	return buf[0:encodeLen]
}
// decodeHex takes a slice that is the input buffer and decodes it into a slice containing UTF-8 code units.
// The start parameter is the index in the slice start of a hex-encoded rune to decode.
// The escapeLen parameter is the length of the escape to decode and must be a length
// that is a power of two, no longer than size of uint32, and within the length of the input slice.
decodeHex takes a slice that is the input buffer and decodes it into a slice containing UTF-8 code units.
The start parameter is the index in the slice start of a hex-encoded rune to decode.
The escapeLen parameter is the length of the escape to decode and must be a length
that is a power of two, no longer than size of uint32, and within the length of the input slice.
// decodeHex takes a slice that is the input buffer and decodes it into a slice containing UTF - 8 code units . // The start parameter is the index in the slice start of a hex - encoded rune to decode . // The escapeLen parameter is the length of the escape to decode and must be a length // that is a power of two no longer than size of uint32 and within the length of the input slice .
func (p *parser) decodeHex(input []byte, start int, hexLen int) []byte {
	if hexLen <= 0 || hexLen > 8 || hexLen%2 != 0 {
		p.panicf("hex escape is invalid length (%d)", hexLen)
	}
	inLen := len(input)
	if start < 0 || start >= inLen {
		p.panicf("start of hex escape (%d) is negative or greater than or equal to input length (%d)", start, inLen)
	}
	end := start + hexLen
	if end > inLen {
		p.panicf("end of hex escape (%d) is greater than input length (%d)", end, inLen)
	}
	hex := input[start:end]
	buf := make([]byte, utf8.UTFMax)
	var cp uint64
	for i := 0; i < hexLen; i += 2 {
		octet, errParse := strconv.ParseUint(string(hex[i:i+2]), 16, 8)
		if errParse != nil {
			p.panicf("invalid hex escape (%q) was not caught by lexer: %v", hex, errParse)
		}
		cp = (cp << 8) | octet
	}
	encodeLen := utf8.EncodeRune(buf, rune(cp))
	return buf[0:encodeLen]
}
func ( p * parser ) decodeHex ( input [ ] byte , start int , hexLen int ) [ ] byte { if hexLen <= 0 || hexLen > 8 || hexLen % 2 != 0 { p . panicf ( " " , hexLen ) } inLen := len ( input ) if start < 0 || start >= inLen { p . panicf ( " " , start , inLen ) } end := start + hexLen if end > inLen { p . panicf ( " " , end , inLen ) } hex := input [ start : end ] buf := make ( [ ] byte , utf8 . UTFMax ) var cp uint64 for i := 0 ; i < hexLen ; i += 2 { octet , errParse := strconv . ParseUint ( string ( hex [ i : i + 2 ] ) , 16 , 8 ) if errParse != nil { p . panicf ( " " , hex , errParse ) } cp = ( cp << 8 ) | octet } encodeLen := utf8 . EncodeRune ( buf , rune ( cp ) ) return buf [ 0 : encodeLen ] }
decodeHex takes a slice that is the input buffer and decodes it into a slice containing UTF-8 code units.
decodeHex takes a slice that is the input buffer and decodes it into a slice containing UTF - 8 code units .
// Length must be a power of two and no larger that size of uint32. // calling code must give us a proper slice... // Construct a working slice to decode with. // Decode the hex string into a UTF-32 scalar. // Now serialize back as UTF-8 code units.