// lexArrayValue consumes one value in an array. It assumes that '[' or ','
// have already been consumed. All whitespace and newlines are ignored.
508768
func lexArrayValue(lx *lexer) stateFn {
	r := lx.next()
	switch {
	case isWhitespace(r) || isNL(r):
		return lexSkip(lx, lexArrayValue)
	case r == commentStart:
		lx.push(lexArrayValue)
		return lexCommentStart
	case r == comma:
		return lx.errorf("unexpected comma")
	case r == arrayEnd:
		// NOTE(caleb): The spec isn't clear about whether you can have
		// a trailing comma or not, so we'll allow it.
		return lexArrayEnd
	}

	lx.backup()
	lx.push(lexArrayValueEnd)
	return lexValue
}
870276
func NewArrayValue(unindexed ...bool) Value {
	return Value{Array, nil, optionalBool(unindexed, false)}
}
345096
func (e *Encoder) encodeArray(valueField reflect.Value, key string) error {
	adaptersCnt := 0
	devicesCnt := 0

	for i := 0; i < valueField.Len(); i++ {
		switch key {
		case "ide":
			if i >= (MAX_IDE_ADAPTERS * MAX_IDE_DEVICES_PER_ADAPTER) {
				return nil
			}

			if devicesCnt >= MAX_IDE_DEVICES_PER_ADAPTER {
				adaptersCnt++
				devicesCnt = 0
			}

			e.parentKey = fmt.Sprintf("%s%d:%d", key, adaptersCnt, devicesCnt)
			devicesCnt++

		case "scsi":
			if i >= (MAX_SCSI_ADAPTERS * MAX_SCSI_DEVICES_PER_ADAPTER) {
				return nil
			}

			if devicesCnt >= MAX_SCSI_DEVICES_PER_ADAPTER {
				adaptersCnt++
				devicesCnt = 0
			}

			val := valueField.Index(i).FieldByName("VirtualDev")
			if !isEmptyValue(val) {
				e.parentKey = fmt.Sprintf("%s%d", key, adaptersCnt)
			} else {
				e.parentKey = fmt.Sprintf("%s%d:%d", key, adaptersCnt, devicesCnt)
				devicesCnt++
			}
		case "sata":
			if i >= (MAX_SATA_ADAPTERS * MAX_SATA_DEVICES_PER_ADAPTER) {
				return nil
			}

			if devicesCnt >= MAX_SATA_DEVICES_PER_ADAPTER {
				adaptersCnt++
				devicesCnt = 0
			}

			e.parentKey = fmt.Sprintf("%s%d:%d", key, adaptersCnt, devicesCnt)
			devicesCnt++
		case "usb":
			if i >= MAX_USB_ADAPTERS*MAX_USB_DEVICES {
				return nil
			}

			e.parentKey = fmt.Sprintf("%s:%d", key, devicesCnt)
			devicesCnt++
		case "ethernet":
			if i >= MAX_VNICS {
				return nil
			}
			e.parentKey = key + strconv.Itoa(i)
		default:
			e.parentKey = key + strconv.Itoa(i)
		}

		err := e.encode(valueField.Index(i))
		if err != nil {
			return err
		}
	}
	return nil
}
1016242
func (ia Int64Array) Value() (driver.Value, error) {
	if !ia.Valid {
		return nil, nil
	}

	return Int64ArrayValue(ia.Int64Array)
}
795587
func lexBool(lx *lexer) stateFn {
	var rs []rune
	for {
		r := lx.next()
		if !unicode.IsLetter(r) {
			lx.backup()
			break
		}
		rs = append(rs, r)
	}
	s := string(rs)
	switch s {
	case "true", "false":
		lx.emit(itemBool)
		return lx.pop()
	}
	return lx.errorf("expected value but found %q instead", s)
}
20131
func (c *ConfigFile) MustValueArray(section, key, delim string) []string {
	val, err := c.GetValue(section, key)
	if err != nil || len(val) == 0 {
		return []string{}
	}

	vals := strings.Split(val, delim)
	for i := range vals {
		vals[i] = strings.TrimSpace(vals[i])
	}
	return vals
}
1114706
func (m *Marshaler) marshalValue(out *errWriter, prop *proto.Properties, v reflect.Value, indent string) error {

	var err error
	v = reflect.Indirect(v)

	// Handle repeated elements.
	if v.Type() != byteArrayType && v.Kind() == reflect.Slice {
		out.write("[")
		comma := ""
		for i := 0; i < v.Len(); i++ {
			sliceVal := v.Index(i)
			out.write(comma)
			if m.Indent != "" {
				out.write("\n")
				out.write(indent)
				out.write(m.Indent)
				out.write(m.Indent)
			}
			m.marshalValue(out, prop, sliceVal, indent+m.Indent)
			comma = ","
		}
		if m.Indent != "" {
			out.write("\n")
			out.write(indent)
			out.write(m.Indent)
		}
		out.write("]")
		return out.err
	}

	// Handle enumerations.
	if (!m.EnumsAsInts || m.EnumsAsSimpleStrings) && prop.Enum != "" {
		var enumStr string
		// Unknown enum values will are stringified by the proto library as their
		// value. Such values should _not_ be quoted or they will be interpreted
		// as an enum string instead of their value.
		if m.EnumsAsSimpleStrings {
			obj, ok := v.Interface().(simpleStringer)
			if ok {
				enumStr = obj.SimpleString()
			} else {
				enumStr = v.Interface().(fmt.Stringer).String()
			}
		} else {
			enumStr = v.Interface().(fmt.Stringer).String()
		}
		var valStr string
		if v.Kind() == reflect.Ptr {
			valStr = strconv.Itoa(int(v.Elem().Int()))
		} else {
			valStr = strconv.Itoa(int(v.Int()))
		}
		isKnownEnum := enumStr != valStr
		if isKnownEnum {
			out.write(`"`)
		}
		out.write(enumStr)
		if isKnownEnum {
			out.write(`"`)
		}
		return out.err
	}

	// Handle nested messages.
	if v.Kind() == reflect.Struct {
		return m.marshalObject(out, v.Addr().Interface().(proto.Message), indent+m.Indent)
	}

	// Handle maps.
	// Since Go randomizes map iteration, we sort keys for stable output.
	if v.Kind() == reflect.Map {
		out.write(`{`)
		keys := v.MapKeys()
		sort.Sort(mapKeys(keys))
		for i, k := range keys {
			if i > 0 {
				out.write(`,`)
			}
			if m.Indent != "" {
				out.write("\n")
				out.write(indent)
				out.write(m.Indent)
				out.write(m.Indent)
			}

			b, err := json.Marshal(k.Interface())
			if err != nil {
				return err
			}
			s := string(b)

			// If the JSON is not a string value, encode it again to make it one.
			if !strings.HasPrefix(s, `"`) {
				b, err := json.Marshal(s)
				if err != nil {
					return err
				}
				s = string(b)
			}

			out.write(s)
			out.write(`:`)
			if m.Indent != "" {
				out.write(` `)
			}

			if err := m.marshalValue(out, prop, v.MapIndex(k), indent+m.Indent); err != nil {
				return err
			}
		}
		if m.Indent != "" {
			out.write("\n")
			out.write(indent)
			out.write(m.Indent)
		}
		out.write(`}`)
		return out.err
	}

	// Default handling defers to the encoding/json library.
	b, err := json.Marshal(v.Interface())
	if err != nil {
		return err
	}
	needToQuote := string(b[0]) != `"` && (v.Kind() == reflect.Int64 || v.Kind() == reflect.Uint64)
	if needToQuote {
		out.write(`"`)
	}
	out.write(string(b))
	if needToQuote {
		out.write(`"`)
	}
	return out.err
}
584379
func (n *FilteredString) ParseValue(val string) {
	if val == "" {
		n.IsSet = false
		n.Value = ""
		return
	}

	n.IsSet = true

	switch val {
	case "null", "default":
		n.Value = ""
	default:
		n.Value = val
	}
}
464265
func lexMapValue(lx *lexer) stateFn {
	r := lx.next()
	switch {
	case unicode.IsSpace(r):
		return lexSkip(lx, lexMapValue)
	case r == mapValTerm:
		return lx.errorf("Unexpected map value terminator %q.", mapValTerm)
	case r == mapEnd:
		return lexSkip(lx, lexMapEnd)
	}
	lx.backup()
	lx.push(lexMapValueEnd)
	return lexValue
}
815192
func Lex(r io.Reader) Lexer {
	lexer := lexWithScanner(r, &scanner.Scanner{})
	lexer.scanner.Error = func(s *scanner.Scanner, msg string) {
		// This is to support single quoted strings. Hacky.
		if !strings.HasSuffix(msg, "char literal") {
			lexer.err = Errorf(Position(lexer.scanner.Pos()), msg)
		}
	}
	return lexer
}
488931
func marshalValue(options *Options, v reflect.Value) (interface{}, error) {
	// return nil on nil pointer struct fields
	if !v.IsValid() || !v.CanInterface() {
		return nil, nil
	}
	val := v.Interface()

	if marshaller, ok := val.(Marshaller); ok {
		return marshaller.Marshal(options)
	}
	// types which are e.g. structs, slices or maps and implement one of the following interfaces should not be
	// marshalled by sheriff because they'll be correctly marshalled by json.Marshal instead.
	// Otherwise (e.g. net.IP) a byte slice may be output as a list of uints instead of as an IP string.
	switch val.(type) {
	case json.Marshaler, encoding.TextMarshaler, fmt.Stringer:
		return val, nil
	}
	k := v.Kind()

	if k == reflect.Ptr {
		v = v.Elem()
		val = v.Interface()
		k = v.Kind()
	}

	if k == reflect.Interface || k == reflect.Struct {
		return Marshal(options, val)
	}
	if k == reflect.Slice {
		l := v.Len()
		dest := make([]interface{}, l)
		for i := 0; i < l; i++ {
			d, err := marshalValue(options, v.Index(i))
			if err != nil {
				return nil, err
			}
			dest[i] = d
		}
		return dest, nil
	}
	if k == reflect.Map {
		mapKeys := v.MapKeys()
		if len(mapKeys) == 0 {
			return nil, nil
		}
		if mapKeys[0].Kind() != reflect.String {
			return nil, MarshalInvalidTypeError{t: mapKeys[0].Kind(), data: val}
		}
		dest := make(map[string]interface{})
		for _, key := range mapKeys {
			d, err := marshalValue(options, v.MapIndex(key))
			if err != nil {
				return nil, err
			}
			dest[key.Interface().(string)] = d
		}
		return dest, nil
	}
	return val, nil
}
646829
func compileValues(a *[]interface{}) {
	for i, x := range *a {
		if str, ok := x.(string); ok {
			(*a)[i] = compile(str)
		}
	}
}
849604
func (schema *Schema) arrayOfEnumValuesValue(v interface{}) *[]SchemaEnumValue {
	a := make([]SchemaEnumValue, 0)
	switch v := v.(type) {
	default:
		fmt.Printf("arrayOfEnumValuesValue: unexpected type %T\n", v)
	case []interface{}:
		for _, v2 := range v {
			switch v2 := v2.(type) {
			default:
				fmt.Printf("arrayOfEnumValuesValue: unexpected type %T\n", v2)
			case string:
				a = append(a, SchemaEnumValue{String: &v2})
			case bool:
				a = append(a, SchemaEnumValue{Bool: &v2})
			}
		}
	}
	return &a
}
385621
func lexTopValueEnd(lx *lexer) stateFn {
	r := lx.next()
	switch {
	case r == commentHashStart:
		// a comment will read to a new line for us.
		lx.push(lexTop)
		return lexCommentStart
	case r == commentSlashStart:
		rn := lx.next()
		if rn == commentSlashStart {
			lx.push(lexTop)
			return lexCommentStart
		}
		lx.backup()
		fallthrough
	case isWhitespace(r):
		return lexTopValueEnd
	case isNL(r) || r == eof || r == optValTerm || r == topOptValTerm || r == topOptTerm:
		lx.ignore()
		return lexTop
	}
	return lx.errorf("Expected a top-level value to end with a new line, "+
		"comment or EOF, but got '%v' instead.", r)
}
87093
func (tokenizer *Tokenizer) parseNamespacedValue() string {
	start := tokenizer.scanner.Index()
	tokenizer.scanner.Advance()
	for tokenizer.CanRead() {
		if tokenizer.isNamespacedChar() {
			tokenizer.scanner.Advance()
			continue
		} else {
			break
		}
	}
	return tokenizer.scanner.SubstringFrom(start)
}
802196
func lexInlineTableValue(lx *lexer) stateFn {
	r := lx.next()
	switch {
	case isWhitespace(r):
		return lexSkip(lx, lexInlineTableValue)
	case isNL(r):
		return lx.errorf("newlines not allowed within inline tables")
	case r == commentStart:
		lx.push(lexInlineTableValue)
		return lexCommentStart
	case r == comma:
		return lx.errorf("unexpected comma")
	case r == inlineTableEnd:
		return lexInlineTableEnd
	}
	lx.backup()
	lx.push(lexInlineTableValueEnd)
	return lexKeyStart
}
754093
func (t Type) IsArray() bool {
	if t.IsJSONType() {
		return false
	}
	return t.TypeString() == arrayType || strings.HasSuffix(t.TypeString(), "[]")
}