aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2008-06-25 02:43:59 +0000
committerKenichi Handa2008-06-25 02:43:59 +0000
commitb4480f1678bbda4bea13cff29d79a13b18f1df9f (patch)
tree644ac7fbed7a6da043852648e3f22084486fc4a0 /src
parented008205fc064e0fda74421e1a4f1037c7edde1e (diff)
downloademacs-b4480f1678bbda4bea13cff29d79a13b18f1df9f.tar.gz
emacs-b4480f1678bbda4bea13cff29d79a13b18f1df9f.zip
(Fstring_to_unibyte): New function.
(syms_of_fns): Defsubr it.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/fns.c b/src/fns.c
index b4c84b16f70..7511eacb03a 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1131,6 +1131,35 @@ correct sequence. */)
1131 return string_to_multibyte (string); 1131 return string_to_multibyte (string);
1132} 1132}
1133 1133
1134DEFUN ("string-to-unibyte", Fstring_to_unibyte, Sstring_to_unibyte,
1135 1, 2, 0,
1136 doc: /* Return a unibyte string with the same individual chars as STRING.
1137If STRING is unibyte, the result is STRING itself.
1138Otherwise it is a newly created string, with no text properties,
1139where each `eight-bit' character is converted to the corresponding byte.
1140If STRING contains a non-ASCII, non-`eight-bit' character,
1141an error is signaled.
1142If the optional 2nd arg ACCEPT-LATIN-1 is non-nil, a Latin-1 character
1143doesn't cause an error, but is converted to a byte of same code. */)
1144 (string, accept_latin_1)
1145 Lisp_Object string, accept_latin_1;
1146{
1147 CHECK_STRING (string);
1148
1149 if (STRING_MULTIBYTE (string))
1150 {
1151 EMACS_INT chars = SCHARS (string);
1152 unsigned char *str = (unsigned char *) xmalloc (chars);
1153 EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars,
1154 ! NILP (accept_latin_1));
1155 if (converted < chars)
1156 error ("Can't convert the %dth character to unibyte", converted);
1157 string = make_unibyte_string (str, chars);
1158 xfree (str);
1159 }
1160 return string;
1161}
1162
1134 1163
1135DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, 1164DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0,
1136 doc: /* Return a copy of ALIST. 1165 doc: /* Return a copy of ALIST.
@@ -5235,6 +5264,7 @@ both `use-dialog-box' and this variable are non-nil. */);
5235 defsubr (&Sstring_as_multibyte); 5264 defsubr (&Sstring_as_multibyte);
5236 defsubr (&Sstring_as_unibyte); 5265 defsubr (&Sstring_as_unibyte);
5237 defsubr (&Sstring_to_multibyte); 5266 defsubr (&Sstring_to_multibyte);
5267 defsubr (&Sstring_to_unibyte);
5238 defsubr (&Scopy_alist); 5268 defsubr (&Scopy_alist);
5239 defsubr (&Ssubstring); 5269 defsubr (&Ssubstring);
5240 defsubr (&Ssubstring_no_properties); 5270 defsubr (&Ssubstring_no_properties);