-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool.go
56 lines (46 loc) · 785 Bytes
/
bool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package djson
import "fmt"
type Booler interface {
Bool() bool
}
type Bool bool
func (b Bool) Bool() bool {
return bool(b)
}
func (b Bool) String() string {
if b {
return "true"
}
return "false"
}
func (b Bool) Int() (int64, error) {
if b {
return 1, nil
}
return 0, nil
}
func (b Bool) Float() (float64, error) {
if b {
return 1, nil
}
return 0, nil
}
func (b Bool) Bytes() []byte {
if b {
return []byte{'t', 'r', 'u', 'e'}
}
return []byte{'f', 'a', 'l', 's', 'e'}
}
func (b Bool) Copy() Bool {
return b
}
func (b Bool) Compare(val Value) (ret int, err error) {
if val.Type != ValueBool {
err = fmt.Errorf("can't compare bool with [%s]", val.TypeName())
return
}
bi, _ := b.Int()
vi, _ := val.Value.(Inter).Int()
ret = int(bi - vi)
return
}