From e4d5d2737b6660a0543424930167b27af4892b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Fri, 11 Jan 2019 02:19:57 +0100 Subject: [PATCH] Use strings.Replacer to unescape tags --- pkg/irc/message.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/irc/message.go b/pkg/irc/message.go index 982e300c..08cf045e 100644 --- a/pkg/irc/message.go +++ b/pkg/irc/message.go @@ -151,11 +151,14 @@ func splitParam(param string) (string, string) { return parts[0], "" } +var unescapeTagReplacer = strings.NewReplacer( + "\\:", ";", + "\\s", " ", + "\\\\", "\\", + "\\r", "\r", + "\\n", "\n", +) + func unescapeTag(s string) string { - s = strings.Replace(s, "\\:", ";", -1) - s = strings.Replace(s, "\\s", " ", -1) - s = strings.Replace(s, "\\\\", "\\", -1) - s = strings.Replace(s, "\\r", "\r", -1) - s = strings.Replace(s, "\\n", "\n", -1) - return s + return unescapeTagReplacer.Replace(s) }