summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-12-28 06:44:58 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-12-28 06:44:58 -0800
commit92dd3486727d748253b8b1a0dd4416c07e61addb (patch)
tree2d46d0f93e777d457990c5296d659f68280378eb /stream.c
parentd2488974756c21c064ddd293fbb72d5a85b91e12 (diff)
downloadtxr-92dd3486727d748253b8b1a0dd4416c07e61addb.tar.gz
txr-92dd3486727d748253b8b1a0dd4416c07e61addb.tar.bz2
txr-92dd3486727d748253b8b1a0dd4416c07e61addb.zip
Overhaul printing of lazy strings.
The #<lazy-string ...> print syntax is gone. Lazy strings are now printed by traversing their structure, without forcing them to the flat representation. * lib.c (lazy_str_put): New function. (out_str_char, out_str_pretty, out_lazy_str): New static functions. (obj_print_impl): Use out_str_pretty for standard-printing regular strings. Use lazy_put_str for pretty-printing lazy strings, and out_lazy_str for standard-printing them. * lib.h (lazy_str_put): Declared. * stream.c (put_string): Check for a lazy string and route to lazy_str_put, so the string doesn't get forced (though of course the underlying list does, if it is lazy).
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c57
1 files changed, 31 insertions, 26 deletions
diff --git a/stream.c b/stream.c
index a1a41036..aadda39e 100644
--- a/stream.c
+++ b/stream.c
@@ -2638,36 +2638,41 @@ static val put_indent(val stream, struct strm_ops *ops, cnum chars)
val put_string(val string, val stream_in)
{
- val stream = default_arg(stream_in, std_output);
- struct strm_ops *ops = coerce(struct strm_ops *, cobj_ops(stream, stream_s));
- struct strm_base *s = coerce(struct strm_base *, stream->co.handle);
- cnum col = s->column;
- const wchar_t *str = c_str(string), *p = str;
+ if (lazy_stringp(string)) {
+ return lazy_str_put(string, stream_in);
+ } else {
+ val stream = default_arg(stream_in, std_output);
+ struct strm_ops *ops = coerce(struct strm_ops *, cobj_ops(stream, stream_s));
+ struct strm_base *s = coerce(struct strm_base *, stream->co.handle);
+ cnum col = s->column;
- if (s->indent_mode != indent_off) {
- while (*str)
- put_char(chr(*str++), stream);
- return t;
- }
+ const wchar_t *str = c_str(string), *p = str;
- for (; *p; p++) {
- switch (*p) {
- case '\n':
- col = 0;
- break;
- case '\t':
- col = (col + 1) | 7;
- break;
- default:
- if (!iswcntrl(*p))
- col += 1 + wide_display_char_p(*p);
- break;
+ if (s->indent_mode != indent_off) {
+ while (*str)
+ put_char(chr(*str++), stream);
+ return t;
}
- }
- ops->put_string(stream, string);
- s->column = col;
- return t;
+ for (; *p; p++) {
+ switch (*p) {
+ case '\n':
+ col = 0;
+ break;
+ case '\t':
+ col = (col + 1) | 7;
+ break;
+ default:
+ if (!iswcntrl(*p))
+ col += 1 + wide_display_char_p(*p);
+ break;
+ }
+ }
+
+ ops->put_string(stream, string);
+ s->column = col;
+ return t;
+ }
}
val put_char(val ch, val stream_in)