From 88dad6e7cba24726c9cd5b1c247510ff27351ab9 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Wed, 31 Jul 2002 07:11:47 +0000 Subject: [PATCH] (Fstring_to_multibyte): New function. (syms_of_fns): Declare Fstring_to_multibyte as Lisp subroutine. --- src/fns.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/fns.c b/src/fns.c index 9f2837943ad..0a1ce7d26da 100644 --- a/src/fns.c +++ b/src/fns.c @@ -1055,6 +1055,40 @@ multibyte character of charset `eight-bit-control' or `eight-bit-graphic'. */) } 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 @@ invoked by mouse clicks and mouse menu items. */); defsubr (&Sstring_make_unibyte); defsubr (&Sstring_as_multibyte); defsubr (&Sstring_as_unibyte); + defsubr (&Sstring_to_multibyte); defsubr (&Scopy_alist); defsubr (&Ssubstring); defsubr (&Snthcdr); -- 2.39.5