package encoder

import (
	
	
)

// The names of a map whose keys may have the same name, of the v2 semantics, which a function, a method or the
// kind of its key writes. The names of a map which is not sorted are checked as they are written ( see
// appendMapKeyName ). The keys of a sorted map are sorted by their names, which puts the same names next to each
// other, and checked by OpMapKey as the entries are written in that order, when the end of the map is
// OpMapEndMayRepeatNames.

// SameMapName reports whether key, the name of an entry of a sorted map as it is encoded with a comma after it ( see
// MapItem ), is the name of the entry before it, prev, which is an error unless AllowDuplicateNamesOption.
func ( *RuntimeContext, ,  []byte) bool {
	return .Option.Flag&AllowDuplicateNamesOption == 0 && string() == string()
}

// DuplicateMapNameError returns the error of key, the name of an entry of a sorted map as it is encoded with a comma
// after it, which an entry before it has: out is the output before the name.
func (,  []byte) error {
	 := jsonstring.AppendUnescaped(nil, [1:len()-2])
	return &errors.TextError{Err: errors.ErrDuplicateName, Name: string(), Out: }
}

// stringStart returns where the string whose closing quote is at end starts: the quote before it which no odd
// number of backslashes precedes, which would escape it.
func stringStart( []byte,  int) int {
	for  :=  - 1;  >= 0; -- {
		if [] != '"' {
			continue
		}
		 := 0
		for  :=  - 1;  >= 0 && [] == '\\'; -- {
			++
		}
		if %2 == 0 {
			return 
		}
	}
	return 0
}

// stringEnd returns where the string which starts at start ends: its closing quote.
func stringEnd( []byte,  int) int {
	for  :=  + 1;  < len(); ++ {
		switch [] {
		case '\\':
			++
		case '"':
			return 
		}
	}
	return len() - 1
}

// memberNames returns where the names of the members of the object obj start: the object is compact and valid.
func memberNames( []byte) []int {
	var  []int
	 := 0
	 := false
	for  := 0;  < len(); ++ {
		switch [] {
		case '{', '[':
			++
			 = [] == '{' &&  == 1
		case '}', ']':
			--
		case ',':
			 =  == 1
		case '"':
			if  {
				 = append(, )
				 = false
			}
			 = stringEnd(, )
		}
	}
	return 
}