patch 8.2.2756: Vim9: blob index and slice not implemented yet
Problem: Vim9: blob index and slice not implemented yet.
Solution: Implement blob index and slice.
diff --git a/src/eval.c b/src/eval.c
index 787243e..1291b36 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -4161,68 +4161,8 @@
break;
case VAR_BLOB:
- len = blob_len(rettv->vval.v_blob);
- if (is_range)
- {
- // The resulting variable is a sub-blob. If the indexes
- // are out of range the result is empty.
- if (n1 < 0)
- {
- n1 = len + n1;
- if (n1 < 0)
- n1 = 0;
- }
- if (n2 < 0)
- n2 = len + n2;
- else if (n2 >= len)
- n2 = len - (exclusive ? 0 : 1);
- if (exclusive)
- --n2;
- if (n1 >= len || n2 < 0 || n1 > n2)
- {
- clear_tv(rettv);
- rettv->v_type = VAR_BLOB;
- rettv->vval.v_blob = NULL;
- }
- else
- {
- blob_T *blob = blob_alloc();
- long i;
-
- if (blob != NULL)
- {
- if (ga_grow(&blob->bv_ga, n2 - n1 + 1) == FAIL)
- {
- blob_free(blob);
- return FAIL;
- }
- blob->bv_ga.ga_len = n2 - n1 + 1;
- for (i = n1; i <= n2; i++)
- blob_set(blob, i - n1,
- blob_get(rettv->vval.v_blob, i));
-
- clear_tv(rettv);
- rettv_blob_set(rettv, blob);
- }
- }
- }
- else
- {
- // The resulting variable is a byte value.
- // If the index is too big or negative that is an error.
- if (n1 < 0)
- n1 = len + n1;
- if (n1 < len && n1 >= 0)
- {
- int v = blob_get(rettv->vval.v_blob, n1);
-
- clear_tv(rettv);
- rettv->v_type = VAR_NUMBER;
- rettv->vval.v_number = v;
- }
- else
- semsg(_(e_blobidx), n1);
- }
+ blob_slice_or_index(rettv->vval.v_blob, is_range, n1, n2,
+ exclusive, rettv);
break;
case VAR_LIST: