patch 9.1.1668: items() does not work for Blobs

Problem:  items() does not work for Blobs
Solution: Extend items() to support Blob
          (Yegappan Lakshmanan).

closes: #18080

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2025-08-23 06:18:34 -04:00
committed by Christian Brabandt
parent 6b56711804
commit da34f84847
13 changed files with 94 additions and 26 deletions

View File

@ -289,6 +289,38 @@ blob2string(blob_T *blob, char_u **tofree, char_u *numbuf)
return *tofree;
}
/*
* "items(blob)" function
* Converts a Blob into a List of [index, byte] pairs.
* Caller must have already checked that argvars[0] is a Blob.
* A null blob behaves like an empty blob.
*/
void
blob2items(typval_T *argvars, typval_T *rettv)
{
blob_T *blob = argvars[0].vval.v_blob;
if (rettv_list_alloc(rettv) == FAIL)
return;
for (int i = 0; i < blob_len(blob); i++)
{
list_T *l2 = list_alloc();
if (l2 == NULL)
return;
if (list_append_list(rettv->vval.v_list, l2) == FAIL)
{
vim_free(l2);
return;
}
if (list_append_number(l2, i) == FAIL
|| list_append_number(l2, blob_get(blob, i)) == FAIL)
return;
}
}
/*
* Convert a string variable, in the format of blob2string(), to a blob.
* Return NULL when conversion failed.