X-Git-Url: https://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-identity.el;h=89e0e21e1dce5ec15f316914c3aab4ce2276570d;hp=ee7e72822e0970ff297ebf8fc217939e4d3e23a6;hb=d1652017cb0170ff664b3b37098cab2f54714132;hpb=bba270d4bab6d579e286c8d5cf8957d2ae039935 diff --git a/lisp/riece-identity.el b/lisp/riece-identity.el index ee7e728..89e0e21 100644 --- a/lisp/riece-identity.el +++ b/lisp/riece-identity.el @@ -26,19 +26,22 @@ (require 'riece-globals) (require 'riece-coding) -(require 'riece-compat) ;riece-set-case-syntax-pair (defvar riece-abbrev-identity-string-function nil) (defvar riece-expand-identity-string-function nil) -(defvar riece-identity-prefix-case-table - (let ((table (copy-case-table (standard-case-table)))) - (riece-set-case-syntax-pair ?\[ ?{ table) - (riece-set-case-syntax-pair ?\] ?} table) - (riece-set-case-syntax-pair ?\\ ?| table) - (riece-set-case-syntax-pair ?~ ?^ table) - table)) - +(defconst riece-identity-prefix-case-pair-alist + '((?\[ . ?{) + (?\] . ?}) + (?\\ . ?|) + (?~ . ?^)) + "An alist used to canonicalize identity-prefix. +RFC2812, 2.2 \"Character codes\" says: + Because of IRC's Scandinavian origin, the characters {}|^ are + considered to be the lower case equivalents of the characters []\~, + respectively. This is a critical issue when determining the + equivalence of two nicknames or channel names.") + (defun riece-identity-prefix (identity) "Return the component sans its server from IDENTITY." (aref identity 0)) @@ -61,42 +64,41 @@ (riece-identity-server ident2)))) (defun riece-identity-canonicalize-prefix (prefix) - "Canonicalize identity PREFIX. -This function downcases PREFIX with Scandinavian alphabet rule. - -RFC2812, 2.2 \"Character codes\" says: - Because of IRC's Scandinavian origin, the characters {}|^ are - considered to be the lower case equivalents of the characters []\~, - respectively. This is a critical issue when determining the - equivalence of two nicknames or channel names." - (let ((old-table (current-case-table))) - (unwind-protect - (progn - (set-case-table riece-identity-prefix-case-table) - (downcase prefix)) - (set-case-table old-table)))) + "Canonicalize identity PREFIX." + (let ((i 0) + c) + (setq prefix (copy-sequence prefix)) + (while (< i (length prefix)) + (if (setq c (cdr (assq (aref prefix i) + riece-identity-prefix-case-pair-alist))) + (aset prefix i c)) + (setq i (1+ i))) + prefix)) (defun riece-identity-equal-no-server (prefix1 prefix2) - "Return t, if IDENT1 and IDENT2 is equal without server." + "Return t, if IDENT1 and IDENT2 is equal without server part." (equal (riece-identity-canonicalize-prefix prefix1) (riece-identity-canonicalize-prefix prefix2))) -(defun riece-identity-member (elt list) +(defun riece-identity-member (elt list &optional no-server) "Return non-nil if an identity ELT is an element of LIST." (catch 'found (while list - (if (and (vectorp (car list)) ;needed because - ;riece-current-channels - ;contains nil. - (riece-identity-equal (car list) elt)) + (if (and (car list) ;needed because riece-current-channels + ;contains nil. + (if no-server + (riece-identity-equal-no-server (car list) elt) + (riece-identity-equal (car list) elt))) (throw 'found list) (setq list (cdr list)))))) -(defun riece-identity-assoc (elt alist) +(defun riece-identity-assoc (elt alist &optional no-server) "Return non-nil if an identity ELT matches the car of an element of ALIST." (catch 'found (while alist - (if (riece-identity-equal (car (car alist)) elt) + (if (if no-server + (riece-identity-equal-no-server (car (car alist)) elt) + (riece-identity-equal (car (car alist)) elt)) (throw 'found (car alist)) (setq alist (cdr alist))))))