forked from phR0ze/n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
char.go
87 lines (74 loc) · 1.96 KB
/
char.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package n
// Char wraps the Go rune providing a way to distinguish it from an int32
// where as a rune is indistinguishable from an int32. Provides convenience
// methods on par with rapid development languages.
type Char rune
// // C is an alias to NewChar for brevity
// func C(obj interface{}) *Str {
// return NewChar(obj)
// }
// NewChar creates a new chart from the given obj. Will always be non nil.
// Supports: string, *string, rune, *rune, byte, *byte
func NewChar(obj interface{}) *Char {
return ToChar(obj)
}
// NewCharV creates a new chart from the given obj. Will always be non nil.
// Allows for empty Char with a Null value
func NewCharV(obj ...interface{}) *Char {
new := Char(0)
return &new
}
// Object interface methods
//--------------------------------------------------------------------------------------------------
// A is an alias of String for brevity
func (p *Char) A() string {
return p.String()
}
// Equal returns true if the given *Char is value equal to this *Char.
func (p *Char) Equal(obj interface{}) bool {
other := ToChar(obj)
if p == nil {
return false
}
return *p == *other
}
// G returns the underlying data structure as a builtin Go type
func (p *Char) G() rune {
return p.O().(rune)
}
// Less returns true if the given *Char is less than this *Char.
func (p *Char) Less(obj interface{}) bool {
other := ToChar(obj)
if p == nil {
return false
}
return p.A() < other.A()
}
// O returns the underlying data structure as is
func (p *Char) O() interface{} {
if p == nil {
return rune(0)
}
return rune(*p)
}
// Nil tests if the object is nil
func (p *Char) Nil() bool {
if p == nil {
return true
}
return false
}
// Null tests if the char is a rune(0)
func (p *Char) Null() bool {
if p == nil {
return false
}
return rune(*p) == rune(0)
}
// String returns a string representation of the Object, implements Stringer interface.
func (p *Char) String() string {
if p == nil || *p == Char(0) {
return ""
}
return string(*p)
}