diff options
-rw-r--r-- | buf.c | 18 | ||||
-rw-r--r-- | buf.h | 1 | ||||
-rw-r--r-- | txr.1 | 20 |
3 files changed, 39 insertions, 0 deletions
@@ -362,6 +362,23 @@ val replace_buf(val buf, val items, val from, val to) return buf; } +val buf_list(val list) +{ + val self = lit("buf-list");; + val len = length(list); + val buf = make_buf(zero, zero, len); + seq_iter_t iter; + val elem; + cnum i; + + for (i = 0, seq_iter_init(self, &iter, list); seq_get(&iter, &elem); i++) + buf->b.data[i] = c_uchar(elem, self); + + buf->b.len = len; + + return buf; +} + static void buf_move_bytes(val buf, val pos, mem_t *ptr, cnum size, val self) { struct buf *b = buf_handle(buf, self); @@ -1197,6 +1214,7 @@ void buf_init(void) reg_fun(intern(lit("copy-buf"), user_package), func_n1(copy_buf)); reg_fun(intern(lit("sub-buf"), user_package), func_n3(sub_buf)); reg_fun(intern(lit("replace-buf"), user_package), func_n4(replace_buf)); + reg_fun(intern(lit("buf-list"), user_package), func_n1(buf_list)); reg_fun(intern(lit("buf-put-buf"), user_package), func_n3(buf_put_buf)); #if HAVE_I8 @@ -38,6 +38,7 @@ val buf_alloc_size(val buf); mem_t *buf_get(val buf, val self); val sub_buf(val seq, val from, val to); val replace_buf(val buf, val items, val from, val to); +val buf_list(val list); val buf_put_buf(val dbuf, val sbuf, val pos); #if HAVE_I8 @@ -24200,6 +24200,26 @@ The of the arguments, semantics and return value given for apply to .codn replace-buf . +.coNP Function @ buf-list +.synb +.mets (buf-list << list ) +.syne +.desc +The +.code buf-list +function creates and returns a new buffer, whose contents are derived from the +elements of +.metn list , +which may be any kind of sequence. + +The elements of +.meta list +must be integers whose values lie in the range 0 to 255, or else +characters whose code point values lie in that range. +These values are placed into the newly created buffer, which +therefore has the same length as +.metn list . + .coNP Function @ buf-put-buf .synb .mets (buf-put-buf < dst-buf < pos << src-buf ) |