Skip to content

Commit

Permalink
Exported OS name constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dwb committed Nov 4, 2016
1 parent 7fb4bcb commit 2a88513
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ var browsers = map[string]*url.URL{
}

const (
osAndroid = "Android"
osMacOS = "Mac OS X"
osIOS = "iOS"
osLinux = "GNU/Linux"
osWindows = "Windows"
OSAndroid = "Android"
OSMacOS = "Mac OS X"
OSiOS = "iOS"
OSLinux = "GNU/Linux"
OSWindows = "Windows"
)

func parseBrowser(l *lex) *UserAgent {
Expand Down Expand Up @@ -75,7 +75,7 @@ func parseMozillaLike(l *lex, ua *UserAgent) bool {
parseUnixLike(l, ua)
case l.match("Android"):
ua.Security = parseSecurity(l)
ua.OS = osAndroid
ua.OS = OSAndroid
if l.match("; Mobile") {
ua.Mobile = true
} else if l.match("; Tablet") {
Expand All @@ -84,16 +84,16 @@ func parseMozillaLike(l *lex, ua *UserAgent) bool {
case l.match("Linux; "):
ua.Security = parseSecurity(l)
if l.match("Android") {
ua.OS = osAndroid
ua.OS = OSAndroid
} else {
return false
}
case l.match("Windows"):
ua.Security = parseSecurity(l)
ua.OS = osWindows
ua.OS = OSWindows
case l.match("Macintosh"):
ua.Security = parseSecurity(l)
ua.OS = osMacOS
ua.OS = OSMacOS
case l.match("Mobile; "):
ua.Security = parseSecurity(l)
ua.OS = "Firefox OS"
Expand All @@ -104,11 +104,11 @@ func parseMozillaLike(l *lex, ua *UserAgent) bool {
ua.Tablet = true
case l.match("iPad; "):
ua.Security = parseSecurity(l)
ua.OS = osIOS
ua.OS = OSiOS
ua.Tablet = true
case l.match("iPhone; ") || l.match("iPod; ") || l.match("iPod touch; "):
ua.Security = parseSecurity(l)
ua.OS = osIOS
ua.OS = OSiOS
ua.Mobile = true
case l.match("Unknown; "):
ua.Security = parseSecurity(l)
Expand All @@ -131,7 +131,7 @@ func parseMozillaLike(l *lex, ua *UserAgent) bool {
func parseUnixLike(l *lex, ua *UserAgent) bool {
switch {
case l.match("Linux") || l.match("Ubuntu"):
ua.OS = osLinux
ua.OS = OSLinux
case l.match("FreeBSD"):
ua.OS = "FreeBSD"
case l.match("OpenBSD"):
Expand Down Expand Up @@ -255,7 +255,7 @@ func parseIE1(l *lex) *UserAgent {
return nil
}

ua.OS = osWindows
ua.OS = OSWindows
// swallow the error to preserve backwards compatibility
_ = parseOSVersion(l, ua)

Expand All @@ -273,7 +273,7 @@ func parseIE2(l *lex) *UserAgent {
if _, ok := l.span("(Windows NT"); !ok {
return nil
}
ua.OS = osWindows
ua.OS = OSWindows

// swallow the error to preserve backwards compatibility
_ = parseOSVersion(l, ua)
Expand Down
4 changes: 2 additions & 2 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ var genericVersionRegexp = regexp.MustCompile(`(?:[^\)]*?) (\d+\.\d+(\.\d+)?)\b`

func parseOSVersion(l *lex, ua *UserAgent) bool {
switch ua.OS {
case osMacOS, osIOS:
case OSMacOS, OSiOS:
_, s, ok := l.spanRegexp(appleVersionRegexp)
if !ok {
return true
Expand All @@ -225,7 +225,7 @@ func parseOSVersion(l *lex, ua *UserAgent) bool {
ua.OSVersion = v
return true

case osAndroid, osWindows:
case OSAndroid, OSWindows:
_, s, ok := l.spanRegexp(genericVersionRegexp)
if !ok {
return true
Expand Down

0 comments on commit 2a88513

Please sign in to comment.