Fix typo.
[riece] / lisp / riece-coding.el
1 ;;; riece-coding.el --- converting string with coding system
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece, coding-system, MULE
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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Code:
26
27 (require 'riece-globals)
28 (require 'riece-options)
29
30 (defun riece-encode-coding-string (string)
31   (if (and (local-variable-p 'riece-coding-system (current-buffer))
32            riece-coding-system)         ;should be nil on non-Mule environment
33       (encode-coding-string string (if (consp riece-coding-system)
34                                        (cdr riece-coding-system)
35                                      riece-coding-system))
36     string))
37
38 (defun riece-decode-coding-string (string)
39   (if (and (local-variable-p 'riece-coding-system (current-buffer))
40            riece-coding-system)         ;should be nil on non-Mule environment
41       (riece-decode-coding-string-1 string
42                                     (if (consp riece-coding-system)
43                                         (car riece-coding-system)
44                                       riece-coding-system))
45     string))
46
47 (defun riece-decode-coding-string-1 (string coding-system)
48   (let* ((decoded (decode-coding-string string coding-system))
49          (length (length decoded)))
50     (put-text-property 0 length 'riece-decoded-encoded-string
51                        string decoded)
52     (put-text-property 0 length 'riece-decoded-coding-system
53                        coding-system decoded)
54     decoded))
55
56 ;; The following functions are API used by handler functions.  For the
57 ;; meantime DECODED is actually a string (with some text properties).
58 ;; In the future, however, the implementation _should_ be changed so
59 ;; that decoding phase is delayed until the body of handler functions.
60 (defun riece-decoded-coding-system (decoded)
61   "Return the coding-system used for decoding DECODED."
62   (get-text-property 0 'riece-decoded-coding-system decoded))
63
64 (defun riece-decoded-encoded-string (decoded)
65   "Return the string before decoding."
66   (get-text-property 0 'riece-decoded-encoded-string decoded))
67
68 (defalias 'riece-decoded-string 'identity)
69
70 (provide 'riece-coding)
71
72 ;;; riece-coding.el ends here