changeset 94146:096ad76b9ccf

(Fmultibyte_char_to_unibyte): Return latin1 chars unchanged.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 18 Apr 2008 03:26:55 +0000
parents 3af508d0bd74
children 587f5f26f25d
files src/ChangeLog src/character.c
diffstat 2 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Apr 18 02:56:45 2008 +0000
+++ b/src/ChangeLog	Fri Apr 18 03:26:55 2008 +0000
@@ -159,6 +159,8 @@
 
 2008-04-18  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* character.c (Fmultibyte_char_to_unibyte): Return latin1 chars unchanged.
+
 	* fileio.c (Fexpand_file_name): Refine last fix so `nm' is only
 	relocated if it points to `name'.
 
--- a/src/character.c	Fri Apr 18 02:56:45 2008 +0000
+++ b/src/character.c	Fri Apr 18 03:26:55 2008 +0000
@@ -326,9 +326,7 @@
 
 DEFUN ("unibyte-char-to-multibyte", Funibyte_char_to_multibyte,
        Sunibyte_char_to_multibyte, 1, 1, 0,
-       doc: /* Convert the unibyte character CH to multibyte character.
-The multibyte character is a result of decoding CH by
-the current unibyte charset (see `unibyte-charset').  */)
+       doc: /* Convert the byte CH to multibyte character.  */)
      (ch)
      Lisp_Object ch;
 {
@@ -348,18 +346,24 @@
 
 DEFUN ("multibyte-char-to-unibyte", Fmultibyte_char_to_unibyte,
        Smultibyte_char_to_unibyte, 1, 1, 0,
-       doc: /* Convert the multibyte character CH to unibyte character.\n\
-The unibyte character is a result of encoding CH by
-the current primary charset (value of `charset-primary').  */)
+       doc: /* Convert the multibyte character CH to a byte.
+If the multibyte character does not represent a byte, return -1.  */)
      (ch)
      Lisp_Object ch;
 {
-  int c;
+  int cm;
 
   CHECK_CHARACTER (ch);
-  c = XFASTINT (ch);
-  c = CHAR_TO_BYTE8 (c);
-  return make_number (c);
+  cm = XFASTINT (ch);
+  if (cm < 256)
+    /* Can't distinguish a byte read from a unibyte buffer from
+       a latin1 char, so let's let it slide.  */
+    return ch;
+  else
+    {
+      int cu = CHAR_TO_BYTE8 (cm);
+      return make_number (cu);
+    }
 }
 
 DEFUN ("char-bytes", Fchar_bytes, Schar_bytes, 1, 1, 0,