summaryrefslogtreecommitdiff
path: root/irc
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2020-10-29 08:59:28 +0100
committerHubert Hirtz <hubert@hirtz.pm>2020-11-19 19:45:52 +0100
commitcf5d7431d754b61fcd929951326eaea27bc74bd1 (patch)
tree343c8adcbd57e126220fc3ed3a426b9528c11ee7 /irc
parentConsider the CHANTYPES isupport token (diff)
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.
Diffstat (limited to 'irc')
-rw-r--r--irc/states.go7
-rw-r--r--irc/tokens.go20
2 files changed, 25 insertions, 2 deletions
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)