chiark / gitweb /
hbytes range
[chiark-tcl.git] / base / hook.c
index e53af08ba8e8fd8dd01cafa1c263a71df1698899..0efc5f1607aabb7539727d681662ce29c46cc089 100644 (file)
@@ -177,6 +177,41 @@ int do_hbytes_zeroes(ClientData cd, Tcl_Interp *ip,
   return TCL_OK;
 }
 
+int do_hbytes_compare(ClientData cd, Tcl_Interp *ip,
+                     HBytes_Value a, HBytes_Value b, int *result) {
+  int al, bl, minl, r;
+
+  al= hbytes_len(&a);
+  bl= hbytes_len(&b);
+  minl= al<bl ? al : bl;
+
+  r= memcmp(hbytes_data(&a), hbytes_data(&b), minl);
+  
+  if (r<0) *result= -2;
+  else if (r>0) *result= +2;
+  else {
+    if (al<bl) *result= -1;
+    else if (al>bl) *result= +1;
+    else *result= 0;
+  }
+  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) {