package gojay

import (
	
	
)

func ( *Decoder) () (rune, error) {
	 := 0
	 := rune(0)
	for ; (.cursor < .length || .read()) &&  < 4; .cursor++ {
		 := .data[.cursor]
		if  >= '0' &&  <= '9' {
			 = *16 + rune(-'0')
		} else if  >= 'a' &&  <= 'f' {
			 = *16 + rune(-'a'+10)
		} else if  >= 'A' &&  <= 'F' {
			 = *16 + rune(-'A'+10)
		} else {
			return 0, InvalidJSONError("Invalid unicode code point")
		}
		++
	}
	return , nil
}

func ( *Decoder) ( []byte,  byte) ([]byte, error) {
	switch  {
	case 't':
		 = append(, '\t')
	case 'n':
		 = append(, '\n')
	case 'r':
		 = append(, '\r')
	case 'b':
		 = append(, '\b')
	case 'f':
		 = append(, '\f')
	case '\\':
		 = append(, '\\')
	default:
		return nil, InvalidJSONError("Invalid JSON")
	}
	return , nil
}

func ( *Decoder) () ([]byte, error) {
	// get unicode after u
	,  := .getUnicode()
	if  != nil {
		return nil, 
	}
	// no error start making new string
	 := make([]byte, 16, 16)
	 := 0
	// check if code can be a surrogate utf16
	if utf16.IsSurrogate() {
		if .cursor >= .length && !.read() {
			return nil, .raiseInvalidJSONErr(.cursor)
		}
		 := .data[.cursor]
		if  != '\\' {
			 += utf8.EncodeRune(, )
			return [:], nil
		}
		.cursor++
		if .cursor >= .length && !.read() {
			return nil, .raiseInvalidJSONErr(.cursor)
		}
		 = .data[.cursor]
		if  != 'u' {
			 += utf8.EncodeRune(, )
			,  = .appendEscapeChar([:], )
			if  != nil {
				.err = 
				return nil, 
			}
			++
			.cursor++
			return [:], nil
		}
		.cursor++
		,  := .getUnicode()
		if  != nil {
			return nil, 
		}
		 := utf16.DecodeRune(, )
		if  == '\uFFFD' {
			 += utf8.EncodeRune(, )
			 += utf8.EncodeRune(, )
		} else {
			 += utf8.EncodeRune(, )
		}
		return [:], nil
	}
	 += utf8.EncodeRune(, )
	return [:], nil
}