nmdc-ircfrontend/clientTag.go

40 lines
819 B
Go
Raw Normal View History

package main
import (
"strings"
)
type clientTag struct {
AppName string
Version string
}
func parseVersion(ver string) clientTag {
// A bit long and unwieldy.
// Heuristic: keep the first word, and the the first word containing digits
ret := clientTag{
AppName: APP_NAME,
Version: APP_VERSION,
}
ver = strings.Trim(strings.Replace(ver, ":", " ", -1), " ")
words := strings.Split(ver, " ")
for _, word := range words[1:] {
if strings.ContainsAny(word, "0123456789") {
ret.AppName = words[0]
ret.Version = strings.Replace(word, "(", "", -1) // AndroIRC
break
}
}
// Strip leading v from mIRC
if len(ret.Version) >= 2 && (ret.Version[0] == 'v' || ret.Version[0] == 'V') && strings.ContainsAny(string(ret.Version[1]), "0123456789") {
ret.Version = ret.Version[1:]
}
return ret
}