1 ;;; liece-coding.el --- Converting string with apropriate coding system.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: IRC, liece, coding-system, MULE
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.
35 (eval-when-compile (require 'liece-compat))
37 (defgroup liece-coding nil
38 "Code conversion group"
43 (defcustom liece-mime-charset-for-write 'iso-2022-jp-2
44 "Charset used in any transferred messages."
48 (defcustom liece-mime-charset-for-read 'x-ctext
49 "Charset used in any transferred messages."
53 (static-when (featurep 'xemacs)
54 (define-obsolete-variable-alias 'liece-default-mime-charset
55 'liece-mime-charset-for-write)
56 (define-obsolete-variable-alias 'liece-default-mime-charset-for-read
57 'liece-mime-charset-for-read))
59 (defcustom liece-detect-coding-system nil
60 "Whether use coding system auto detection."
64 (defcustom liece-detect-coding-region-function
65 (function liece-detect-coding-region)
66 "User customizable `detect-coding-region'."
70 (defcustom liece-detect-coding-string-function
71 (function liece-detect-coding-string)
72 "User customizable detect-coding-string."
76 (defcustom liece-decode-coding-string-function
77 (function decode-coding-string)
78 "User customizable `decode-coding-string'."
82 (defun liece-coding-encode-charset-region (start end &optional lbt)
83 (encode-mime-charset-region start end liece-mime-charset-for-write lbt))
85 (defun liece-coding-decode-charset-region (start end)
86 (let ((cs (if (and liece-detect-coding-system
87 (fboundp liece-detect-coding-region-function))
88 (funcall liece-detect-coding-region-function start end)
89 (mime-charset-to-coding-system liece-mime-charset-for-read))))
90 (decode-coding-region start end cs)))
92 (defun liece-detect-coding-region (start end)
93 (let ((cs (detect-coding-region start end)))
96 (if (featurep 'xemacs)
97 (eval '(setq cs (coding-system-name cs))))
100 (defun liece-coding-encode-charset-string (str &optional lbt)
101 (encode-mime-charset-string str liece-mime-charset-for-write lbt))
104 (when (fboundp 'detect-coding-string)
105 (defun liece-detect-coding-string (str)
106 (let ((cs (detect-coding-string str)))
109 (static-if (fboundp 'coding-system-name)
110 (coding-system-name cs)
113 (defun liece-coding-decode-charset-string (str)
114 (let ((cs (or (and liece-detect-coding-system
115 (fboundp liece-detect-coding-string-function)
116 (funcall liece-detect-coding-string-function str))
117 (mime-charset-to-coding-system liece-mime-charset-for-read))))
118 (funcall liece-decode-coding-string-function str cs)))
120 (provide 'liece-coding)
122 ;;; liece-coding.el ends here