]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/international/mule-cmds.el (encode-coding-char): Fix ASCII case
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 28 May 2019 23:33:20 +0000 (19:33 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 28 May 2019 23:33:20 +0000 (19:33 -0400)
Don't bother with string-as-multibyte since `string` already returns
multibyte when needed.  Don't forget to encode when the string is
ASCII, e.g. for ebcdic case and to make sure we always return
a unibyte string.

* test/lisp/international/mule-tests.el (mule-cmds-tests--encode-ebcdic):
New test.

lisp/international/mule-cmds.el
test/lisp/international/mule-tests.el

index 27296ecfb2cde74035009b6f7c9a1337e18735a6..ecdab5e931d8481a3b85c63f07eb95121c6cb4eb 100644 (file)
@@ -2913,13 +2913,13 @@ If there's no description string for VALUE, return nil."
 If CODING-SYSTEM can't safely encode CHAR, return nil.
 The 3rd optional argument CHARSET, if non-nil, is a charset preferred
 on encoding."
-  (let* ((str1 (string-as-multibyte (string char)))
-        (str2 (string-as-multibyte (string char char)))
+  (let* ((str1 (string char))
+        (str2 (string char char))
         (found (find-coding-systems-string str1))
        enc1 enc2 i1 i2)
-    (if (and (consp found)
-            (eq (car found) 'undecided))
-       str1
+    (if (eq (car-safe found) 'undecided) ;Aka (not (multibyte-string-p str1))
+        ;; `char' is ASCII.
+       (encode-coding-string str1 coding-system)
       (when (memq (coding-system-base coding-system) found)
        ;; We must find the encoded string of CHAR.  But, just encoding
        ;; CHAR will put extra control sequences (usually to designate
index 4c937caa142d40715a9d02cfd3aa928767e70198..678cbc297381762f9ab07522581190f6b640459d 100644 (file)
                      (find-auto-coding "" (buffer-size)))
                    '(utf-8 . :coding)))))
 
+(ert-deftest mule-cmds-tests--encode-ebcdic ()
+  (should (equal (encode-coding-char ?a 'ebcdic-int) "\201"))
+  (should (not (multibyte-string-p (encode-coding-char ?a 'utf-8)))))
+
 ;; Stop "Local Variables" above causing confusion when visiting this file.
 \f