3 /* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 * As a special exception, the Free Software Foundation gives permission
20 * for additional uses of the text contained in its release of GUILE.
22 * The exception is that, if you link the GUILE library with other files
23 * to produce an executable, this does not by itself cause the
24 * resulting executable to be covered by the GNU General Public License.
25 * Your use of that executable is in no way restricted on account of
26 * linking the GUILE library code into it.
28 * This exception does not however invalidate any other reasons why
29 * the executable file might be covered by the GNU General Public License.
31 * This exception applies only to the code released by the
32 * Free Software Foundation under the name GUILE. If you copy
33 * code from other Free Software Foundation releases into a copy of
34 * GUILE, as the General Public License permits, the exception does
35 * not apply to the code that you add in this way. To avoid misleading
36 * anyone as to the status of such modified files, you must delete
37 * this exception notice from them.
39 * If you write modifications of your own for GUILE, it is your choice
40 * whether to permit this exception to apply to your modifications.
41 * If you do not wish that, delete this exception notice.
54 #include "mbstrings.h"
57 SCM_PROC(s_multi_byte_string_p
, "multi-byte-string?", 1, 0, 0, scm_multi_byte_string_p
);
60 scm_multi_byte_string_p (obj
)
63 return (SCM_MB_STRINGP (obj
)
71 scm_regular_string_p (obj
)
74 return (SCM_REGULAR_STRINGP (obj
)
79 SCM_PROC(s_list_to_multi_byte_string
, "list->multi-byte-string", 1, 0, 0, scm_multi_byte_string
);
80 SCM_PROC(s_multi_byte_string
, "multi-byte-string", 0, 0, 1, scm_multi_byte_string
);
83 scm_multi_byte_string (chrs
)
91 i
= scm_ilength (chrs
);
92 SCM_ASSERT (i
>= 0, chrs
, SCM_ARG1
, s_multi_byte_string
);
94 res
= scm_makstr (i
, 0);
95 SCM_SETLENGTH (res
, SCM_LENGTH (res
), scm_tc7_mb_string
);
96 data
= SCM_CHARS (res
);
99 while (i
&& SCM_NNULLP (chrs
))
105 SCM_ASSERT (SCM_ICHRP (ch
), chrs
, SCM_ARG1
, s_multi_byte_string
);
106 used
= xwctomb (data
+ byte_len
, SCM_ICHR (ch
));
107 SCM_ASSERT (used
>= 0, chrs
, SCM_ARG1
, s_multi_byte_string
);
108 byte_len
+= (used
? used
: 1);
109 chrs
= SCM_CDR (chrs
);
112 res
= scm_vector_set_length_x (res
, SCM_MAKINUM (byte_len
));
118 scm_mb_ilength (data
, size
)
119 unsigned char * data
;
132 inc
= xmblen (data
+ pos
, size
- pos
);
146 SCM_PROC(s_multi_byte_string_length
, "multi-byte-string-length", 1, 0, 0, scm_multi_byte_string_length
);
149 scm_multi_byte_string_length (str
)
154 unsigned char * data
;
156 SCM_ASSERT (SCM_NIMP (str
) && SCM_ROSTRINGP (str
), str
, SCM_ARG1
, s_multi_byte_string_length
);
158 data
= SCM_ROCHARS (str
);
159 size
= SCM_ROLENGTH (str
);
160 len
= scm_mb_ilength (data
, size
);
161 SCM_ASSERT (len
>= 0, str
, SCM_ARG1
, s_multi_byte_string_length
);
162 return SCM_MAKINUM (len
);
166 SCM_PROC(s_symbol_multi_byte_p
, "symbol-multi-byte?", 1, 0, 0, scm_symbol_multi_byte_p
);
169 scm_symbol_multi_byte_p (symbol
)
172 return SCM_SYMBOL_MULTI_BYTE_STRINGP(symbol
);
175 SCM_PROC(s_set_symbol_multi_byte_x
, "set-symbol-multi-byte!", 2, 0, 0, scm_set_symbol_multi_byte_x
);
178 scm_set_symbol_multi_byte_x (symbol
, val
)
182 if (SCM_TYP7 (symbol
) == scm_tc7_msymbol
)
184 SCM_SYMBOL_MULTI_BYTE_STRINGP(symbol
) = (SCM_FALSEP (val
)
188 return SCM_UNSPECIFIED
;
192 SCM_PROC(s_regular_port_p
, "regular-port?", 1, 0, 0, scm_regular_port_p
);
195 scm_regular_port_p (p
)
198 return (SCM_PORT_REPRESENTATION(p
) == scm_regular_port
203 SCM_PROC(s_regular_port_x
, "regular-port!", 1, 0, 0, scm_regular_port_x
);
206 scm_regular_port_x (p
)
209 SCM_PORT_REPRESENTATION(p
) = scm_regular_port
;
210 return SCM_UNSPECIFIED
;
213 SCM_PROC(s_multi_byte_port_p
, "multi-byte-port?", 1, 0, 0, scm_multi_byte_port_p
);
216 scm_multi_byte_port_p (p
)
219 return (SCM_PORT_REPRESENTATION(p
) == scm_mb_port
224 SCM_PROC(s_multi_byte_port_x
, "multi-byte-port!", 1, 0, 0, scm_multi_byte_port_x
);
227 scm_multi_byte_port_x (p
)
230 SCM_PORT_REPRESENTATION(p
) = scm_mb_port
;
231 return SCM_UNSPECIFIED
;
235 SCM_PROC(s_wide_character_port_p
, "wide-character-port?", 1, 0, 0, scm_wide_character_port_p
);
238 scm_wide_character_port_p (p
)
241 return (SCM_PORT_REPRESENTATION(p
) == scm_wchar_port
246 SCM_PROC(s_wide_character_port_x
, "wide-character-port!", 1, 0, 0, scm_wide_character_port_x
);
249 scm_wide_character_port_x (p
)
252 SCM_PORT_REPRESENTATION(p
) = scm_wchar_port
;
253 return SCM_UNSPECIFIED
;
262 scm_put_wchar (c
, port
, writing
)
268 scm_gen_puts (scm_regular_string
, "#\\", port
);
269 switch (SCM_PORT_REPRESENTATION (port
))
271 case scm_regular_port
:
276 scm_gen_putc ((unsigned char)c
, port
);
277 else if ((c
<= ' ') && scm_charnames
[c
])
278 scm_gen_puts (scm_regular_string
, scm_charnames
[c
], port
);
280 scm_intprint (c
, 8, port
);
282 scm_gen_putc ((int) c
, port
);
288 scm_gen_putc ('\\', port
);
289 scm_intprint (c
, 8, port
);
299 if (XMB_CUR_MAX
> sizeof (buf
))
302 len
= xwctomb (buf
, c
);
308 scm_gen_putc (0, port
);
310 scm_gen_putc (c
, port
);
316 scm_gen_putc (c
, port
);
328 scm_print_mb_string (exp
, port
, writing
)
339 scm_gen_putc ('\"', port
);
341 len
= SCM_ROLENGTH (exp
);
342 data
= SCM_ROCHARS (exp
);
349 inc
= xmbtowc (&c
, data
+ i
, len
- i
);
362 scm_gen_putc ('\\', port
);
364 scm_gen_putc (c
, port
);
367 scm_gen_putc ('\"', port
);
370 scm_gen_write (scm_mb_string
, SCM_ROCHARS (exp
), SCM_ROLENGTH (exp
), port
);
376 scm_print_mb_symbol (exp
, port
)
386 int mw_pos
= 0; /* initialized to placate compiler */
387 int inc
= 0; /* same */
390 len
= SCM_LENGTH (exp
);
391 str
= SCM_CHARS (exp
);
397 for (end
= pos
; end
< len
; end
+= inc
)
399 inc
= xmbtowc (&c
, str
+ end
, len
- end
);
413 #ifdef BRACKETS_AS_PARENS
421 case SCM_WHITE_SPACES
:
422 case SCM_LINE_INCREMENTORS
:
431 scm_gen_write (scm_regular_string
, "#{", 2, port
);
442 qinc
= xmbtowc (&c
, str
+ q
, end
- q
);
448 scm_gen_putc (c
, port
);
456 scm_gen_write (scm_regular_string
, buf
, 2, port
);
485 qinc
= xmbtowc (&c
, str
+ q
, end
- q
);
488 scm_gen_putc (c
, port
);
493 scm_gen_write (scm_regular_string
, "}#", 2, port
);
501 scm_init_mbstrings ()
503 #include "mbstrings.x"