diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-05-27 20:20:14 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-05-27 20:20:14 -0700 |
commit | 6bccfe8a55a12ef162fd945633c130f8b3362529 (patch) | |
tree | 2c0c75c5022003f0de0f8d6f20bfa70bc76d9266 /buf.c | |
parent | 55cf3cae3665cab1264fe00ec31859d8dba13027 (diff) | |
download | txr-6bccfe8a55a12ef162fd945633c130f8b3362529.tar.gz txr-6bccfe8a55a12ef162fd945633c130f8b3362529.tar.bz2 txr-6bccfe8a55a12ef162fd945633c130f8b3362529.zip |
quasiliterals: buffers in hex, separation for strings and buffers.
In this commit, output variables in the TXR Pattern language and
in TXR Lisp quasiliterals now support separator strings for values
that are strings and buffers. Values which are buffers appear
Diffstat (limited to 'buf.c')
-rw-r--r-- | buf.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -887,6 +887,30 @@ val buf_pprint(val buf, val stream_in) return t; } +val buf_str_sep(val buf, val sep, val self) +{ + struct buf *b = buf_handle(buf, self); + ucnum len = c_unum(b->len, self); + val ret = null_string; + + if (len > 0) { + val stream = make_string_output_stream(); + ucnum i = 0; + + goto first; + + while (i < len) { + put_string(sep, stream); + first: + format(stream, lit("~,02x"), num_fast(b->data[i++]), nao); + } + + ret = get_string_from_stream(stream); + } + + return ret; +} + void buf_hex(val buf, char *hex, size_t sz, int caps) { val self = lit("buf-hex"); |