-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
61 lines (54 loc) · 999 Bytes
/
util.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
package cmdtree
import (
strings "strings"
sort "sort"
)
func trimLeftStr(str string)(string){
i := 0
for i < len(str) && str[i] == ' ' {
i++
}
return str[i:]
}
func trimRightStr(str string)(string){
i := len(str)
for i > 0 && str[i - 1] == ' ' {
i--
}
return str[:i]
}
func SplitNode(cmd string)(node string, _ string){
i := strings.IndexByte(cmd, ' ')
if i < 0 { i = len(cmd) }
return cmd[:i], cmd[i:]
}
func strInList(str string, list []string)(bool){
switch len(list) {
case 0:
return false
case 1:
return list[0] == str
case 2:
return list[0] == str || list[1] == str
}
i := sort.SearchStrings(list, str)
return 0 <= i && i < len(list) && list[i] == str
}
func delDuplication(list []string)([]string){
if len(list) <= 1 {
return list
}
sort.Strings(list)
j := 0
for i := 1; i < len(list); i++ {
if list[i] != list[j] {
j++
if j < i {
list[i], list[j] = list[j], list[i]
}
}
}
list = list[:j + 1]
sort.Strings(list)
return list
}