From f301e8071b32552f8096286ae7c978ab9e79061c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 15 Jun 2019 21:48:49 -0700 Subject: buffers: expose sub-buf and replace-buf. * buf.c (buf_init): Intrinsics sub-buf and replace-buf registered. * txr.1: Documented. --- buf.c | 2 ++ txr.1 | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/buf.c b/buf.c index 506ac45a..910d7801 100644 --- a/buf.c +++ b/buf.c @@ -1075,6 +1075,8 @@ void buf_init(void) reg_fun(intern(lit("length-buf"), user_package), func_n1(length_buf)); reg_fun(intern(lit("buf-alloc-size"), user_package), func_n1(buf_alloc_size)); 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)); #if HAVE_I8 reg_fun(intern(lit("buf-put-i8"), user_package), func_n3(buf_put_i8)); diff --git a/txr.1 b/txr.1 index 72cbdbce..635ce352 100644 --- a/txr.1 +++ b/txr.1 @@ -26871,6 +26871,13 @@ is a object, then the function behaves like .codn carray-sub . +If +.meta sequence +is a +.code buf +object, then the function behaves like +.codn buf-sub . + If .meta sequence is a structure, it must support the @@ -27049,6 +27056,15 @@ object, then behaves like .codn carray-replace . +If +.meta sequence +is a +.code buf +object, then +.code replace +behaves like +.codn buf-replace . + If .meta sequence is a structure, then the structure must support the @@ -59542,6 +59558,49 @@ which has the same length and contents, and compares to .metn buf . +.coNP Function @ sub-buf +.synb +.mets (sub-buf < buf >> [ from <> [ to ]]) +.syne +.desc +The +.code sub-buf +function has the same semantics as the +.code sub +function, except that the first argument must be a buffer. + +The extracted sub-range of a buffer is itself a buffer object. + +For a description of the arguments and semantics, refer to the +.code sub +function. + +.coNP Function @ replace-buf +.synb +.mets (replace-buf < buf < item-sequence >> [ from <> [ to ]]) +.syne +.desc +The +.code replace-buf +function has the same semantics as the +.code replace +function, except that the first argument must be a buffer. + +The elements of +.code item-sequence +are stored into +.meta buf +as if using the +.code buf-put-u8 +function and therefore must be suitable +.meta val +arguments for that function. + +The of the arguments, semantics and return value given for +.code replace +apply to +.codn replace-buf . + .coNP Function @ buf-put-i8 .synb .mets (buf-put-i8 < buf < pos << val ) -- cgit v1.2.3