// Copyright 2017-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// This file is a Go translation and modification of MathJax 3.2.2 behavior.
// Source: ts/input/tex/ParseUtil.ts, readKeyval and keyvalOptions.

package tex

import 

// parseUtilKeyvalOptions collects the complete list before validating its own keys.
// The original readKeyval uses an ordinary JavaScript object: primitive
// assignments to __proto__ do not create an own property, and Object.keys
// enumerates array-index properties before other keys.
func parseUtilKeyvalOptions( string,  func(string) bool,  bool) (*ordered.Map[any], error) {
	 := ordered.New[any]()
	 := 
	for  != "" {
		, , ,  := empheqReadOptionValue(, "=,")
		if  != nil {
			return nil, 
		}
		 = 
		var  any = true
		if  == '=' {
			var  string
			, _, ,  = empheqReadOptionValue(, ",")
			if  != nil {
				return nil, 
			}
			switch  {
			case "true":
				 = true
			case "false":
				 = false
			default:
				 = 
			}
		} else if  == "" {
			continue
		}
		if  != "__proto__" {
			.Set(, )
		}
	}
	if  != nil {
		for ,  := range .JavaScriptKeys() {
			if !() {
				if  {
					return nil, texError("InvalidOption", "Invalid option: %s", )
				}
				.Delete()
			}
		}
	}
	return , nil
}