1 ;;; riece-coding.el --- converting string with coding system
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece, coding-system, MULE
8 ;; This file is part of Riece.
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)
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.
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.
27 (require 'riece-globals)
29 (defgroup riece-coding nil
35 (defcustom riece-default-coding-system
37 (cons 'ctext 'iso-2022-jp-2))
38 "Coding system for process I/O.
39 The value is a coding system, or a cons cell (DECODING . ENCODING)
40 specifying the coding systems for decoding and encoding respectively."
41 :type '(choice (symbol :tag "Coding system")
42 (cons (symbol :tag "Input coding system")
43 (symbol :tag "Output coding system"))
44 (const nil :tag "No conversion"))
47 (if (fboundp 'encode-coding-string)
48 (defalias 'riece--encode-coding-string 'encode-coding-string)
49 (defalias 'riece--encode-coding-string 'identity))
51 (if (fboundp 'decode-coding-string)
52 (defalias 'riece--decode-coding-string 'decode-coding-string)
53 (defalias 'riece--decode-coding-string 'identity))
55 (defun riece-encode-coding-string (string)
56 (if (and (local-variable-p 'riece-coding-system (current-buffer))
57 riece-coding-system) ;should be nil on non-Mule environment
58 (if (consp riece-coding-system)
59 (riece--encode-coding-string string (cdr riece-coding-system))
60 (riece--encode-coding-string string riece-coding-system))
63 (defun riece-decode-coding-string (string)
64 (if (and (local-variable-p 'riece-coding-system (current-buffer))
65 riece-coding-system) ;should be nil on non-Mule environment
66 (riece-decode-coding-string-1 string
67 (if (consp riece-coding-system)
68 (car riece-coding-system)
72 (defun riece-decode-coding-string-1 (string coding-system)
73 (let* ((decoded (riece--decode-coding-string string coding-system))
74 (length (length decoded)))
75 (put-text-property 0 length 'riece-decoded-encoded-string
77 (put-text-property 0 length 'riece-decoded-coding-system
78 coding-system decoded)
81 ;; The following functions are API used by handler functions. For the
82 ;; meantime DECODED is actually a string (with some text properties).
83 ;; In the future, however, the implementation _should_ be changed so
84 ;; that decoding phase is delayed until the body of handler functions.
85 (defun riece-decoded-coding-system (decoded)
86 "Return the coding-system used for decoding DECODED."
87 (get-text-property 0 'riece-decoded-coding-system decoded))
89 (defun riece-decoded-encoded-string (decoded)
90 "Return the string before decoding."
91 (get-text-property 0 'riece-decoded-encoded-string decoded))
93 (defalias 'riece-decoded-string 'identity)
95 (provide 'riece-coding)
97 ;;; riece-coding.el ends here