// perform a binary search for the specified attribute inside an Object
//template<ValueLength offsetSize>
496292
func (s Slice) searchObjectKeyBinary(attribute string, ieBase ValueLength, n ValueLength, offsetSize ValueLength) (Slice, error) {
	useTranslator := attributeTranslator != nil
	vpackAssert(n > 0)

	l := ValueLength(0)
	r := ValueLength(n - 1)
	index := ValueLength(r / 2)

	for {
		offset := ValueLength(ieBase + index*offsetSize)
		key := Slice(s[readIntegerFixed(s[offset:], uint(offsetSize)):])

		var res int
		var err error
		if key.IsString() {
			res, err = key.CompareString(attribute)
			if err != nil {
				return nil, WithStack(err)
			}
		} else if key.IsSmallInt() || key.IsUInt() {
			// translate key
			if !useTranslator {
				// no attribute translator
				return nil, WithStack(NeedAttributeTranslatorError)
			}
			res, err = key.translateUnchecked().CompareString(attribute)
			if err != nil {
				return nil, WithStack(err)
			}
		} else {
			// invalid key
			return nil, nil
		}

		if res == 0 {
			// found. now return a Slice pointing at the value
			keySize, err := key.ByteSize()
			if err != nil {
				return nil, WithStack(err)
			}
			return Slice(key[keySize:]), nil
		}

		if res > 0 {
			if index == 0 {
				return nil, nil
			}
			r = index - 1
		} else {
			l = index + 1
		}
		if r < l {
			return nil, nil
		}

		// determine new midpoint
		index = l + ((r - l) / 2)
	}
}
70039
func GetAttrs(e Markup, f, val string) []*Attribute {

	var found []*Attribute

	for _, as := range e.Attributes() {
		if as.Name != f {
			continue
		}

		if val != "" {
			if !strings.Contains(as.Value, val) {
				continue
			}
		}

		found = append(found, as)
	}

	return found
}
622121
func attributeSuffixSelector(key, val string) Selector {
	return attributeSelector(key,
		func(s string) bool {
			if strings.TrimSpace(s) == "" {
				return false
			}
			return strings.HasSuffix(s, val)
		})
}
502244
func (attrs Attributes) GetOnlyAttributeValueBytes(oid asn1.ObjectIdentifier) (rv asn1.RawValue, err error) {
	var vals []AnySet
	if vals, err = attrs.GetValues(oid); err != nil {
		return
	}
	if len(vals) != 1 {
		err = ASN1Error{"bad attribute count"}
		return
	}
	if len(vals[0].Elements) != 1 {
		err = ASN1Error{"bad attribute element count"}
		return
	}

	return vals[0].Elements[0], nil
}
403763
func (c *Context) GetVertexAttrib(index, pname int) *js.Object {
	return c.Call("getVertexAttrib", index, pname)
}
119827
func (l *LinkDefinition) Attribute() *AttributeDefinition {
	p := l.Parent.ToObject()
	if p == nil {
		return nil
	}
	att, _ := p[l.Name]

	return att
}
782875
func (n *node) search(line string) *Template {
	separator := n.separator
	return n.recursiveSearch(strings.Split(line, separator))
}
206134
func ParseAttribute(input string) *Attribute {
	ll := len(input)
	if ll == 0 {
		return &Attribute{String: helper.StringToPtr(input)}
	}

	// Check if the string is a number ending with potential units
	var unit string
	numeric := input
	if unicode.IsLetter(rune(input[ll-1])) {
		// Try suffix matching
		for _, u := range lengthSortedUnits {
			if strings.HasSuffix(input, u) {
				unit = u
				break
			}
		}

		// Check if we know about the unit.
		if len(unit) != 0 {
			numeric = strings.TrimSpace(strings.TrimSuffix(input, unit))
		}
	}

	// Try to parse as an int
	i, err := strconv.ParseInt(numeric, 10, 64)
	if err == nil {
		return &Attribute{Int: helper.Int64ToPtr(i), Unit: unit}
	}

	// Try to parse as a float
	f, err := strconv.ParseFloat(numeric, 64)
	if err == nil {
		return &Attribute{Float: helper.Float64ToPtr(f), Unit: unit}
	}

	// Try to parse as a bool
	b, err := strconv.ParseBool(input)
	if err == nil {
		return &Attribute{Bool: helper.BoolToPtr(b)}
	}

	return &Attribute{String: helper.StringToPtr(input)}
}
844364
func attributeSubstringSelector(key, val string) Selector {
	return attributeSelector(key,
		func(s string) bool {
			if strings.TrimSpace(s) == "" {
				return false
			}
			return strings.Contains(s, val)
		})
}
193095
func arrayAttribute(a *design.AttributeDefinition) *design.AttributeDefinition {
	return a.Type.(*design.Array).ElemType
}
235697
func decodeAttr(attr *internal.Attr) (key string, value interface{}) {
	switch attr.Type {
	case attrTypeString:
		return attr.Key, attr.StringValue
	case attrTypeInt:
		return attr.Key, attr.IntValue
	case attrTypeBool:
		return attr.Key, attr.BoolValue
	case attrTypeFloat:
		return attr.Key, attr.FloatValue
	default:
		return attr.Key, nil
	}
}
788479
func ParseMatchAttributes(attrs, templateAttrs []Attribute) {
	for i, a := range attrs {
		for _, b := range templateAttrs {
			if a.Equals(b) {
				attrs[i] = b
			} else if a.GetName() == b.GetName() {
				attrs[i] = b
			}
		}
	}
}
391773
func attributeAndValueEquals(attr html.Attribute, attribute, value string) bool {
	return attr.Key == attribute && attr.Val == value
}
61336
func AttributeValue(sel interface{}, name string, value *string, ok *bool, opts ...QueryOption) Action {
	if value == nil {
		panic("value cannot be nil")
	}

	return QueryAfter(sel, func(ctx context.Context, nodes ...*cdp.Node) error {
		if len(nodes) < 1 {
			return errors.New("expected at least one element")
		}

		nodes[0].RLock()
		defer nodes[0].RUnlock()

		attrs := nodes[0].Attributes
		for i := 0; i < len(attrs); i += 2 {
			if attrs[i] == name {
				*value = attrs[i+1]
				if ok != nil {
					*ok = true
				}
				return nil
			}
		}

		if ok != nil {
			*ok = false
		}

		return nil
	}, opts...)
}
205846
func (b *BinaryAttribute) Equals(other Attribute) bool {
	if a, ok := other.(*BinaryAttribute); !ok {
		return false
	} else {
		return a.Name == b.Name
	}
}
467094
func attributeDashmatchSelector(key, val string) Selector {
	return attributeSelector(key,
		func(s string) bool {
			if s == val {
				return true
			}
			if len(s) <= len(val) {
				return false
			}
			if s[:len(val)] == val && s[len(val)] == '-' {
				return true
			}
			return false
		})
}
675464
func GetAttributeValue(entry *ldap.Entry, attributes []string) string {
	for _, k := range attributes {
		// Ignore empty attributes
		if len(k) == 0 {
			continue
		}
		// Special-case DN, since it's not an attribute
		if strings.ToLower(k) == "dn" {
			return entry.DN
		}
		// Otherwise get an attribute and return it if present
		if v := entry.GetAttributeValue(k); len(v) > 0 {
			return v
		}
	}
	return ""
}