-
Notifications
You must be signed in to change notification settings - Fork 2
/
string.go
60 lines (49 loc) · 1.01 KB
/
string.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
57
58
59
60
package types
import (
"fmt"
"github.com/cstockton/go-conv"
)
type String string
func (i String) String() string {
return string(i)
}
func (i String) Equals(other TypedValue) bool {
if i.Kind() == other.Kind() {
return i == other
}
return false
}
func (i String) Compare(other TypedValue) TypeComparision {
if i.Kind() != other.Kind() {
panic(fmt.Sprintf(
"couldn't compare between different kind of types where left is: %s(%v) and right is: %s(%v)",
i.Kind(), i, other.Kind(), other),
)
}
otherVal, err := conv.String(other)
PanicOnError(err)
if string(i) == otherVal {
return Equals
} else if string(i) > otherVal {
return LeftIsBigger
} else {
return RightIsBigger
}
}
func (i String) Cast(toPtr interface{}) {
if err := conv.Infer(toPtr, i); err != nil {
panic(err)
}
}
func (i String) Kind() TypeKind {
return KindString
}
func (i String) Ptr() TypedValue {
return &i
}
func (i String) NativeType() interface{} {
return string(i)
}
func (i String) Precedence() int {
return 4
}