forked from ua-parser/uap-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos.go
More file actions
49 lines (45 loc) · 1.15 KB
/
Copy pathos.go
File metadata and controls
49 lines (45 loc) · 1.15 KB
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 (osp *osParser) Match(line string, os *Os) {
matches := osp.Reg.FindStringSubmatchIndex(line)
if len(matches) > 0 {
os.Family = string(osp.Reg.ExpandString(nil, osp.OSReplacement, line, matches))
os.Major = string(osp.Reg.ExpandString(nil, osp.V1Replacement, line, matches))
os.Minor = string(osp.Reg.ExpandString(nil, osp.V2Replacement, line, matches))
os.Patch = string(osp.Reg.ExpandString(nil, osp.V3Replacement, line, matches))
os.PatchMinor = string(osp.Reg.ExpandString(nil, osp.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
}