-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperators.go
110 lines (88 loc) · 1.58 KB
/
operators.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import "regexp"
type Operator interface {
Compare(base, target string) bool
Symbol() string
}
var CLEANER, _ = regexp.Compile("(>=|<=|>|<|=|~|\\^)")
var Operators = []Operator{
&Gte{
operator: &operator{">="},
},
&Lte{
operator: &operator{"<="},
},
&Gt{
operator: &operator{">"},
},
&Lt{
operator: &operator{"<"},
},
&Equal{
operator: &operator{"="},
},
&Tilde{
operator: &operator{"~"},
},
&Caret{
operator: &operator{"^"},
},
}
type operator struct {
Operator string
}
func (opt *operator) Symbol() string {
return opt.Operator
}
type Gte struct {
*operator
}
func (symbol *Gte) Compare(base, target string) bool {
return base >= target
}
type Lte struct {
*operator
}
func (symbol *Lte) Compare(base, target string) bool {
return base <= target
}
type Gt struct {
*operator
}
func (symbol *Gt) Compare(base, target string) bool {
return base > target
}
type Lt struct {
*operator
}
func (symbol *Lt) Compare(base, target string) bool {
return base < target
}
type Equal struct {
*operator
}
func (symbol *Equal) Compare(base, target string) bool {
return base == target
}
type Tilde struct {
*operator
}
func (symbol *Tilde) Compare(base, target string) bool {
return base >= target
}
type Caret struct {
*operator
}
func (symbol *Caret) Compare(base, target string) bool {
return base >= target
}
type Vers []string
func (v Vers) Len() int {
return len(v)
}
func (v Vers) Swap(i, j int) {
v[i], v[j] = v[j], v[i]
}
func (v Vers) Less(i, j int) bool {
return CLEANER.ReplaceAllString(v[i], "") > CLEANER.ReplaceAllString(v[j], "")
}