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.
52 SCM_PROC(s_multi_byte_string_p
, "multi-byte-string?", 1, 0, 0, scm_multi_byte_string_p
);
55 scm_multi_byte_string_p (SCM obj
)
58 scm_multi_byte_string_p (obj
)
62 return (SCM_MB_STRINGP (obj
)
70 scm_regular_string_p (SCM obj
)
73 scm_regular_string_p (obj
)
77 return (SCM_REGULAR_STRINGP (obj
)
82 SCM_PROC(s_list_to_multi_byte_string
, "list->multi-byte-string", 1, 0, 0, scm_multi_byte_string
);
83 SCM_PROC(s_multi_byte_string
, "multi-byte-string", 0, 0, 1, scm_multi_byte_string
);
86 scm_multi_byte_string (SCM chrs
)
89 scm_multi_byte_string (chrs
)
98 i
= scm_ilength (chrs
);
99 SCM_ASSERT (i
>= 0, chrs
, SCM_ARG1
, s_multi_byte_string
);
101 res
= scm_makstr (i
, 0);
102 SCM_SETLENGTH (res
, SCM_LENGTH (res
), scm_tc7_mb_string
);
103 data
= SCM_CHARS (res
);
106 while (i
&& SCM_NNULLP (chrs
))
112 SCM_ASSERT (SCM_ICHRP (ch
), chrs
, SCM_ARG1
, s_multi_byte_string
);
113 used
= xwctomb (data
+ byte_len
, SCM_ICHR (ch
));
114 SCM_ASSERT (used
>= 0, chrs
, SCM_ARG1
, s_multi_byte_string
);
115 byte_len
+= (used
? used
: 1);
116 chrs
= SCM_CDR (chrs
);
119 res
= scm_vector_set_length_x (res
, SCM_MAKINUM (byte_len
));
125 scm_mb_ilength (unsigned char * data
, int size
)
128 scm_mb_ilength (data
, size
)
129 unsigned char * data
;
143 inc
= xmblen (data
+ pos
, size
- pos
);
157 SCM_PROC(s_multi_byte_string_length
, "multi-byte-string-length", 1, 0, 0, scm_multi_byte_string_length
);
160 scm_multi_byte_string_length (SCM str
)
163 scm_multi_byte_string_length (str
)
169 unsigned char * data
;
171 SCM_ASSERT (SCM_NIMP (str
) && SCM_ROSTRINGP (str
), str
, SCM_ARG1
, s_multi_byte_string_length
);
173 data
= SCM_ROCHARS (str
);
174 size
= SCM_ROLENGTH (str
);
175 len
= scm_mb_ilength (data
, size
);
176 SCM_ASSERT (len
>= 0, str
, SCM_ARG1
, s_multi_byte_string_length
);
177 return SCM_MAKINUM (len
);
181 SCM_PROC(s_symbol_multi_byte_p
, "symbol-multi-byte?", 1, 0, 0, scm_symbol_multi_byte_p
);
184 scm_symbol_multi_byte_p (SCM symbol
)
187 scm_symbol_multi_byte_p (symbol
)
191 return SCM_SYMBOL_MULTI_BYTE_SCM_STRINGP(symbol
);
194 SCM_PROC(s_set_symbol_multi_byte_x
, "set-symbol-multi-byte!", 2, 0, 0, scm_set_symbol_multi_byte_x
);
197 scm_set_symbol_multi_byte_x (SCM symbol
, SCM val
)
200 scm_set_symbol_multi_byte_x (symbol
, val
)
205 if (SCM_TYP7 (symbol
) == scm_tc7_msymbol
)
207 SCM_SYMBOL_MULTI_BYTE_SCM_STRINGP(symbol
) = (SCM_FALSEP (val
)
211 return SCM_UNSPECIFIED
;
215 SCM_PROC(s_regular_port_p
, "regular-port?", 1, 0, 0, scm_regular_port_p
);
218 scm_regular_port_p (SCM p
)
221 scm_regular_port_p (p
)
225 return (SCM_PORT_REPRESENTATION(p
) == scm_regular_port
230 SCM_PROC(s_regular_port_x
, "regular-port!", 1, 0, 0, scm_regular_port_x
);
233 scm_regular_port_x (SCM p
)
236 scm_regular_port_x (p
)
240 SCM_PORT_REPRESENTATION(p
) = scm_regular_port
;
241 return SCM_UNSPECIFIED
;
244 SCM_PROC(s_multi_byte_port_p
, "multi-byte-port?", 1, 0, 0, scm_multi_byte_port_p
);
247 scm_multi_byte_port_p (SCM p
)
250 scm_multi_byte_port_p (p
)
254 return (SCM_PORT_REPRESENTATION(p
) == scm_mb_port
259 SCM_PROC(s_multi_byte_port_x
, "multi-byte-port!", 1, 0, 0, scm_multi_byte_port_x
);
262 scm_multi_byte_port_x (SCM p
)
265 scm_multi_byte_port_x (p
)
269 SCM_PORT_REPRESENTATION(p
) = scm_mb_port
;
270 return SCM_UNSPECIFIED
;
274 SCM_PROC(s_wide_character_port_p
, "wide-character-port?", 1, 0, 0, scm_wide_character_port_p
);
277 scm_wide_character_port_p (SCM p
)
280 scm_wide_character_port_p (p
)
284 return (SCM_PORT_REPRESENTATION(p
) == scm_wchar_port
289 SCM_PROC(s_wide_character_port_x
, "wide-character-port!", 1, 0, 0, scm_wide_character_port_x
);
292 scm_wide_character_port_x (SCM p
)
295 scm_wide_character_port_x (p
)
299 SCM_PORT_REPRESENTATION(p
) = scm_wchar_port
;
300 return SCM_UNSPECIFIED
;
309 scm_put_wchar (int c
, SCM port
, int writing
)
312 scm_put_wchar (c
, port
, writing
)
319 scm_gen_puts (scm_regular_string
, "#\\", port
);
320 switch (SCM_PORT_REPRESENTATION (port
))
322 case scm_regular_port
:
327 scm_gen_putc ((unsigned char)c
, port
);
328 else if ((c
<= ' ') && scm_charnames
[c
])
329 scm_gen_puts (scm_regular_string
, scm_charnames
[c
], port
);
331 scm_intprint (c
, 8, port
);
333 scm_gen_putc ((int) c
, port
);
339 scm_gen_putc ('\\', port
);
340 scm_intprint (c
, 8, port
);
350 if (XMB_CUR_MAX
> sizeof (buf
))
353 len
= xwctomb (buf
, c
);
359 scm_gen_putc (0, port
);
361 scm_gen_putc (c
, port
);
367 scm_gen_putc (c
, port
);
379 scm_print_mb_string (SCM exp
, SCM port
, int writing
)
382 scm_print_mb_string (exp
, port
, writing
)
394 scm_gen_putc ('\"', port
);
396 len
= SCM_ROLENGTH (exp
);
397 data
= SCM_ROCHARS (exp
);
404 inc
= xmbtowc (&c
, data
+ i
, len
- i
);
417 scm_gen_putc ('\\', port
);
419 scm_gen_putc (c
, port
);
422 scm_gen_putc ('\"', port
);
425 scm_gen_write (scm_mb_string
, SCM_ROCHARS (exp
), SCM_ROLENGTH (exp
), port
);
431 scm_print_mb_symbol (SCM exp
, SCM port
)
434 scm_print_mb_symbol (exp
, port
)
449 len
= SCM_LENGTH (exp
);
450 str
= SCM_CHARS (exp
);
456 for (end
= pos
; end
< len
; end
+= inc
)
458 inc
= xmbtowc (&c
, str
+ end
, len
- end
);
472 #ifdef BRACKETS_AS_PARENS
480 case SCM_WHITE_SPACES
:
481 case SCM_LINE_INCREMENTORS
:
490 scm_gen_write (scm_regular_string
, "#{", 2, port
);
501 qinc
= xmbtowc (&c
, str
+ q
, end
- q
);
507 scm_gen_putc (c
, port
);
515 scm_gen_write (scm_regular_string
, buf
, 2, port
);
544 qinc
= xmbtowc (&c
, str
+ q
, end
- q
);
547 scm_gen_putc (c
, port
);
552 scm_gen_write (scm_regular_string
, "}#", 2, port
);
560 scm_init_mbstrings (void)
563 scm_init_mbstrings ()
566 #include "mbstrings.x"