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
44 (if (mime-charset-p 'iso-2022-jp-2)
46 default-mime-charset-for-write)
47 "Charset used in any transferred messages."
51 (defcustom liece-mime-charset-for-read
52 (if (mime-charset-p 'x-ctext)
55 "Charset used in any transferred messages."
59 (static-when (featurep 'xemacs)
60 (define-obsolete-variable-alias 'liece-default-mime-charset
61 'liece-mime-charset-for-write)
62 (define-obsolete-variable-alias 'liece-default-mime-charset-for-read
63 'liece-mime-charset-for-read))
65 (defcustom liece-detect-coding-system nil
66 "Whether use coding system auto detection."
70 (defcustom liece-detect-coding-region-function
71 (function liece-detect-coding-region)
72 "User customizable `detect-coding-region'."
76 (defcustom liece-detect-coding-string-function
77 (function liece-detect-coding-string)
78 "User customizable detect-coding-string."
82 (defcustom liece-decode-coding-string-function
83 (function decode-coding-string)
84 "User customizable `decode-coding-string'."
88 (defun liece-coding-encode-charset-region (start end &optional lbt)
89 (encode-mime-charset-region start end liece-mime-charset-for-write lbt))
91 (defun liece-coding-decode-charset-region (start end)
92 (let ((cs (if (and liece-detect-coding-system
93 (fboundp liece-detect-coding-region-function))
94 (funcall liece-detect-coding-region-function start end)
95 (mime-charset-to-coding-system liece-mime-charset-for-read))))
96 (decode-coding-region start end cs)))
98 (defun liece-detect-coding-region (start end)
99 (let ((cs (detect-coding-region start end)))
102 (if (featurep 'xemacs)
103 (eval '(setq cs (coding-system-name cs))))
106 (defun liece-coding-encode-charset-string (str &optional lbt)
107 (encode-mime-charset-string str liece-mime-charset-for-write lbt))
110 (when (fboundp 'detect-coding-string)
111 (defun liece-detect-coding-string (str)
112 (let ((cs (detect-coding-string str)))
115 (static-if (fboundp 'coding-system-name)
116 (coding-system-name cs)
119 (defun liece-coding-decode-charset-string (str)
120 (let ((cs (or (and liece-detect-coding-system
121 (fboundp liece-detect-coding-string-function)
122 (funcall liece-detect-coding-string-function str))
123 (mime-charset-to-coding-system liece-mime-charset-for-read))))
124 (funcall liece-decode-coding-string-function str cs)))
126 (provide 'liece-coding)
128 ;;; liece-coding.el ends here