You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

userhost.go 1.1KB

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