diff options
| author | Kenichi Handa | 2003-02-09 08:37:36 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2003-02-09 08:37:36 +0000 |
| commit | 2df18cdb0b3656a3c3bca6546fdc58583e3ce4ee (patch) | |
| tree | a359a221ac0a36ed4af1601c0c92318478a9f275 /src/fns.c | |
| parent | fd8771f59fabfa7c5d76c2d9fc8916ec721ba071 (diff) | |
| download | emacs-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.c | 50 |
1 files changed, 50 insertions, 0 deletions
| @@ -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 | |||
| 1044 | Lisp_Object | ||
| 1045 | string_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 | ||
| 1040 | Lisp_Object | 1071 | Lisp_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 | |||
| 1175 | DEFUN ("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. | ||
| 1178 | If STRING is multibyte, the resutl is STRING itself. | ||
| 1179 | Otherwise it is a newly created string, with no text properties. | ||
| 1180 | Characters 0200 through 0237 are converted to eight-bit-control | ||
| 1181 | characters of the same character code. Characters 0240 through 0377 | ||
| 1182 | are converted to eight-bit-control characters of the same character | ||
| 1183 | codes. */) | ||
| 1184 | (string) | ||
| 1185 | Lisp_Object string; | ||
| 1186 | { | ||
| 1187 | CHECK_STRING (string); | ||
| 1188 | |||
| 1189 | return string_to_multibyte (string); | ||
| 1190 | } | ||
| 1191 | |||
| 1143 | 1192 | ||
| 1144 | DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, | 1193 | DEFUN ("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); |