[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ecafe1cbb5 10/25: Recognize ASCII and strict CASEMAPPINGs in ERC
From: |
F. Jason Park |
Subject: |
master ecafe1cbb5 10/25: Recognize ASCII and strict CASEMAPPINGs in ERC |
Date: |
Thu, 30 Jun 2022 18:29:53 -0400 (EDT) |
branch: master
commit ecafe1cbb5297ba4df5717b7222fe2c73ef9077c
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Recognize ASCII and strict CASEMAPPINGs in ERC
* lisp/erc/erc.el (erc-downcase, erc--casemapping-rfc1459-strict,
erc--casemapping-rfc1459): Add new translation tables for the latter
two mappings and use them in `erc-downcase'.
* test/lisp/erc/erc-tests.el: Add test for `erc-downcase'.
---
lisp/erc/erc.el | 34 +++++++++++++++++++++++-----------
test/lisp/erc/erc-tests.el | 24 ++++++++++++++++++++++++
2 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 80fc3dfe5f..1584948e93 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -393,18 +393,30 @@ erc-channel-user struct.")
"Hash table of users on the current server.
It associates nicknames with `erc-server-user' struct instances.")
+(defconst erc--casemapping-rfc1459
+ (make-translation-table
+ '((?\[ . ?\{) (?\] . ?\}) (?\\ . ?\|) (?~ . ?^))
+ (mapcar (lambda (c) (cons c (+ c 32))) "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
+
+(defconst erc--casemapping-rfc1459-strict
+ (make-translation-table
+ '((?\[ . ?\{) (?\] . ?\}) (?\\ . ?\|))
+ (mapcar (lambda (c) (cons c (+ c 32))) "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
+
(defun erc-downcase (string)
- "Convert STRING to IRC standard conforming downcase."
- (let ((s (downcase string))
- (c '((?\[ . ?\{)
- (?\] . ?\})
- (?\\ . ?\|)
- (?~ . ?^))))
- (save-match-data
- (while (string-match "[]\\[~]" s)
- (aset s (match-beginning 0)
- (cdr (assq (aref s (match-beginning 0)) c)))))
- s))
+ "Return a downcased copy of STRING with properties.
+Use the CASEMAPPING ISUPPORT parameter to determine the style."
+ (let* ((mapping (erc--get-isupport-entry 'CASEMAPPING 'single))
+ (inhibit-read-only t))
+ (if (equal mapping "ascii")
+ (downcase string)
+ (with-temp-buffer
+ (insert string)
+ (translate-region (point-min) (point-max)
+ (if (equal mapping "rfc1459-strict")
+ erc--casemapping-rfc1459-strict
+ erc--casemapping-rfc1459))
+ (buffer-string)))))
(defmacro erc-with-server-buffer (&rest body)
"Execute BODY in the current ERC server buffer.
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 91e7d50eac..cffb61f708 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -442,6 +442,30 @@
(erc-call-hooks nil parsed))
(should (= hooked 2)))))
+(ert-deftest erc-downcase ()
+ (let ((erc--isupport-params (make-hash-table)))
+
+ (puthash 'PREFIX '("(ov)@+") erc--isupport-params)
+ (puthash 'BOT '("B") erc--isupport-params)
+
+ (ert-info ("ascii")
+ (puthash 'CASEMAPPING '("ascii") erc--isupport-params)
+ (should (equal (erc-downcase "Bob[m]`") "bob[m]`"))
+ (should (equal (erc-downcase "Tilde~") "tilde~" ))
+ (should (equal (erc-downcase "\\O/") "\\o/" )))
+
+ (ert-info ("rfc1459")
+ (puthash 'CASEMAPPING '("rfc1459") erc--isupport-params)
+ (should (equal (erc-downcase "Bob[m]`") "bob{m}`" ))
+ (should (equal (erc-downcase "Tilde~") "tilde^" ))
+ (should (equal (erc-downcase "\\O/") "|o/" )))
+
+ (ert-info ("rfc1459-strict")
+ (puthash 'CASEMAPPING '("rfc1459-strict") erc--isupport-params)
+ (should (equal (erc-downcase "Bob[m]`") "bob{m}`"))
+ (should (equal (erc-downcase "Tilde~") "tilde~" ))
+ (should (equal (erc-downcase "\\O/") "|o/" )))))
+
(ert-deftest erc-ring-previous-command-base-case ()
(ert-info ("Create ring when nonexistent and do nothing")
(let (erc-input-ring
- master updated (a3311dbce0 -> 85c2f3bc3e), F. Jason Park, 2022/06/30
- master 0f52e7ac68 01/25: Rework mutual dependency between erc and erc-backend, F. Jason Park, 2022/06/30
- master c5b78a3379 05/25: Customize displaying of ERC buffers on reconnect, F. Jason Park, 2022/06/30
- master 4ae0707704 03/25: Accept user keyword arg in ERC entry-point commands, F. Jason Park, 2022/06/30
- master a63ed6f78a 04/25: Remove duplicate ERC prompt on reconnect, F. Jason Park, 2022/06/30
- master de53d18a4d 07/25: Don't set erc-server-announced-name unless known, F. Jason Park, 2022/06/30
- master 873499ce06 06/25: Allow exemption from flood penalty in erc-backend, F. Jason Park, 2022/06/30
- master ecafe1cbb5 10/25: Recognize ASCII and strict CASEMAPPINGs in ERC,
F. Jason Park <=
- master 752e860db4 16/25: Address long-standing ERC buffer-naming issues, F. Jason Park, 2022/06/30
- master 85c2f3bc3e 25/25: Update ERC's Info doc with network-ID related changes, F. Jason Park, 2022/06/30
- master 54414ec846 02/25: Initialize erc-server-filter-data in erc-backend, F. Jason Park, 2022/06/30
- master 4e312c07f7 11/25: Make ERC respect spaces in server passwords, F. Jason Park, 2022/06/30
- master 485b84cb7c 08/25: Require erc-networks in erc.el, F. Jason Park, 2022/06/30
- master c356f86b51 09/25: Update ISUPPORT handling in ERC, F. Jason Park, 2022/06/30
- master 1c24af0fcb 12/25: Add helper to determine local channels in ERC, F. Jason Park, 2022/06/30
- master 529e46f128 13/25: Add eventual replacement for erc-default-recipients, F. Jason Park, 2022/06/30
- master 1767b0bd7e 19/25: Don't call erc-auto-query twice on PRIVMSG, F. Jason Park, 2022/06/30
- master 7c47d6c52d 18/25: Register erc-kill-buffer-function locally, F. Jason Park, 2022/06/30