diff options
-rw-r--r-- | buf.c | 19 | ||||
-rw-r--r-- | buf.h | 1 | ||||
-rw-r--r-- | txr.1 | 29 |
3 files changed, 49 insertions, 0 deletions
@@ -362,6 +362,24 @@ val replace_buf(val buf, val items, val from, val to) 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); + cnum p = buf_check_index(b, pos, self); + val req_len = plus(num(p), num(size)); + if (gt(req_len, b->len)) + buf_do_set_len(buf, b, req_len, nil, self); + memmove(b->data + p, ptr, size); +} + +val buf_put_buf(val dbuf, val sbuf, val pos) +{ + val self = lit("buf-put-buf"); + struct buf *sb = buf_handle(sbuf, self); + buf_move_bytes(dbuf, pos, sb->data, c_num(sb->len), self); + return sbuf; +} + static void buf_put_bytes(val buf, val pos, mem_t *ptr, cnum size, val self) { struct buf *b = buf_handle(buf, self); @@ -1077,6 +1095,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-put-buf"), user_package), func_n3(buf_put_buf)); #if HAVE_I8 reg_fun(intern(lit("buf-put-i8"), user_package), func_n3(buf_put_i8)); @@ -39,6 +39,7 @@ mem_t *buf_get(val buf, val self); void buf_fill(val buf, mem_t *src, val self); val sub_buf(val seq, val from, val to); val replace_buf(val buf, val items, val from, val to); +val buf_put_buf(val dbuf, val sbuf, val pos); #if HAVE_I8 val buf_put_i8(val buf, val pos, val num); @@ -23829,6 +23829,35 @@ The of the arguments, semantics and return value given for apply to .codn replace-buf . +.coNP Function @ buf-put-buf +.synb +.mets (buf-put-buf < dst-buf < pos << src-buf ) +.syne +.desc +The +.code buf-put-buf +function stores a copy of buffer +.meta src-buf +into +.meta dst-buf +at the offset indicated by +.metn pos . + +The source and destination memory regions may overlap. + +The return value is +.metn src-buf . + +Note: the effect of a +.code buf-put-buf +operation may also be performed by a suitable call to +.codn replace-buf ; +however, +.code buf-put-buf +is less general: it doesn't insert or delete by replacing +destination ranges with data of differing length, +and requires a source operand of buffer type. + .coNP Function @ buf-put-i8 .synb .mets (buf-put-i8 < buf < pos << val ) |