package jsoniter

import (
	
	
)

// ReadObject read one field from object.
// If object ended, returns empty string.
// Otherwise, returns the field name.
func ( *Iterator) () ( string) {
	 := .nextToken()
	switch  {
	case 'n':
		.skipThreeBytes('u', 'l', 'l')
		return "" // null
	case '{':
		 = .nextToken()
		if  == '"' {
			.unreadByte()
			 := .ReadString()
			 = .nextToken()
			if  != ':' {
				.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{}))
			}
			return 
		}
		if  == '}' {
			return "" // end of object
		}
		.ReportError("ReadObject", `expect " after {, but found `+string([]byte{}))
		return
	case ',':
		 := .ReadString()
		 = .nextToken()
		if  != ':' {
			.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{}))
		}
		return 
	case '}':
		return "" // end of object
	default:
		.ReportError("ReadObject", fmt.Sprintf(`expect { or , or } or n, but found %s`, string([]byte{})))
		return
	}
}

// CaseInsensitive
func ( *Iterator) () int64 {
	 := int64(0x811c9dc5)
	 := .nextToken()
	if  != '"' {
		.ReportError("readFieldHash", `expect ", but found `+string([]byte{}))
		return 0
	}
	for {
		for  := .head;  < .tail; ++ {
			// require ascii string and no escape
			 := .buf[]
			if  == '\\' {
				.head = 
				for ,  := range .readStringSlowPath() {
					if 'A' <=  &&  <= 'Z' && !.cfg.caseSensitive {
						 += 'a' - 'A'
					}
					 ^= int64()
					 *= 0x1000193
				}
				 = .nextToken()
				if  != ':' {
					.ReportError("readFieldHash", `expect :, but found `+string([]byte{}))
					return 0
				}
				return 
			}
			if  == '"' {
				.head =  + 1
				 = .nextToken()
				if  != ':' {
					.ReportError("readFieldHash", `expect :, but found `+string([]byte{}))
					return 0
				}
				return 
			}
			if 'A' <=  &&  <= 'Z' && !.cfg.caseSensitive {
				 += 'a' - 'A'
			}
			 ^= int64()
			 *= 0x1000193
		}
		if !.loadMore() {
			.ReportError("readFieldHash", `incomplete field name`)
			return 0
		}
	}
}

func calcHash( string,  bool) int64 {
	if ! {
		 = strings.ToLower()
	}
	 := int64(0x811c9dc5)
	for ,  := range []byte() {
		 ^= int64()
		 *= 0x1000193
	}
	return int64()
}

// ReadObjectCB read object with callback, the key is ascii only and field name not copied
func ( *Iterator) ( func(*Iterator, string) bool) bool {
	 := .nextToken()
	var  string
	if  == '{' {
		if !.incrementDepth() {
			return false
		}
		 = .nextToken()
		if  == '"' {
			.unreadByte()
			 = .ReadString()
			 = .nextToken()
			if  != ':' {
				.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{}))
			}
			if !(, ) {
				.decrementDepth()
				return false
			}
			 = .nextToken()
			for  == ',' {
				 = .ReadString()
				 = .nextToken()
				if  != ':' {
					.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{}))
				}
				if !(, ) {
					.decrementDepth()
					return false
				}
				 = .nextToken()
			}
			if  != '}' {
				.ReportError("ReadObjectCB", `object not ended with }`)
				.decrementDepth()
				return false
			}
			return .decrementDepth()
		}
		if  == '}' {
			return .decrementDepth()
		}
		.ReportError("ReadObjectCB", `expect " after {, but found `+string([]byte{}))
		.decrementDepth()
		return false
	}
	if  == 'n' {
		.skipThreeBytes('u', 'l', 'l')
		return true // null
	}
	.ReportError("ReadObjectCB", `expect { or n, but found `+string([]byte{}))
	return false
}

// ReadMapCB read map with callback, the key can be any string
func ( *Iterator) ( func(*Iterator, string) bool) bool {
	 := .nextToken()
	if  == '{' {
		if !.incrementDepth() {
			return false
		}
		 = .nextToken()
		if  == '"' {
			.unreadByte()
			 := .ReadString()
			if .nextToken() != ':' {
				.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{}))
				.decrementDepth()
				return false
			}
			if !(, ) {
				.decrementDepth()
				return false
			}
			 = .nextToken()
			for  == ',' {
				 = .ReadString()
				if .nextToken() != ':' {
					.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{}))
					.decrementDepth()
					return false
				}
				if !(, ) {
					.decrementDepth()
					return false
				}
				 = .nextToken()
			}
			if  != '}' {
				.ReportError("ReadMapCB", `object not ended with }`)
				.decrementDepth()
				return false
			}
			return .decrementDepth()
		}
		if  == '}' {
			return .decrementDepth()
		}
		.ReportError("ReadMapCB", `expect " after {, but found `+string([]byte{}))
		.decrementDepth()
		return false
	}
	if  == 'n' {
		.skipThreeBytes('u', 'l', 'l')
		return true // null
	}
	.ReportError("ReadMapCB", `expect { or n, but found `+string([]byte{}))
	return false
}

func ( *Iterator) () bool {
	 := .nextToken()
	if  == '{' {
		 = .nextToken()
		if  == '}' {
			return false
		}
		.unreadByte()
		return true
	} else if  == 'n' {
		.skipThreeBytes('u', 'l', 'l')
		return false
	}
	.ReportError("readObjectStart", "expect { or n, but found "+string([]byte{}))
	return false
}

func ( *Iterator) () ( []byte) {
	 := .ReadStringAsSlice()
	if .skipWhitespacesWithoutLoadMore() {
		if  == nil {
			 = make([]byte, len())
			copy(, )
		}
		if !.loadMore() {
			return
		}
	}
	if .buf[.head] != ':' {
		.ReportError("readObjectFieldAsBytes", "expect : after object field, but found "+string([]byte{.buf[.head]}))
		return
	}
	.head++
	if .skipWhitespacesWithoutLoadMore() {
		if  == nil {
			 = make([]byte, len())
			copy(, )
		}
		if !.loadMore() {
			return
		}
	}
	if  == nil {
		return 
	}
	return 
}