mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 07:29:31 +01:00
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
// written by Daniel Oaks <daniel@danieloaks.net>
|
|
// released under the ISC license
|
|
|
|
package ircutils
|
|
|
|
import "strings"
|
|
|
|
// UserHost holds a username+host combination
|
|
type UserHost struct {
|
|
Nick string
|
|
User string
|
|
Host string
|
|
}
|
|
|
|
// ParseUserhost takes a userhost string and returns a UserHost instance.
|
|
func ParseUserhost(userhost string) UserHost {
|
|
var uh UserHost
|
|
|
|
if len(userhost) == 0 {
|
|
return uh
|
|
}
|
|
|
|
if strings.Contains(userhost, "!") {
|
|
usersplit := strings.SplitN(userhost, "!", 2)
|
|
var rest string
|
|
if len(usersplit) == 2 {
|
|
uh.Nick = usersplit[0]
|
|
rest = usersplit[1]
|
|
} else {
|
|
rest = usersplit[0]
|
|
}
|
|
|
|
hostsplit := strings.SplitN(rest, "@", 2)
|
|
if len(hostsplit) == 2 {
|
|
uh.User = hostsplit[0]
|
|
uh.Host = hostsplit[1]
|
|
} else {
|
|
uh.User = hostsplit[0]
|
|
}
|
|
} else {
|
|
hostsplit := strings.SplitN(userhost, "@", 2)
|
|
if len(hostsplit) == 2 {
|
|
uh.Nick = hostsplit[0]
|
|
uh.Host = hostsplit[1]
|
|
} else {
|
|
uh.User = hostsplit[0]
|
|
}
|
|
}
|
|
|
|
return uh
|
|
}
|
|
|
|
// // Canonical returns the canonical string representation of the userhost.
|
|
// func (uh *UserHost) Canonical() string {
|
|
// return ""
|
|
// }
|