// TryToBool casts an empty interface to a bool.
516443
func TryToBool(i interface{}) (b bool, err error) {
	switch v := i.(type) {
	case nil:
	case bool:
		b = v
	case *bool:
		b = *v
	case string:
		b, err = strconv.ParseBool(v)
	case *string:
		b, err = strconv.ParseBool(*v)
	case int, int8, int16, int32, int64:
		b = v != 0
	default:
		err = castError(i, "bool")
	}
	return
}
434070
func (s *AttributeValue) SetBOOL(v bool) *AttributeValue {
	s.BOOL = &v
	return s
}
453828
func (a *Array) Bool(b bool) *Array {
	a.buf = enc.AppendBool(enc.AppendArrayDelim(a.buf), b)
	return a
}
488144
func ParseBool(value string) (bool, error) {
	switch strings.ToLower(value) {
	case "yes", "yeah", "y", "true", "1", "on":
		return true, nil
	case "no", "nope", "n", "false", "0", "off":
		return false, nil
	default:
		return false, trace.BadParameter("unsupported value: %q", value)
	}
}
1081167
func NewBool(val bool, p *bool) *Bool {
	*p = val
	return (*Bool)(p)
}
879544
func (stream *Stream) WriteBool(val bool) {
	if val {
		stream.WriteTrue()
	} else {
		stream.WriteFalse()
	}
}
715447
func (c *IniConfigContainer) DefaultBool(key string, defaultval bool) bool {
	v, err := c.Bool(key)
	if err != nil {
		return defaultval
	}
	return v
}
399149
func ParseBool(s string) (bool, error) {
	v, err := boolParser.Parse(s)
	if err != nil {
		return false, err
	}
	return v.(bool), nil
}
849590
func ToBool(in interface{}) (bool, error) {
	switch val := in.(type) {
	case string:
		sval, err := strconv.ParseBool(val)
		if err != nil {
			return false, ErrBadType
		}
		return sval, nil
	default:
		value, err := cast.ToBoolE(val)
		if err != nil {
			return false, ErrBadType
		}
		return value, nil
	}
}
483920
func (c *Config) GetBool(s string) bool {
	return c.config.GetBool(s)
}
291850
func CastToBool(value interface{}) (bool, bool) {
	casted, ok := value.(bool)

	if !ok {
		castedStr := CastToString(value)

		castedBool, err := ParseBool(castedStr)
		if err != nil {
			return false, false
		}

		casted = castedBool
	}

	return casted, true
}
1103609
func ToBool(in interface{}) bool {
	if b, ok := in.(bool); ok {
		return b
	}

	if str, ok := in.(string); ok {
		str = strings.ToLower(str)
		switch str {
		case "1", "t", "true", "yes":
			return true
		default:
			return strToFloat64(str) == 1
		}
	}

	val := reflect.Indirect(reflect.ValueOf(in))
	switch val.Kind() {
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		return val.Int() == 1
	case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
		return val.Uint() == 1
	case reflect.Float32, reflect.Float64:
		return val.Float() == 1
	default:
		return false
	}
}
566590
func (context *BaseContext) GetBool(
	key string, defaultValue ...bool) bool {
	if value, ok := context.userData[key]; ok {
		if value, ok := value.(bool); ok {
			return value
		}
	}
	if len(defaultValue) > 0 {
		return defaultValue[0]
	}
	return false
}
122815
func ParseBool(s string) bool {
	b, err := strconv.ParseBool(s)
	if err != nil {
		return false
	}

	return b
}
463517
func ValueToBool(val Value) (bool, bool) {
	if val == nil || val.Nil() || val.Err() {
		return false, false
	}
	switch v := val.(type) {
	case NumericValue:
		iv := v.Int()
		if iv == 0 {
			return false, true
		} else if iv == 1 {
			return true, true
		} else {
			return false, false
		}
	case StringValue:
		bv, err := strconv.ParseBool(v.Val())
		if err != nil {
			return false, false
		}
		return bv, true
	case BoolValue:
		return v.Val(), true
	}
	return false, false
}
702606
func (me *DefaultAdapter) LiteralBool(buf *SqlBuilder, b bool) error {
	if buf.IsPrepared {
		return me.PlaceHolderSql(buf, b)
	}
	if b {
		buf.Write(me.True)
	} else {
		buf.Write(me.False)
	}
	return nil
}
140310
func NewBoolByInterface(i interface{}) (Bool, error) {

	t := reflect.TypeOf(i)
	val := reflect.ValueOf(i)
	if val.Kind() == reflect.Ptr {
		val = val.Elem()
	}

	if t.Name() == "Bool" {
		if b, ok := (val.Interface()).(Bool); ok {
			return b, nil
		}
	}

	switch val.Kind() {

	case reflect.Bool:
		return NewBool((val.Interface()).(bool)), nil

	case reflect.Uint8:
		return Bool((val.Interface()).(byte)), nil

	case reflect.String:
		if b, err := strconv.ParseBool((val.Interface()).(string)); err == nil {
			return NewBool(b), nil
		}

	case reflect.Slice:
		v := val.Index(0)
		if b, ok := (v.Interface()).(byte); ok {
			return Bool(b), nil
		}
	}

	return False, errors.New("unsupported type")
}