From cf5d7431d754b61fcd929951326eaea27bc74bd1 Mon Sep 17 00:00:00 2001 From: Hubert Hirtz Date: Thu, 29 Oct 2020 08:59:28 +0100 Subject: Consider the CASEMAPPING isupport token Using RFC1459 as a default since servers not advertising this token are likely to be pre-IRCv2, thus following the casemapping described in the RFCs. --- irc/states.go | 7 +++++-- irc/tokens.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'irc') diff --git a/irc/states.go b/irc/states.go index 650c0e1..da5d582 100644 --- a/irc/states.go +++ b/irc/states.go @@ -265,8 +265,11 @@ func (s *Session) IsChannel(name string) bool { } func (s *Session) Casemap(name string) string { - // TODO use CASEMAPPING - return CasemapASCII(name) + if s.features["CASEMAPPING"] == "ascii" { + return CasemapASCII(name) + } else { + return CasemapRFC1459(name) + } } func (s *Session) Users() []string { diff --git a/irc/tokens.go b/irc/tokens.go index 7ad5738..f4ec3c7 100644 --- a/irc/tokens.go +++ b/irc/tokens.go @@ -20,6 +20,26 @@ func CasemapASCII(name string) string { return sb.String() } +func CasemapRFC1459(name string) string { + var sb strings.Builder + sb.Grow(len(name)) + for _, r := range name { + if 'A' <= r && r <= 'Z' { + r += 'a' - 'A' + } else if r == '[' { + r = '{' + } else if r == ']' { + r = '}' + } else if r == '\\' { + r = '|' + } else if r == '~' { + r = '^' + } + sb.WriteRune(r) + } + return sb.String() +} + func word(s string) (w, rest string) { split := strings.SplitN(s, " ", 2) -- cgit v1.2.3