1 ;;; liece-q-el.el --- CTCP binary data quotation in emacs-lisp.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: IRC, liece, CTCP
9 ;; This file is part of Liece.
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)
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.
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.
32 (defconst liece-quote-strings
33 '(("\\\\" . "\\") ("\\a" . "
\ 1") ("\\n" . "\n") ("\\r" . "\r")))
35 (defun liece-quote-el-decode-region (start end)
36 "Decode binary data between START and END."
39 (narrow-to-region start end)
40 (dolist (pair liece-quote-strings)
41 (goto-char (point-min)) (replace-string (car pair) (cdr pair)))))
43 (defun liece-quote-el-decode-string (string)
44 "Decode binary data from STRING."
49 (liece-quote-el-decode-string (point-min) (point-max))
50 (buffer-substring (point-min) (point-max)))))
52 (defun liece-quote-el-encode-region (start end)
53 "Encode binary data between START and END."
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)
63 (goto-char (point-min))
64 (while (search-forward "\n" nil t)
65 (backward-delete-char 1)
67 (goto-char (point-min))
68 (while (search-forward "\r" nil t)
69 (backward-delete-char 1)
72 (defun liece-quote-el-encode-string (string)
73 "Encode binary data from STRING."
79 (liece-quote-el-encode-region (point-min) (point-max))
80 (buffer-substring (point-min) (point-max)))))
82 (defalias 'liece-quote-decode-string 'liece-quote-el-decode-string)
83 (defalias 'liece-quote-encode-string 'liece-quote-el-encode-string)
85 (defalias 'liece-quote-decode-region 'liece-quote-el-decode-region)
86 (defalias 'liece-quote-encode-region 'liece-quote-el-encode-region)
90 ;;; liece-q-el.el ends here