-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsamsung.go
49 lines (40 loc) · 825 Bytes
/
samsung.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 devices
import (
"regexp"
)
type Samsung struct {
p Parser
matches []string
}
// NewSamsung creates a new Samsung platform.
func NewSamsung(p Parser) *Samsung {
return &Samsung{
p: p,
matches: make([]string, 0),
}
}
var (
samsungName = "Samsung"
samsungMatchRegex = `(?i)(?:Linux.*?; Android.*?; (?:SAMSUNG )?(SM-[A-Z0-9]+).*?)`
)
func (s *Samsung) Name() string {
s.registerMatches()
if len(s.matches) > 1 {
return samsungName + " " + s.matches[1]
}
return samsungName
}
func (s *Samsung) Match() bool {
s.registerMatches()
return len(s.matches) > 0
}
func (s *Samsung) registerMatches() {
if len(s.matches) > 0 {
return
}
re := regexp.MustCompile(samsungMatchRegex)
matches := re.FindStringSubmatch(s.p.String())
if len(matches) > 0 {
s.matches = matches
}
}