chiark / gitweb /
hbytes range
authorian <ian>
Sun, 8 Sep 2002 17:16:10 +0000 (17:16 +0000)
committerian <ian>
Sun, 8 Sep 2002 17:16:10 +0000 (17:16 +0000)
base/chiark-tcl.h
base/hook.c
base/tables-examples.tct
hbytes/hbytes.h
hbytes/hook.c

index 4422d328c99e3914243f76a7174b376f6b90e809..f542fe035364148ad2b51a9ccc9dd4d5cdf7995e 100644 (file)
@@ -13,6 +13,8 @@
  *  hbytes chopto VAR NEWVARLENGTH               => suffix (removed from VAR)
  *                                                  (too short? error)
  *
  *  hbytes chopto VAR NEWVARLENGTH               => suffix (removed from VAR)
  *                                                  (too short? error)
  *
+ *  hbytes range VALUE START SIZE                => substring (or error)
+ *
  *  hbytes compare A B
  *      =>  -2   A is lexically earlier than B and not a prefix of B  (A<B)
  *          -1   A is prefix of B but not equal                       (A<B)
  *  hbytes compare A B
  *      =>  -2   A is lexically earlier than B and not a prefix of B  (A<B)
  *          -1   A is prefix of B but not equal                       (A<B)
index 8774f7b6a3fb174a5588305052cb65dc1f8dff93..0efc5f1607aabb7539727d681662ce29c46cc089 100644 (file)
@@ -197,6 +197,21 @@ int do_hbytes_compare(ClientData cd, Tcl_Interp *ip,
   return TCL_OK;
 }
 
   return TCL_OK;
 }
 
+int do_hbytes_range(ClientData cd, Tcl_Interp *ip,
+                   HBytes_Value v, int start, int size,
+                   HBytes_Value *result) {
+  const Byte *data;
+  int l;
+
+  l= hbytes_len(&v);
+  if (start<0 || size<0 || l<start+size)
+    return staticerr(ip, "hbytes range subscripts out of range");
+
+  data= hbytes_data(&v);
+  hbytes_array(result, data+start, size);
+  return TCL_OK;
+}
+  
 int do__hbytes(ClientData cd, Tcl_Interp *ip,
               const HBytes_SubCommand *subcmd,
               int objc, Tcl_Obj *const *objv) {
 int do__hbytes(ClientData cd, Tcl_Interp *ip,
               const HBytes_SubCommand *subcmd,
               int objc, Tcl_Obj *const *objv) {
index 6bdc7ff4afc95966cbc0182826be367ce232524f..b5a104b825409384e6a206df5bde3175996ecd46 100644 (file)
@@ -47,6 +47,11 @@ Table hbytes HBytes_SubCommand
                a       hb
                b       hb
                =>      int
                a       hb
                b       hb
                =>      int
+       range
+               v       hb
+               start   int
+               size    int
+               =>      hb
        prepend
                v       hbv
                str     ...
        prepend
                v       hbv
                str     ...
index 4422d328c99e3914243f76a7174b376f6b90e809..f542fe035364148ad2b51a9ccc9dd4d5cdf7995e 100644 (file)
@@ -13,6 +13,8 @@
  *  hbytes chopto VAR NEWVARLENGTH               => suffix (removed from VAR)
  *                                                  (too short? error)
  *
  *  hbytes chopto VAR NEWVARLENGTH               => suffix (removed from VAR)
  *                                                  (too short? error)
  *
+ *  hbytes range VALUE START SIZE                => substring (or error)
+ *
  *  hbytes compare A B
  *      =>  -2   A is lexically earlier than B and not a prefix of B  (A<B)
  *          -1   A is prefix of B but not equal                       (A<B)
  *  hbytes compare A B
  *      =>  -2   A is lexically earlier than B and not a prefix of B  (A<B)
  *          -1   A is prefix of B but not equal                       (A<B)
index 8774f7b6a3fb174a5588305052cb65dc1f8dff93..0efc5f1607aabb7539727d681662ce29c46cc089 100644 (file)
@@ -197,6 +197,21 @@ int do_hbytes_compare(ClientData cd, Tcl_Interp *ip,
   return TCL_OK;
 }
 
   return TCL_OK;
 }
 
+int do_hbytes_range(ClientData cd, Tcl_Interp *ip,
+                   HBytes_Value v, int start, int size,
+                   HBytes_Value *result) {
+  const Byte *data;
+  int l;
+
+  l= hbytes_len(&v);
+  if (start<0 || size<0 || l<start+size)
+    return staticerr(ip, "hbytes range subscripts out of range");
+
+  data= hbytes_data(&v);
+  hbytes_array(result, data+start, size);
+  return TCL_OK;
+}
+  
 int do__hbytes(ClientData cd, Tcl_Interp *ip,
               const HBytes_SubCommand *subcmd,
               int objc, Tcl_Obj *const *objv) {
 int do__hbytes(ClientData cd, Tcl_Interp *ip,
               const HBytes_SubCommand *subcmd,
               int objc, Tcl_Obj *const *objv) {