diff options
-rw-r--r-- | buf.c | 9 | ||||
-rw-r--r-- | buf.h | 1 | ||||
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | txr.1 | 22 |
4 files changed, 34 insertions, 0 deletions
@@ -137,6 +137,14 @@ static struct buf *buf_handle(val buf, val ctx) ctx, buf, nao); } +val copy_buf(val buf) +{ + struct buf *b = buf_handle(buf, lit("copy-buf")); + return if3(b->size, + make_duplicate_buf(b->len, b->data), + make_borrowed_buf(b->len, b->data)); +} + static void buf_grow(struct buf *b, val init_val, val self) { cnum len = c_num(b->len); @@ -935,6 +943,7 @@ void buf_init(void) reg_fun(intern(lit("buf-trim"), user_package), func_n1(buf_trim)); reg_fun(intern(lit("buf-set-length"), user_package), func_n3o(buf_set_length, 2)); reg_fun(intern(lit("length-buf"), user_package), func_n1(length_buf)); + reg_fun(intern(lit("copy-buf"), user_package), func_n1(copy_buf)); #if HAVE_I8 reg_fun(intern(lit("buf-put-i8"), user_package), func_n3(buf_put_i8)); @@ -30,6 +30,7 @@ val bufp(val object); val make_borrowed_buf(val len, mem_t *data); val init_borrowed_buf(obj_t *buf, val len, mem_t *data); val make_duplicate_buf(val len, mem_t *data); +val copy_buf(val buf); val buf_trim(val buf); val buf_set_length(val obj, val len, val init_val); val length_buf(val buf); @@ -9939,6 +9939,8 @@ val copy(val seq) return copy_str(seq); case VEC: return copy_vec(seq); + case BUF: + return copy_buf(seq); case COBJ: if (seq->co.cls == hash_s) return copy_hash(seq); @@ -26177,6 +26177,12 @@ is a structure, it returns .cble If .meta object +is a buffer, it returns +.cblk +.meti (copy-buf << object ). +.cble +If +.meta object is a .codn carray , it returns @@ -56985,6 +56991,22 @@ If is specified, its value must be in the range 0 to 255. It defaults to zero. +.coNP Function @ copy-buf +.synb +.mets (copy-buf << buf ) +.syne +.desc +The +.code copy-buf +function returns a duplicate of +.metn buf : +an object distinct from +.meta buf +which has the same length and contents, and compares +.code equal +to +.metn buf . + .coNP Function @ buf-put-i8 .synb .mets (buf-put-i8 < buf < pos << val ) |