changeset 88953:b18e038d980f

(Fstring_to_multibyte): New function. (syms_of_fns): Declare Fstring_to_multibyte as Lisp subroutine.
author Kenichi Handa <handa@m17n.org>
date Wed, 31 Jul 2002 07:11:47 +0000
parents f74c5b0985f1
children 363e137c2601
files src/fns.c
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/fns.c	Wed Jul 31 07:11:28 2002 +0000
+++ b/src/fns.c	Wed Jul 31 07:11:47 2002 +0000
@@ -1055,6 +1055,40 @@
     }
   return string;
 }
+
+
+DEFUN ("string-to-multibyte", Fstring_to_multibyte, Sstring_to_multibyte,
+       1, 1, 0,
+       doc: /* Return a multibyte string with the same individual chars as STRING.
+If STRING is multibyte, the result is STRING itself.
+Otherwise it is a newly created string, with no text properties.
+
+If STRING is unibyte and contains an 8-bit byte, it is converted to
+the corresponding multibyte character of charset `eight-bit'.  */)
+     (string)
+     Lisp_Object string;
+{
+  CHECK_STRING (string);
+
+  if (! STRING_MULTIBYTE (string))
+    {
+      Lisp_Object new_string;
+      int nchars, nbytes;
+
+      nchars = XSTRING (string)->size;
+      nbytes = parse_str_to_multibyte (XSTRING (string)->data,
+				       STRING_BYTES (XSTRING (string)));
+      new_string = make_uninit_multibyte_string (nchars, nbytes);
+      bcopy (XSTRING (string)->data, XSTRING (new_string)->data,
+	     STRING_BYTES (XSTRING (string)));
+      if (nbytes != STRING_BYTES (XSTRING (string)))
+	str_to_multibyte (XSTRING (new_string)->data, nbytes,
+			  STRING_BYTES (XSTRING (string)));
+      string = new_string;
+      XSTRING (string)->intervals = NULL_INTERVAL;
+    }
+  return string;
+}
 
 DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0,
        doc: /* Return a copy of ALIST.
@@ -4898,6 +4932,7 @@
   defsubr (&Sstring_make_unibyte);
   defsubr (&Sstring_as_multibyte);
   defsubr (&Sstring_as_unibyte);
+  defsubr (&Sstring_to_multibyte);
   defsubr (&Scopy_alist);
   defsubr (&Ssubstring);
   defsubr (&Snthcdr);