-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathvalue.go
85 lines (67 loc) · 1.49 KB
/
value.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
package strutil
import "strings"
// Value string
type Value string
// StrVal string. alias of Value
type StrVal = Value
// Set value
func (s *Value) Set(val string) error {
*s = Value(val)
return nil
}
// IsEmpty check
func (s *Value) IsEmpty() bool {
return string(*s) == ""
}
// IsStartWith prefix
func (s *Value) IsStartWith(sub string) bool {
return strings.HasPrefix(string(*s), sub)
}
// HasPrefix prefix
func (s *Value) HasPrefix(sub string) bool {
return strings.HasPrefix(string(*s), sub)
}
// IsEndWith suffix
func (s *Value) IsEndWith(sub string) bool {
return strings.HasSuffix(string(*s), sub)
}
// HasSuffix suffix
func (s *Value) HasSuffix(sub string) bool {
return strings.HasSuffix(string(*s), sub)
}
// Bytes string to bytes
func (s *Value) Bytes() []byte {
return []byte(*s)
}
// Val string
func (s *Value) Val() string {
return string(*s)
}
// Int convert
func (s *Value) Int() int {
return QuietInt(string(*s))
}
// Int64 convert
func (s *Value) Int64() int64 {
return QuietInt64(string(*s))
}
// Bool convert
func (s *Value) Bool() bool {
return QuietBool(string(*s))
}
// Value string
func (s *Value) String() string {
return string(*s)
}
// Split string
func (s *Value) Split(sep string) []string {
return strings.Split(string(*s), sep)
}
// SplitN string
func (s *Value) SplitN(sep string, n int) []string {
return strings.SplitN(string(*s), sep, n)
}
// TrimSpace string and return new
func (s *Value) TrimSpace() Value {
return Value(strings.TrimSpace(string(*s)))
}