-
Notifications
You must be signed in to change notification settings - Fork 44
/
util.go
37 lines (30 loc) · 748 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
package rpm
import (
"fmt"
"strings"
)
// TimeFormat is the time format used by the rpm ecosystem. The time being
// formatted must be in UTC for Format to generate the correct format.
const TimeFormat = "Mon Jan _2 15:04:05 2006"
func errorf(format string, a ...interface{}) error {
return fmt.Errorf("rpm: "+format, a...)
}
func parseVersion(v string) (epoch int, version, release string) {
if i := strings.IndexByte(v, ':'); i >= 0 {
epoch, v = parseInt(v[:i]), v[i+1:]
}
if i := strings.IndexByte(v, '-'); i >= 0 {
return epoch, v[:i], v[i+1:]
}
return epoch, v, ""
}
func parseInt(s string) int {
var n int
for _, dec := range s {
if dec < '0' || dec > '9' {
return 0
}
n = n*10 + (int(dec) - '0')
}
return n
}