Update.
[riece] / lisp / riece-inlines.el
1 ;;; riece-inlines.el --- inline functions
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; RFC2812, 2.2 "Character codes" says:
28 ;;    Because of IRC's Scandinavian origin, the characters {}|^ are
29 ;;    considered to be the lower case equivalents of the characters []\~,
30 ;;    respectively. This is a critical issue when determining the
31 ;;    equivalence of two nicknames or channel names.
32
33 ;;; Code:
34
35 (defsubst scandinavian-downcase (string)
36   (let* ((result (downcase string))
37          (length (length result))
38          (index 0))
39     (while (< index length)
40       (if (eq (aref result index) ?\[)
41           (aset result index ?{)
42         (if (eq (aref result index) ?\])
43             (aset result index ?})
44           (if (eq (aref result index) ?\\)
45               (aset result index ?|)
46             (if (eq (aref result index) ?~)
47                 (aset result index ?^)))))
48       (setq index (1+ index)))
49     result))
50
51 (defsubst scandinavian-equal-ignore-case (s1 s2)
52   (string-equal (scandinavian-downcase s1) (scandinavian-downcase s2)))
53
54 (defsubst scandinavian-member-ignore-case (thing list)
55   (catch 'found
56     (while list
57       (if (and (stringp (car list))
58                (scandinavian-equal-ignore-case (car list) thing))
59           (throw 'found list)
60         (setq list (cdr list))))))
61
62 (provide 'riece-inlines)
63
64 ;;; riece-inlines.el ends here