-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
43 lines (37 loc) · 924 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
package cheerio
import (
"regexp"
"strings"
)
// Normalizes package names so they are comparable
func NormalizedPkgName(pkg string) string {
return strings.ToLower(pkg)
}
// Convenience functions that get the last instance of a type of file
var tarRegexp = regexp.MustCompile(`[/A-Za-z0-9\._\-]+\.(?:tar\.(?:gz|bz2)|tgz)`)
var zipRegexp = regexp.MustCompile(`[/A-Za-z0-9\._\-]+\.zip`)
var eggRegexp = regexp.MustCompile(`[/A-Za-z0-9\._\-]+\.egg`)
func lastTar(files []string) string {
for f := len(files) - 1; f >= 0; f-- {
if tarRegexp.MatchString(files[f]) {
return files[f]
}
}
return ""
}
func lastEgg(files []string) string {
for f := len(files) - 1; f >= 0; f-- {
if eggRegexp.MatchString(files[f]) {
return files[f]
}
}
return ""
}
func lastZip(files []string) string {
for f := len(files) - 1; f >= 0; f-- {
if zipRegexp.MatchString(files[f]) {
return files[f]
}
}
return ""
}