File: os.go

package info (click to toggle)
golang-github-ua-parser-uap-go 0.0~git20200325.e1c09f1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,840 kB
  • sloc: makefile: 5; sh: 4
file content (49 lines) | stat: -rw-r--r-- 1,209 bytes parent folder | download | duplicates (2)
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
}