-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
46 lines (37 loc) · 767 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
package git
import (
"fmt"
"strings"
)
func trim(strs ...string) []string {
out := make([]string, 0, len(strs))
for _, s := range strs {
trimmed := strings.TrimSpace(s)
if trimmed == "" {
continue
}
out = append(out, trimmed)
}
return out
}
func trimAndPrefix(prefix string, strs ...string) []string {
out := make([]string, 0, len(strs))
for _, s := range strs {
trimmed := strings.TrimSpace(s)
if trimmed == "" {
continue
}
if !strings.HasPrefix(trimmed, prefix) {
trimmed = fmt.Sprintf("%s%s", prefix, trimmed)
}
out = append(out, trimmed)
}
return out
}
func reverse(strs ...string) []string {
out := make([]string, 0, len(strs))
for i := len(strs) - 1; i >= 0; i-- {
out = append(out, strs[i])
}
return out
}