// TryToInt casts an empty interface to an int.
502368
func TryToInt(i interface{}) (r int, err error) {
	switch t := i.(type) {
	case nil:
		r = 0
	case int:
		r = t
	case *int:
		r = *t
	case int8:
		r = int(t)
	case int16:
		r = int(t)
	case int32:
		r = int(t)
	case int64:
		r = int(t)
	case uint:
		r = int(t)
	case uint8:
		r = int(t)
	case uint16:
		r = int(t)
	case uint32:
		r = int(t)
	case uint64:
		r = int(t)
	case float32:
		r = int(t)
	case float64:
		r = int(t)
	case bool:
		if t {
			r = 1
		}
	case string:
		r, err = strconv.Atoi(t)
	default:
		err = castError(i, "int")
	}
	return
}
831481
func Int(input interface{}) (output int64, err error) {

	switch castValue := input.(type) {
	case Inter:
		output = castValue.Int()
		return
	case string:
		output, err = strconv.ParseInt(castValue, 10, 64)
		return
	case []byte:
		output, err = strconv.ParseInt(string(castValue), 10, 64)
		return
	case int:
		output = int64(castValue)
		return
	case int8:
		output = int64(castValue)
		return
	case int16:
		output = int64(castValue)
		return
	case int32:
		output = int64(castValue)
		return
	case int64:
		output = int64(castValue)
		return
	case uint:
		output = int64(castValue)
		return
	case uint8:
		output = int64(castValue)
		return
	case uint16:
		output = int64(castValue)
		return
	case uint32:
		output = int64(castValue)
		return
	case uint64:
		output = int64(castValue)
		return
	case float32:
		output = int64(castValue)
		return
	case float64:
		output = int64(castValue)
		return
	case bool:
		output = int64(0)
		if castValue {
			output = int64(1)
		}
		return
	case nil:
		output = int64(0)
		return
	default:
		err = NewCastError("Could not convert to int")
	}
	return
}
1124253
func TryToTime(i interface{}) (t time.Time, err error) {
	switch v := i.(type) {
	case time.Time:
		t = v
	case *time.Time:
		t = *v
	case string:
		t, err = StringToTime(v)
	case *string:
		t, err = StringToTime(*v)
	default:
		err = castError(i, "time.Time")
	}
	return
}
899610
func (m *Mutex) TryLock() bool {
	v := atomic.LoadInt32(&m.v)
	if v <= 0 {
		return false
	}
	return atomic.CompareAndSwapInt32(&m.v, 1, 0)
}
415108
func TryToUint64(i interface{}) (r uint64, err error) {
	switch t := i.(type) {
	case nil:
		r = 0
	case uint:
		r = uint64(t)
	case uint8:
		r = uint64(t)
	case uint16:
		r = uint64(t)
	case uint32:
		r = uint64(t)
	case uint64:
		r = uint64(t)
	case *uint64:
		r = *t
	case int:
		r = uint64(t)
	case int8:
		r = uint64(t)
	case int16:
		r = uint64(t)
	case int32:
		r = uint64(t)
	case int64:
		r = uint64(t)
	case float32:
		r = uint64(t)
	case float64:
		r = uint64(t)
	case bool:
		if t {
			r = 1
		}
	case string:
		r, err = strconv.ParseUint(t, 10, 64)
	default:
		err = castError(i, "uint64")
	}
	return
}
1007093
func TryToUint32(i interface{}) (r uint32, err error) {
	switch t := i.(type) {
	case nil:
		r = 0
	case uint:
		r = uint32(t)
	case uint8:
		r = uint32(t)
	case uint16:
		r = uint32(t)
	case uint32:
		r = t
	case *uint32:
		r = *t
	case uint64:
		r = uint32(t)
	case int:
		r = uint32(t)
	case int8:
		r = uint32(t)
	case int16:
		r = uint32(t)
	case int32:
		r = uint32(t)
	case int64:
		r = uint32(t)
	case float32:
		r = uint32(t)
	case float64:
		r = uint32(t)
	case bool:
		if t {
			r = 1
		}
	case string:
		var v uint64
		if v, err = strconv.ParseUint(t, 10, 32); err == nil {
			r = uint32(v)
		}
	default:
		err = castError(i, "uint32")
	}
	return
}
568865
func TryToInt32Slice(i interface{}) (r []int32, err error) {
	switch v := i.(type) {
	case []int:
		r = make([]int32, len(v))
		for index, value := range v {
			r[index] = int32(value)
		}
	case []int32:
		r = v
	case *[]int32:
		r = *v
	case []int64:
		r = make([]int32, len(v))
		for index, value := range v {
			r[index] = int32(value)
		}
	case []string:
		r = make([]int32, len(v))
		for index, value := range v {
			r[index], err = TryToInt32(value)
			if err != nil {
				return
			}
		}
	default:
		err = castError(i, "[]int32")
	}
	return
}
421902
func NumberToInt(x Value) (Int, error) {
	switch x := x.(type) {
	case Int:
		return x, nil
	case Float:
		f := float64(x)
		if math.IsInf(f, 0) {
			return zero, fmt.Errorf("cannot convert float infinity to integer")
		} else if math.IsNaN(f) {
			return zero, fmt.Errorf("cannot convert float NaN to integer")
		}
		return finiteFloatToInt(x), nil

	}
	return zero, fmt.Errorf("cannot convert %s to int", x.Type())
}
852934
func (t *Trie) TryGet(key []byte) ([]byte, error) {
	key = keybytesToHex(key)
	value, newroot, didResolve, err := t.tryGet(t.root, key, 0)
	if err == nil && didResolve {
		t.root = newroot
	}
	return value, err
}
310875
func TryToFloat64(i interface{}) (r float64, err error) {
	switch t := i.(type) {
	case float32:
		r = float64(t)
	case float64:
		r = t
	case *float64:
		r = *t
	case int:
		r = float64(t)
	case int8:
		r = float64(t)
	case int16:
		r = float64(t)
	case int32:
		r = float64(t)
	case int64:
		r = float64(t)
	case bool:
		if t {
			r = 1
		}
	case string:
		r, err = strconv.ParseFloat(t, 64)
	default:
		err = castError(i, "float64")
	}
	return
}
759843
func (fsm *MapInputSource) Int(name string) (int, error) {
	otherGenericValue, exists := fsm.valueMap[name]
	if exists {
		otherValue, isType := otherGenericValue.(int)
		if !isType {
			return 0, incorrectTypeForFlagError(name, "int", otherGenericValue)
		}
		return otherValue, nil
	}
	nestedGenericValue, exists := nestedVal(name, fsm.valueMap)
	if exists {
		otherValue, isType := nestedGenericValue.(int)
		if !isType {
			return 0, incorrectTypeForFlagError(name, "int", nestedGenericValue)
		}
		return otherValue, nil
	}

	return 0, nil
}
172440
func (v *Validator) TypeInt(field string) *ValidationResult {
	if _, err := strconv.Atoi(v.data.Get(field)); err != nil {
		return v.addTypeError(field, "integer")
	} else {
		return validationOk
	}
}
870547
func (d *MyDecimal) ToInt() (int64, error) {
	var x int64
	wordIdx := 0
	for i := d.digitsInt; i > 0; i -= digitsPerWord {
		y := x
		/*
		   Attention: trick!
		   we're calculating -|from| instead of |from| here
		   because |LONGLONG_MIN| > LONGLONG_MAX
		   so we can convert -9223372036854775808 correctly
		*/
		x = x*wordBase - int64(d.wordBuf[wordIdx])
		wordIdx++
		if y < math.MinInt64/wordBase || x > y {
			/*
			   the decimal is bigger than any possible integer
			   return border integer depending on the sign
			*/
			if d.negative {
				return math.MinInt64, ErrOverflow
			}
			return math.MaxInt64, ErrOverflow
		}
	}
	/* boundary case: 9223372036854775808 */
	if !d.negative && x == math.MinInt64 {
		return math.MaxInt64, ErrOverflow
	}
	if !d.negative {
		x = -x
	}
	for i := d.digitsFrac; i > 0; i -= digitsPerWord {
		if d.wordBuf[wordIdx] != 0 {
			return x, ErrTruncated
		}
		wordIdx++
	}
	return x, nil
}
303599
func stringValToInt(val string) (int, error) {
	parsedField, err := strconv.Atoi(val)
	if err != nil {
		splitErr := strings.Split(err.Error(), ": ")
		errStr := splitErr[len(splitErr)-1]
		// return a value of zero and the error encountered during string parsing
		return 0, fmt.Errorf("Value '%v' cannot be parsed as an integer (%v)", val, errStr)
	}
	// return the integer equivalent of the input string and a nil error (indicating success)
	return parsedField, nil
}
215090
func (b *ByteBuf) PeekInt(offset int) (int, error) {
	if b.Readable() < 4+offset {
		return 0, io.ErrShortBuffer
	}

	start := b.readerIndex + offset
	return Byte2Int(b.buf[start : start+4]), nil
}
257853
func ToInt(n int) [4]byte {
	s := make([]byte, 4)
	binary.LittleEndian.PutUint32(s, uint32(n))
	a := [4]byte{}
	copy(a[:], s[:4])
	return a
}
372987
func valToInt(i interface{}) (int, bool) {
	i64, ok := valToInt64(i)
	if !ok {
		return -1, false
	}
	if i64 > MaxInt || i64 < MinInt {
		return -1, false
	}
	return int(i64), true
}