-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathslice.go
63 lines (56 loc) · 1.17 KB
/
slice.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
package hostsfile
func itemInSliceString(item string, list []string) bool {
for _, i := range list {
if i == item {
return true
}
}
return false
}
func itemInSliceInt(item int, list []int) bool {
for _, i := range list {
if i == item {
return true
}
}
return false
}
func removeFromSliceString(s string, slice []string) []string {
pos := findPositionInSliceString(s, slice)
for pos > -1 {
slice = append(slice[:pos], slice[pos+1:]...)
pos = findPositionInSliceString(s, slice)
}
return slice
}
func findPositionInSliceString(s string, slice []string) int {
for index, v := range slice {
if v == s {
return index
}
}
return -1
}
func removeFromSliceInt(s int, slice []int) []int {
pos := findPositionInSliceInt(s, slice)
for pos > -1 {
slice = append(slice[:pos], slice[pos+1:]...)
pos = findPositionInSliceInt(s, slice)
}
return slice
}
func removeOneFromSliceInt(s int, slice []int) []int {
pos := findPositionInSliceInt(s, slice)
if pos > -1 {
slice = append(slice[:pos], slice[pos+1:]...)
}
return slice
}
func findPositionInSliceInt(s int, slice []int) int {
for index, v := range slice {
if v == s {
return index
}
}
return -1
}