forked from ua-parser/uap-go
/
os.go
49 lines (45 loc) · 1.18 KB
/
os.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
package uaparser
type Os struct {
Family string
Major string
Minor string
Patch string
PatchMinor string `yaml:"patch_minor"`
}
func (parser *osParser) Match(line string, os *Os) {
matches := parser.Reg.FindStringSubmatchIndex(line)
if len(matches) > 0 {
os.Family = string(parser.Reg.ExpandString(nil, parser.OSReplacement, line, matches))
os.Major = string(parser.Reg.ExpandString(nil, parser.V1Replacement, line, matches))
os.Minor = string(parser.Reg.ExpandString(nil, parser.V2Replacement, line, matches))
os.Patch = string(parser.Reg.ExpandString(nil, parser.V3Replacement, line, matches))
os.PatchMinor = string(parser.Reg.ExpandString(nil, parser.V4Replacement, line, matches))
}
}
func (os *Os) ToString() string {
var str string
if os.Family != "" {
str += os.Family
}
version := os.ToVersionString()
if version != "" {
str += " " + version
}
return str
}
func (os *Os) ToVersionString() string {
var version string
if os.Major != "" {
version += os.Major
}
if os.Minor != "" {
version += "." + os.Minor
}
if os.Patch != "" {
version += "." + os.Patch
}
if os.PatchMinor != "" {
version += "." + os.PatchMinor
}
return version
}