Merge branch 'master' into pr/ielevenliu/43
This commit is contained in:
@@ -25,16 +25,19 @@ type UserAgent struct {
|
|||||||
|
|
||||||
// Constants for browsers and operating systems for easier comparison
|
// Constants for browsers and operating systems for easier comparison
|
||||||
const (
|
const (
|
||||||
Windows = "Windows"
|
Windows = "Windows"
|
||||||
WindowsPhone = "Windows Phone"
|
WindowsPhone = "Windows Phone"
|
||||||
Android = "Android"
|
WindowsNT = "Windows NT"
|
||||||
MacOS = "macOS"
|
WindowsPhoneOS = "Windows Phone OS"
|
||||||
IOS = "iOS"
|
Android = "Android"
|
||||||
Linux = "Linux"
|
MacOS = "macOS"
|
||||||
FreeBSD = "FreeBSD"
|
IOS = "iOS"
|
||||||
ChromeOS = "ChromeOS"
|
Linux = "Linux"
|
||||||
BlackBerry = "BlackBerry"
|
FreeBSD = "FreeBSD"
|
||||||
Harmony = "Harmony"
|
ChromeOS = "ChromeOS"
|
||||||
|
BlackBerry = "BlackBerry"
|
||||||
|
CrOS = "CrOS"
|
||||||
|
Harmony = "Harmony"
|
||||||
|
|
||||||
Opera = "Opera"
|
Opera = "Opera"
|
||||||
OperaMini = "Opera Mini"
|
OperaMini = "Opera Mini"
|
||||||
@@ -46,6 +49,10 @@ const (
|
|||||||
Safari = "Safari"
|
Safari = "Safari"
|
||||||
Edge = "Edge"
|
Edge = "Edge"
|
||||||
Vivaldi = "Vivaldi"
|
Vivaldi = "Vivaldi"
|
||||||
|
MobileSafari = "Mobile Safari"
|
||||||
|
NetFront = "NetFront"
|
||||||
|
Mozilla = "Mozilla"
|
||||||
|
Msie = "MSIE"
|
||||||
|
|
||||||
GoogleAdsBot = "Google Ads Bot"
|
GoogleAdsBot = "Google Ads Bot"
|
||||||
Googlebot = "Googlebot"
|
Googlebot = "Googlebot"
|
||||||
@@ -53,10 +60,16 @@ const (
|
|||||||
FacebookExternalHit = "facebookexternalhit"
|
FacebookExternalHit = "facebookexternalhit"
|
||||||
Applebot = "Applebot"
|
Applebot = "Applebot"
|
||||||
Bingbot = "Bingbot"
|
Bingbot = "Bingbot"
|
||||||
|
YandexBot = "YandexBot"
|
||||||
|
YandexAdNet = "YandexAdNet"
|
||||||
|
|
||||||
FacebookApp = "Facebook App"
|
FacebookApp = "Facebook App"
|
||||||
InstagramApp = "Instagram App"
|
InstagramApp = "Instagram App"
|
||||||
TiktokApp = "TikTok App"
|
TiktokApp = "TikTok App"
|
||||||
|
|
||||||
|
Version = "Version"
|
||||||
|
Mobile = "Mobile"
|
||||||
|
Tablet = "Tablet"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse user agent string returning UserAgent struct
|
// Parse user agent string returning UserAgent struct
|
||||||
@@ -76,15 +89,13 @@ func Parse(userAgent string) UserAgent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Printf("%+v\n", tokens)
|
|
||||||
|
|
||||||
// OS lookup
|
// OS lookup
|
||||||
switch {
|
switch {
|
||||||
case tokens.exists("Android"):
|
case tokens.exists(Android):
|
||||||
ua.OS = Android
|
ua.OS = Android
|
||||||
var osIndex int
|
var osIndex int
|
||||||
osIndex, ua.OSVersion = tokens.getIndexValue(Android)
|
osIndex, ua.OSVersion = tokens.getIndexValue(Android)
|
||||||
ua.Tablet = strings.Contains(strings.ToLower(ua.String), "tablet")
|
ua.Tablet = strings.Contains(strings.ToLower(ua.String), strings.ToLower(Tablet))
|
||||||
ua.Device = tokens.findAndroidDevice(osIndex)
|
ua.Device = tokens.findAndroidDevice(osIndex)
|
||||||
|
|
||||||
case tokens.exists("iPhone"):
|
case tokens.exists("iPhone"):
|
||||||
@@ -99,14 +110,14 @@ func Parse(userAgent string) UserAgent {
|
|||||||
ua.Device = "iPad"
|
ua.Device = "iPad"
|
||||||
ua.Tablet = true
|
ua.Tablet = true
|
||||||
|
|
||||||
case tokens.exists("Windows NT"):
|
case tokens.exists(WindowsNT):
|
||||||
ua.OS = Windows
|
ua.OS = Windows
|
||||||
ua.OSVersion = tokens.get("Windows NT")
|
ua.OSVersion = tokens.get(WindowsNT)
|
||||||
ua.Desktop = true
|
ua.Desktop = true
|
||||||
|
|
||||||
case tokens.exists("Windows Phone OS"):
|
case tokens.exists(WindowsPhoneOS):
|
||||||
ua.OS = WindowsPhone
|
ua.OS = WindowsPhone
|
||||||
ua.OSVersion = tokens.get("Windows Phone OS")
|
ua.OSVersion = tokens.get(WindowsPhoneOS)
|
||||||
ua.Mobile = true
|
ua.Mobile = true
|
||||||
|
|
||||||
case tokens.exists("Macintosh"):
|
case tokens.exists("Macintosh"):
|
||||||
@@ -114,24 +125,24 @@ func Parse(userAgent string) UserAgent {
|
|||||||
ua.OSVersion = tokens.findMacOSVersion()
|
ua.OSVersion = tokens.findMacOSVersion()
|
||||||
ua.Desktop = true
|
ua.Desktop = true
|
||||||
|
|
||||||
case tokens.exists("Linux"):
|
case tokens.exists(Linux):
|
||||||
ua.OS = Linux
|
ua.OS = Linux
|
||||||
ua.OSVersion = tokens.get(Linux)
|
ua.OSVersion = tokens.get(Linux)
|
||||||
ua.Desktop = true
|
ua.Desktop = true
|
||||||
|
|
||||||
case tokens.exists("FreeBSD"):
|
case tokens.exists(FreeBSD):
|
||||||
ua.OS = FreeBSD
|
ua.OS = FreeBSD
|
||||||
ua.OSVersion = tokens.get(FreeBSD)
|
ua.OSVersion = tokens.get(FreeBSD)
|
||||||
ua.Desktop = true
|
ua.Desktop = true
|
||||||
|
|
||||||
case tokens.exists("CrOS"):
|
case tokens.exists(CrOS):
|
||||||
ua.OS = ChromeOS
|
ua.OS = ChromeOS
|
||||||
ua.OSVersion = tokens.get("CrOS")
|
ua.OSVersion = tokens.get(CrOS)
|
||||||
ua.Desktop = true
|
ua.Desktop = true
|
||||||
|
|
||||||
case tokens.exists("BlackBerry"):
|
case tokens.exists(BlackBerry):
|
||||||
ua.OS = BlackBerry
|
ua.OS = BlackBerry
|
||||||
ua.OSVersion = tokens.get("BlackBerry")
|
ua.OSVersion = tokens.get(BlackBerry)
|
||||||
ua.Mobile = true
|
ua.Mobile = true
|
||||||
|
|
||||||
case tokens.exists("OpenHarmony"):
|
case tokens.exists("OpenHarmony"):
|
||||||
@@ -141,11 +152,11 @@ func Parse(userAgent string) UserAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case tokens.exists("Googlebot"):
|
case tokens.exists(Googlebot):
|
||||||
ua.Name = Googlebot
|
ua.Name = Googlebot
|
||||||
ua.Version = tokens.get(Googlebot)
|
ua.Version = tokens.get(Googlebot)
|
||||||
ua.Bot = true
|
ua.Bot = true
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.existsAny("GoogleProber", "GoogleProducer"):
|
case tokens.existsAny("GoogleProber", "GoogleProducer"):
|
||||||
if name := tokens.findBestMatch(false); name != "" {
|
if name := tokens.findBestMatch(false); name != "" {
|
||||||
@@ -153,14 +164,14 @@ func Parse(userAgent string) UserAgent {
|
|||||||
}
|
}
|
||||||
ua.Bot = true
|
ua.Bot = true
|
||||||
|
|
||||||
case tokens.exists("Applebot"):
|
case tokens.exists(Applebot):
|
||||||
ua.Name = Applebot
|
ua.Name = Applebot
|
||||||
ua.Version = tokens.get(Applebot)
|
ua.Version = tokens.get(Applebot)
|
||||||
ua.Bot = true
|
ua.Bot = true
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
ua.OS = ""
|
ua.OS = ""
|
||||||
|
|
||||||
case tokens.get("Opera Mini") != "":
|
case tokens.get(OperaMini) != "":
|
||||||
ua.Name = OperaMini
|
ua.Name = OperaMini
|
||||||
ua.Version = tokens.get(OperaMini)
|
ua.Version = tokens.get(OperaMini)
|
||||||
ua.Mobile = true
|
ua.Mobile = true
|
||||||
@@ -168,84 +179,91 @@ func Parse(userAgent string) UserAgent {
|
|||||||
case tokens.get("OPR") != "":
|
case tokens.get("OPR") != "":
|
||||||
ua.Name = Opera
|
ua.Name = Opera
|
||||||
ua.Version = tokens.get("OPR")
|
ua.Version = tokens.get("OPR")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("OPT") != "":
|
case tokens.get("OPT") != "":
|
||||||
ua.Name = OperaTouch
|
ua.Name = OperaTouch
|
||||||
ua.Version = tokens.get("OPT")
|
ua.Version = tokens.get("OPT")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
// Opera on iOS
|
// Opera on iOS
|
||||||
case tokens.get("OPiOS") != "":
|
case tokens.get("OPiOS") != "":
|
||||||
ua.Name = Opera
|
ua.Name = Opera
|
||||||
ua.Version = tokens.get("OPiOS")
|
ua.Version = tokens.get("OPiOS")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
// Chrome on iOS
|
// Chrome on iOS
|
||||||
case tokens.get("CriOS") != "":
|
case tokens.get("CriOS") != "":
|
||||||
ua.Name = Chrome
|
ua.Name = Chrome
|
||||||
ua.Version = tokens.get("CriOS")
|
ua.Version = tokens.get("CriOS")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
// Firefox on iOS
|
// Firefox on iOS
|
||||||
case tokens.get("FxiOS") != "":
|
case tokens.get("FxiOS") != "":
|
||||||
ua.Name = Firefox
|
ua.Name = Firefox
|
||||||
ua.Version = tokens.get("FxiOS")
|
ua.Version = tokens.get("FxiOS")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("Firefox") != "":
|
case tokens.get(Firefox) != "":
|
||||||
ua.Name = Firefox
|
ua.Name = Firefox
|
||||||
ua.Version = tokens.get(Firefox)
|
ua.Version = tokens.get(Firefox)
|
||||||
ua.Mobile = tokens.exists("Mobile")
|
ua.Mobile = tokens.exists(Mobile)
|
||||||
ua.Tablet = tokens.exists("Tablet")
|
ua.Tablet = tokens.exists(Tablet)
|
||||||
|
|
||||||
case tokens.get("Vivaldi") != "":
|
case tokens.get(Vivaldi) != "":
|
||||||
ua.Name = Vivaldi
|
ua.Name = Vivaldi
|
||||||
ua.Version = tokens.get(Vivaldi)
|
ua.Version = tokens.get(Vivaldi)
|
||||||
|
|
||||||
case tokens.exists("MSIE"):
|
case tokens.exists(Msie):
|
||||||
ua.Name = InternetExplorer
|
ua.Name = InternetExplorer
|
||||||
ua.Version = tokens.get("MSIE")
|
ua.Version = tokens.get(Msie)
|
||||||
|
|
||||||
case tokens.get("EdgiOS") != "":
|
case tokens.get("EdgiOS") != "":
|
||||||
ua.Name = Edge
|
ua.Name = Edge
|
||||||
ua.Version = tokens.get("EdgiOS")
|
ua.Version = tokens.get("EdgiOS")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("Edge") != "":
|
case tokens.get(Edge) != "":
|
||||||
ua.Name = Edge
|
ua.Name = Edge
|
||||||
ua.Version = tokens.get("Edge")
|
ua.Version = tokens.get(Edge)
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("Edg") != "":
|
case tokens.get("Edg") != "":
|
||||||
ua.Name = Edge
|
ua.Name = Edge
|
||||||
ua.Version = tokens.get("Edg")
|
ua.Version = tokens.get("Edg")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("EdgA") != "":
|
case tokens.get("EdgA") != "":
|
||||||
ua.Name = Edge
|
ua.Name = Edge
|
||||||
ua.Version = tokens.get("EdgA")
|
ua.Version = tokens.get("EdgA")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("bingbot") != "":
|
case tokens.get("bingbot") != "":
|
||||||
ua.Name = Bingbot
|
ua.Name = Bingbot
|
||||||
ua.Version = tokens.get("bingbot")
|
ua.Version = tokens.get("bingbot")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("YandexBot") != "":
|
case tokens.get(YandexBot) != "":
|
||||||
ua.Name = "YandexBot"
|
ua.Name = YandexBot
|
||||||
ua.Version = tokens.get("YandexBot")
|
ua.Version = tokens.get(YandexBot)
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
ua.Bot = true
|
||||||
|
|
||||||
|
case tokens.get(YandexAdNet) != "":
|
||||||
|
ua.Name = YandexAdNet
|
||||||
|
ua.Version = tokens.get(YandexAdNet)
|
||||||
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
ua.Bot = true
|
||||||
|
|
||||||
case tokens.get("SamsungBrowser") != "":
|
case tokens.get("SamsungBrowser") != "":
|
||||||
ua.Name = "Samsung Browser"
|
ua.Name = "Samsung Browser"
|
||||||
ua.Version = tokens.get("SamsungBrowser")
|
ua.Version = tokens.get("SamsungBrowser")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.get("HeadlessChrome") != "":
|
case tokens.get("HeadlessChrome") != "":
|
||||||
ua.Name = HeadlessChrome
|
ua.Name = HeadlessChrome
|
||||||
ua.Version = tokens.get("HeadlessChrome")
|
ua.Version = tokens.get("HeadlessChrome")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
ua.Bot = true
|
ua.Bot = true
|
||||||
|
|
||||||
case tokens.existsAny("AdsBot-Google-Mobile", "Mediapartners-Google", "AdsBot-Google"):
|
case tokens.existsAny("AdsBot-Google-Mobile", "Mediapartners-Google", "AdsBot-Google"):
|
||||||
@@ -285,18 +303,18 @@ func Parse(userAgent string) UserAgent {
|
|||||||
case tokens.get("HuaweiBrowser") != "":
|
case tokens.get("HuaweiBrowser") != "":
|
||||||
ua.Name = "Huawei Browser"
|
ua.Name = "Huawei Browser"
|
||||||
ua.Version = tokens.get("HuaweiBrowser")
|
ua.Version = tokens.get("HuaweiBrowser")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.exists("BlackBerry"):
|
case tokens.exists(BlackBerry):
|
||||||
ua.Name = "BlackBerry"
|
ua.Name = BlackBerry
|
||||||
ua.Version = tokens.get("Version")
|
ua.Version = tokens.get(Version)
|
||||||
|
|
||||||
case tokens.exists("NetFront"):
|
case tokens.exists(NetFront):
|
||||||
ua.Name = "NetFront"
|
ua.Name = NetFront
|
||||||
ua.Version = tokens.get("NetFront")
|
ua.Version = tokens.get(NetFront)
|
||||||
ua.Mobile = true
|
ua.Mobile = true
|
||||||
|
|
||||||
// if chrome and Safari defined, find any other token sent descr
|
// if Chrome and Safari defined, find any other token sent descr
|
||||||
case tokens.exists(Chrome) && tokens.exists(Safari):
|
case tokens.exists(Chrome) && tokens.exists(Safari):
|
||||||
name := tokens.findBestMatch(true)
|
name := tokens.findBestMatch(true)
|
||||||
if name != "" {
|
if name != "" {
|
||||||
@@ -306,30 +324,30 @@ func Parse(userAgent string) UserAgent {
|
|||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
||||||
case tokens.exists("Chrome"):
|
case tokens.exists(Chrome):
|
||||||
ua.Name = Chrome
|
ua.Name = Chrome
|
||||||
ua.Version = tokens.get("Chrome")
|
ua.Version = tokens.get(Chrome)
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.exists("Brave Chrome"):
|
case tokens.exists("Brave Chrome"):
|
||||||
ua.Name = Chrome
|
ua.Name = Chrome
|
||||||
ua.Version = tokens.get("Brave Chrome")
|
ua.Version = tokens.get("Brave Chrome")
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
case tokens.exists("Safari"):
|
case tokens.exists(Safari):
|
||||||
ua.Name = Safari
|
ua.Name = Safari
|
||||||
v := tokens.get("Version")
|
v := tokens.get(Version)
|
||||||
if v != "" {
|
if v != "" {
|
||||||
ua.Version = v
|
ua.Version = v
|
||||||
} else {
|
} else {
|
||||||
ua.Version = tokens.get("Safari")
|
ua.Version = tokens.get(Safari)
|
||||||
}
|
}
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ua.OS == "Android" && tokens.get("Version") != "" {
|
if ua.IsAndroid() && tokens.get(Version) != "" {
|
||||||
ua.Name = "Android browser"
|
ua.Name = "Android browser"
|
||||||
ua.Version = tokens.get("Version")
|
ua.Version = tokens.get(Version)
|
||||||
ua.Mobile = true
|
ua.Mobile = true
|
||||||
} else {
|
} else {
|
||||||
if name := tokens.findBestMatch(false); name != "" {
|
if name := tokens.findBestMatch(false); name != "" {
|
||||||
@@ -341,7 +359,7 @@ func Parse(userAgent string) UserAgent {
|
|||||||
ua.Bot = strings.Contains(strings.ToLower(ua.Name), "bot")
|
ua.Bot = strings.Contains(strings.ToLower(ua.Name), "bot")
|
||||||
// If mobile flag has already been set, don't override it.
|
// If mobile flag has already been set, don't override it.
|
||||||
if !ua.Mobile {
|
if !ua.Mobile {
|
||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny(Mobile, MobileSafari)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,7 +373,7 @@ func Parse(userAgent string) UserAgent {
|
|||||||
ua.Mobile = false
|
ua.Mobile = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not already bot, check some popular bots and wether URL is set
|
// if not already bot, check some popular bots and whether URL is set
|
||||||
if !ua.Bot {
|
if !ua.Bot {
|
||||||
ua.Bot = ua.URL != ""
|
ua.Bot = ua.URL != ""
|
||||||
}
|
}
|
||||||
@@ -390,7 +408,7 @@ func parse(userAgent string) properties {
|
|||||||
|
|
||||||
if val.Len() == 0 { // only if value don't exists
|
if val.Len() == 0 { // only if value don't exists
|
||||||
var ver string
|
var ver string
|
||||||
s, ver = checkVer(s) // determin version string and split
|
s, ver = checkVer(s) // determine version string and split
|
||||||
clients.add(s, ver)
|
clients.add(s, ver)
|
||||||
} else {
|
} else {
|
||||||
clients.add(s, strings.TrimSpace(val.String()))
|
clients.add(s, strings.TrimSpace(val.String()))
|
||||||
@@ -409,7 +427,6 @@ func parse(userAgent string) properties {
|
|||||||
bua := []byte(userAgent)
|
bua := []byte(userAgent)
|
||||||
for i, c := range bua {
|
for i, c := range bua {
|
||||||
|
|
||||||
//fmt.Println(string(c), c)
|
|
||||||
switch {
|
switch {
|
||||||
case c == 41: // )
|
case c == 41: // )
|
||||||
addToken()
|
addToken()
|
||||||
@@ -440,7 +457,7 @@ func parse(userAgent string) properties {
|
|||||||
// If the following character is not a space, change to a space.
|
// If the following character is not a space, change to a space.
|
||||||
buff.WriteByte(' ')
|
buff.WriteByte(' ')
|
||||||
}
|
}
|
||||||
// Otherwise don't write as its probably a badly formatted key value separator.
|
// Otherwise don't write as it's probably a badly formatted key value separator.
|
||||||
|
|
||||||
case slash && c == 32:
|
case slash && c == 32:
|
||||||
addToken()
|
addToken()
|
||||||
@@ -475,10 +492,8 @@ func checkVer(s string) (name, v string) {
|
|||||||
return s, ""
|
return s, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
//v = s[i+1:]
|
|
||||||
|
|
||||||
switch s[:i] {
|
switch s[:i] {
|
||||||
case "Linux", "Windows NT", "Windows Phone OS", "MSIE", "Android", "OpenHarmony":
|
case Linux, WindowsNT, WindowsPhoneOS, Msie, Android, "OpenHarmony":
|
||||||
return s[:i], s[i+1:]
|
return s[:i], s[i+1:]
|
||||||
case "CrOS x86_64", "CrOS aarch64", "CrOS armv7l":
|
case "CrOS x86_64", "CrOS aarch64", "CrOS armv7l":
|
||||||
j := strings.LastIndex(s[:i], " ")
|
j := strings.LastIndex(s[:i], " ")
|
||||||
@@ -486,20 +501,12 @@ func checkVer(s string) (name, v string) {
|
|||||||
default:
|
default:
|
||||||
return s, ""
|
return s, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// for _, c := range v {
|
|
||||||
// if (c >= 48 && c <= 57) || c == 46 {
|
|
||||||
// } else {
|
|
||||||
// return s, ""
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return s[:i], s[i+1:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore retursn true if token should be ignored
|
// ignore returns true if token should be ignored
|
||||||
func ignore(s string) bool {
|
func ignore(s string) bool {
|
||||||
switch s {
|
switch s {
|
||||||
case "KHTML, like Gecko", "U", "compatible", "Mozilla", "WOW64", "en", "en-us", "en-gb", "ru-ru", "Browser":
|
case "KHTML, like Gecko", "U", "compatible", Mozilla, "WOW64", "en", "en-us", "en-gb", "ru-ru", "Browser":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
@@ -613,9 +620,9 @@ func (p properties) findBestMatch(withVerOnly bool) string {
|
|||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
for _, prop := range p.list {
|
for _, prop := range p.list {
|
||||||
switch prop.Key {
|
switch prop.Key {
|
||||||
case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA", "CrOS", "Tablet", "OpenHarmony":
|
case Chrome, Firefox, Safari, Version, Mobile, MobileSafari, Mozilla, "AppleWebKit", WindowsNT, WindowsPhoneOS, Android, "Macintosh", Linux, "GSA", CrOS, Tablet, "OpenHarmony":
|
||||||
default:
|
default:
|
||||||
// don' pick if starts with number
|
// don't pick if starts with number
|
||||||
if len(prop.Key) != 0 && prop.Key[0] >= 48 && prop.Key[0] <= 57 {
|
if len(prop.Key) != 0 && prop.Key[0] >= 48 && prop.Key[0] <= 57 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -647,15 +654,15 @@ func (p *properties) findAndroidDevice(startIndex int) string {
|
|||||||
if len(p.list) > i+1 {
|
if len(p.list) > i+1 {
|
||||||
dev := p.list[i+1].Key
|
dev := p.list[i+1].Key
|
||||||
if len(dev) == 2 || (len(dev) == 5 && dev[2] == '-') {
|
if len(dev) == 2 || (len(dev) == 5 && dev[2] == '-') {
|
||||||
// probably langage tag (en-us etc..), ignore and continue loop
|
// probably language tag (en-us etc..), ignore and continue loop
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch dev {
|
switch dev {
|
||||||
case Chrome, Firefox, Safari, "Opera Mini", "Presto", "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "CrOS":
|
case Chrome, Firefox, Safari, OperaMini, "Presto", Version, Mobile, MobileSafari, Mozilla, "AppleWebKit", WindowsNT, WindowsPhoneOS, Android, "Macintosh", Linux, CrOS:
|
||||||
// ignore this tokens, not device names
|
// ignore these tokens, not device names
|
||||||
default:
|
default:
|
||||||
if strings.Contains(strings.ToLower(dev), "tablet") {
|
if strings.Contains(strings.ToLower(dev), strings.ToLower(Tablet)) {
|
||||||
p.list[i+1].Key = "Tablet" // leave Tablet tag for later table detection
|
p.list[i+1].Key = Tablet // leave Tablet tag for later table detection
|
||||||
} else {
|
} else {
|
||||||
p.list = append(p.list[:i+1], p.list[i+2:]...)
|
p.list = append(p.list[:i+1], p.list[i+2:]...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user