aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2008-06-26 07:37:15 +0000
committerKenichi Handa2008-06-26 07:37:15 +0000
commitb529ed1e1756cf04a8712940af0d91f0990b5672 (patch)
tree54faa6892eb36c04d92c51340cd243b5b0c564d2
parenta509862bf359ebe4a30e92016980c0f7634c3456 (diff)
downloademacs-b529ed1e1756cf04a8712940af0d91f0990b5672.tar.gz
emacs-b529ed1e1756cf04a8712940af0d91f0990b5672.zip
(encode-coding-char): Fix for ASCII characters.
-rw-r--r--lisp/international/mule-cmds.el47
1 files changed, 25 insertions, 22 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 0d3f0b01404..2e9b1e100e8 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -2805,29 +2805,32 @@ If there's no description string for VALUE, return nil."
2805(defun encode-coding-char (char coding-system) 2805(defun encode-coding-char (char coding-system)
2806 "Encode CHAR by CODING-SYSTEM and return the resulting string. 2806 "Encode CHAR by CODING-SYSTEM and return the resulting string.
2807If CODING-SYSTEM can't safely encode CHAR, return nil." 2807If CODING-SYSTEM can't safely encode CHAR, return nil."
2808 (let ((str1 (string-as-multibyte (string char))) 2808 (let* ((str1 (string-as-multibyte (string char)))
2809 (str2 (string-as-multibyte (string char char))) 2809 (str2 (string-as-multibyte (string char char)))
2810 (found (find-coding-systems-string str1))
2810 enc1 enc2 i1 i2) 2811 enc1 enc2 i1 i2)
2811 (when (memq (coding-system-base coding-system) 2812 (if (and (consp found)
2812 (find-coding-systems-string str1)) 2813 (eq (car found) 'undecided))
2813 ;; We must find the encoded string of CHAR. But, just encoding 2814 str1
2814 ;; CHAR will put extra control sequences (usually to designate 2815 (when (memq (coding-system-base coding-system) found)
2815 ;; ASCII charset) at the tail if type of CODING is ISO 2022. 2816 ;; We must find the encoded string of CHAR. But, just encoding
2816 ;; To exclude such tailing bytes, we at first encode one-char 2817 ;; CHAR will put extra control sequences (usually to designate
2817 ;; string and two-char string, then check how many bytes at the 2818 ;; ASCII charset) at the tail if type of CODING is ISO 2022.
2818 ;; tail of both encoded strings are the same. 2819 ;; To exclude such tailing bytes, we at first encode one-char
2819 2820 ;; string and two-char string, then check how many bytes at the
2820 (setq enc1 (encode-coding-string str1 coding-system) 2821 ;; tail of both encoded strings are the same.
2821 i1 (length enc1) 2822
2822 enc2 (encode-coding-string str2 coding-system) 2823 (setq enc1 (encode-coding-string str1 coding-system)
2823 i2 (length enc2)) 2824 i1 (length enc1)
2824 (while (and (> i1 0) (= (aref enc1 (1- i1)) (aref enc2 (1- i2)))) 2825 enc2 (encode-coding-string str2 coding-system)
2825 (setq i1 (1- i1) i2 (1- i2))) 2826 i2 (length enc2))
2826 2827 (while (and (> i1 0) (= (aref enc1 (1- i1)) (aref enc2 (1- i2))))
2827 ;; Now (substring enc1 i1) and (substring enc2 i2) are the same, 2828 (setq i1 (1- i1) i2 (1- i2)))
2828 ;; and they are the extra control sequences at the tail to 2829
2829 ;; exclude. 2830 ;; Now (substring enc1 i1) and (substring enc2 i2) are the same,
2830 (substring enc2 0 i2)))) 2831 ;; and they are the extra control sequences at the tail to
2832 ;; exclude.
2833 (substring enc2 0 i2)))))
2831 2834
2832;; Backwards compatibility. These might be better with :init-value t, 2835;; Backwards compatibility. These might be better with :init-value t,
2833;; but that breaks loadup. 2836;; but that breaks loadup.