comparison src/fns.c @ 49656:46090ea2c5c3

(string_to_multibyte): New function. (Fstring_to_multibyte): New function. (syms_of_fns): Defsubr it.
author Kenichi Handa <handa@m17n.org>
date Sun, 09 Feb 2003 08:37:36 +0000
parents c1dbdec496c3
children d7f7ccbc302a
comparison
equal deleted inserted replaced
49655:9ae045dbc337 49656:46090ea2c5c3
1033 0, 1); 1033 0, 1);
1034 1034
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
1041 string_make_unibyte (string) 1072 string_make_unibyte (string)
1042 Lisp_Object string; 1073 Lisp_Object string;
1138 string = new_string; 1169 string = new_string;
1139 STRING_SET_INTERVALS (string, NULL_INTERVAL); 1170 STRING_SET_INTERVALS (string, NULL_INTERVAL);
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.
1146 This is an alist which represents the same mapping from objects to objects, 1195 This is an alist which represents the same mapping from objects to objects,
1147 but does not share the alist structure with ALIST. 1196 but does not share the alist structure with ALIST.
5543 defsubr (&Scopy_sequence); 5592 defsubr (&Scopy_sequence);
5544 defsubr (&Sstring_make_multibyte); 5593 defsubr (&Sstring_make_multibyte);
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);
5551 defsubr (&Snthcdr); 5601 defsubr (&Snthcdr);
5552 defsubr (&Snth); 5602 defsubr (&Snth);