Remove Gnus, making way for new subtree Gnus pkg
[packages] / xemacs-packages / liece / lisp / liece-q-el.el
1 ;;; liece-q-el.el --- CTCP binary data quotation in emacs-lisp.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1999-01-31
6 ;; Revised: 1999-01-31
7 ;; Keywords: IRC, liece, CTCP
8
9 ;; This file is part of Liece.
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26
27 ;;; Commentary:
28 ;; 
29
30 ;;; Code:
31
32 (defconst liece-quote-strings
33   '(("\\\\" . "\\") ("\\a" . "\ 1") ("\\n" . "\n") ("\\r" . "\r")))
34   
35 (defun liece-quote-el-decode-region (start end)
36   "Decode binary data between START and END."
37   (interactive "r")
38   (save-restriction
39     (narrow-to-region start end)
40     (dolist (pair liece-quote-strings)
41       (goto-char (point-min)) (replace-string (car pair) (cdr pair)))))
42
43 (defun liece-quote-el-decode-string (string)
44   "Decode binary data from STRING."
45   (interactive)
46   (save-excursion
47     (with-temp-buffer
48       (insert string)
49       (liece-quote-el-decode-string (point-min) (point-max))
50       (buffer-substring (point-min) (point-max)))))
51
52 (defun liece-quote-el-encode-region (start end)
53   "Encode binary data between START and END."
54   (interactive "r")
55   (save-restriction
56     (narrow-to-region start end)
57     (goto-char (point-min))
58     (while (search-forward "\\" nil t) (insert "\\"))
59     (goto-char (point-min))
60     (while (search-forward "\ 1" nil t)
61       (backward-delete-char 1)
62       (insert "\\a"))
63     (goto-char (point-min))
64     (while (search-forward "\n" nil t)
65       (backward-delete-char 1)
66       (insert "\\n"))
67     (goto-char (point-min))
68     (while (search-forward "\r" nil t)
69       (backward-delete-char 1)
70       (insert "\\r"))))
71
72 (defun liece-quote-el-encode-string (string)
73   "Encode binary data from STRING."
74   (interactive)
75   (save-excursion
76     (with-temp-buffer
77       (erase-buffer)
78       (insert string)
79       (liece-quote-el-encode-region (point-min) (point-max))
80       (buffer-substring (point-min) (point-max)))))
81
82 (defalias 'liece-quote-decode-string 'liece-quote-el-decode-string)
83 (defalias 'liece-quote-encode-string 'liece-quote-el-encode-string)
84
85 (defalias 'liece-quote-decode-region 'liece-quote-el-decode-region)
86 (defalias 'liece-quote-encode-region 'liece-quote-el-encode-region)
87
88 (provide 'liece-q-el)
89
90 ;;; liece-q-el.el ends here
91