changeset 21034:f3128abaf8aa

(DEFAULT_NONASCII_INSERT_OFFSET): Macro definition is moved to charset.h. (unibyte_char_to_multibyte): Always return a valid character. (Funibyte_char_to_multibyte): New function. (syms_of_charset): Defsubr it. Doc-string of nonascii-insert-offset is modified.
author Kenichi Handa <handa@m17n.org>
date Tue, 03 Mar 1998 01:29:16 +0000
parents 9f32198e0d9f
children 5d18067080d0
files src/charset.c
diffstat 1 files changed, 31 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/charset.c	Tue Mar 03 01:29:16 1998 +0000
+++ b/src/charset.c	Tue Mar 03 01:29:16 1998 +0000
@@ -286,24 +286,24 @@
   return MAKE_CHAR (alt_charset, c1, c2);
 }
 
-#define DEFAULT_NONASCII_INSERT_OFFSET 0x800
+/* Convert the unibyte character C to multibyte based on
+   Vnonascii_translate_table or nonascii_insert_offset.  If they can't
+   convert C to a valid multibyte character, convert it based on
+   DEFAULT_NONASCII_INSERT_OFFSET which makes C a Latin-1 character.  */
 
-/* Convert the unibyte character C to multibyte
-   based on Vnonascii_translate_table or nonascii_insert_offset.
-   Note that copy_text in insdel.c has similar code.  */
-
-int
 unibyte_char_to_multibyte (c)
      int c;
 {
-  if (c >= 0200 && c < 0400)
+  if (c >= 0240 && c < 0400)
     {
+      int c_save = c;
+
       if (! NILP (Vnonascii_translate_table))
 	c = XINT (Faref (Vnonascii_translate_table, make_number (c)));
       else if (nonascii_insert_offset > 0)
 	c += nonascii_insert_offset;
-      else
-	c += DEFAULT_NONASCII_INSERT_OFFSET;
+      if (c >= 0240 && (c < 0400 || ! VALID_MULTIBYTE_CHAR_P (c)))
+	c = c_save + DEFAULT_NONASCII_INSERT_OFFSET;
     }
   return c;
 }
@@ -864,6 +864,26 @@
   return (CHAR_VALID_P (XFASTINT (object), !NILP (genericp)) ? Qt : Qnil);
 }
 
+DEFUN ("unibyte-char-to-multibyte", Funibyte_char_to_multibyte,
+       Sunibyte_char_to_multibyte, 1, 1, 0,
+  "Convert the unibyte character CH to multibyte character.\n\
+The conversion is done based on nonascii-translate-table (which see)\n\
+ or nonascii-insert-offset (which see).")
+  (ch)
+     Lisp_Object ch;
+{
+  int c;
+
+  CHECK_NUMBER (ch, 0);
+  c = XINT (ch);
+  if (c < 0 || c >= 0400)
+    error ("Invalid unibyte character: %d", c);
+  c = unibyte_char_to_multibyte (c);
+  if (c < 0)
+    error ("Can't convert to multibyte character: %d", XINT (ch));
+  return make_number (c);
+}
+
 DEFUN ("char-bytes", Fchar_bytes, Schar_bytes, 1, 1, 0,
   "Return byte length of multi-byte form of CHAR.")
   (ch)
@@ -1663,6 +1683,7 @@
   defsubr (&Schar_charset);
   defsubr (&Siso_charset);
   defsubr (&Schar_valid_p);
+  defsubr (&Sunibyte_char_to_multibyte);
   defsubr (&Schar_bytes);
   defsubr (&Schar_width);
   defsubr (&Sstring_width);
@@ -1708,7 +1729,7 @@
   leading_code_private_22 = LEADING_CODE_PRIVATE_22;
 
   DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset,
-    "Offset for converting non-ASCII unibyte codes 0200...0377 to multibyte.\n\
+    "Offset for converting non-ASCII unibyte codes 0240...0377 to multibyte.\n\
 This is used for converting unibyte text to multibyte,\n\
 and for inserting character codes specified by number.\n\n\
 Conversion is performed only when multibyte characters are enabled,\n\