1// written by Daniel Oaks <daniel@danieloaks.net> 2// released under the ISC license 3 4package ircutils 5 6import "strings" 7 8// UserHost holds a username+host combination 9type UserHost struct { 10 Nick string 11 User string 12 Host string 13} 14 15// ParseUserhost takes a userhost string and returns a UserHost instance. 16func ParseUserhost(userhost string) UserHost { 17 var uh UserHost 18 19 if len(userhost) == 0 { 20 return uh 21 } 22 23 if strings.Contains(userhost, "!") { 24 usersplit := strings.SplitN(userhost, "!", 2) 25 var rest string 26 if len(usersplit) == 2 { 27 uh.Nick = usersplit[0] 28 rest = usersplit[1] 29 } else { 30 rest = usersplit[0] 31 } 32 33 hostsplit := strings.SplitN(rest, "@", 2) 34 if len(hostsplit) == 2 { 35 uh.User = hostsplit[0] 36 uh.Host = hostsplit[1] 37 } else { 38 uh.User = hostsplit[0] 39 } 40 } else { 41 hostsplit := strings.SplitN(userhost, "@", 2) 42 if len(hostsplit) == 2 { 43 uh.Nick = hostsplit[0] 44 uh.Host = hostsplit[1] 45 } else { 46 uh.User = hostsplit[0] 47 } 48 } 49 50 return uh 51} 52 53// // Canonical returns the canonical string representation of the userhost. 54// func (uh *UserHost) Canonical() string { 55// return "" 56// } 57