aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
authorKenichi Handa2003-02-09 08:37:36 +0000
committerKenichi Handa2003-02-09 08:37:36 +0000
commit2df18cdb0b3656a3c3bca6546fdc58583e3ce4ee (patch)
treea359a221ac0a36ed4af1601c0c92318478a9f275 /src/fns.c
parentfd8771f59fabfa7c5d76c2d9fc8916ec721ba071 (diff)
downloademacs-2df18cdb0b3656a3c3bca6546fdc58583e3ce4ee.tar.gz
emacs-2df18cdb0b3656a3c3bca6546fdc58583e3ce4ee.zip
(string_to_multibyte): New function.
(Fstring_to_multibyte): New function. (syms_of_fns): Defsubr it.
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/fns.c b/src/fns.c
index 05b2b824315..0e65055a405 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1035,6 +1035,37 @@ string_make_multibyte (string)
1035 return make_multibyte_string (buf, SCHARS (string), nbytes); 1035 return make_multibyte_string (buf, SCHARS (string), nbytes);
1036} 1036}
1037 1037
1038
1039/* Convert STRING to a multibyte string without changing each
1040 character codes. Thus, characters 0200 trough 0237 are converted
1041 to eight-bit-control characters, and characters 0240 through 0377
1042 are converted eight-bit-graphic characters. */
1043
1044Lisp_Object
1045string_to_multibyte (string)
1046 Lisp_Object string;
1047{
1048 unsigned char *buf;
1049 int nbytes;
1050 int i;
1051
1052 if (STRING_MULTIBYTE (string))
1053 return string;
1054
1055 nbytes = parse_str_to_multibyte (SDATA (string), SBYTES (string));
1056 /* If all the chars are ASCII, they won't need any more bytes
1057 once converted. In that case, we can return STRING itself. */
1058 if (nbytes == SBYTES (string))
1059 return string;
1060
1061 buf = (unsigned char *) alloca (nbytes);
1062 bcopy (SDATA (string), buf, SBYTES (string));
1063 str_to_multibyte (buf, nbytes, SBYTES (string));
1064
1065 return make_multibyte_string (buf, SCHARS (string), nbytes);
1066}
1067
1068
1038/* Convert STRING to a single-byte string. */ 1069/* Convert STRING to a single-byte string. */
1039 1070
1040Lisp_Object 1071Lisp_Object
@@ -1140,6 +1171,24 @@ multibyte character of charset `eight-bit-control' or `eight-bit-graphic'. */)
1140 } 1171 }
1141 return string; 1172 return string;
1142} 1173}
1174
1175DEFUN ("string-to-multibyte", Fstring_to_multibyte, Sstring_to_multibyte,
1176 1, 1, 0,
1177 doc: /* Return a multibyte string with the same individual chars as STRING.
1178If STRING is multibyte, the resutl is STRING itself.
1179Otherwise it is a newly created string, with no text properties.
1180Characters 0200 through 0237 are converted to eight-bit-control
1181characters of the same character code. Characters 0240 through 0377
1182are converted to eight-bit-control characters of the same character
1183codes. */)
1184 (string)
1185 Lisp_Object string;
1186{
1187 CHECK_STRING (string);
1188
1189 return string_to_multibyte (string);
1190}
1191
1143 1192
1144DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, 1193DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0,
1145 doc: /* Return a copy of ALIST. 1194 doc: /* Return a copy of ALIST.
@@ -5545,6 +5594,7 @@ invoked by mouse clicks and mouse menu items. */);
5545 defsubr (&Sstring_make_unibyte); 5594 defsubr (&Sstring_make_unibyte);
5546 defsubr (&Sstring_as_multibyte); 5595 defsubr (&Sstring_as_multibyte);
5547 defsubr (&Sstring_as_unibyte); 5596 defsubr (&Sstring_as_unibyte);
5597 defsubr (&Sstring_to_multibyte);
5548 defsubr (&Scopy_alist); 5598 defsubr (&Scopy_alist);
5549 defsubr (&Ssubstring); 5599 defsubr (&Ssubstring);
5550 defsubr (&Ssubstring_no_properties); 5600 defsubr (&Ssubstring_no_properties);