Mercurial > vim
comparison src/blob.c @ 25806:8d55e978f95b v8.2.3438
patch 8.2.3438: cannot manipulate blobs
Commit: https://github.com/vim/vim/commit/5dfe467432638fac2e0156a2f9cd0d9eb569fb39
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Tue Sep 14 17:54:30 2021 +0200
patch 8.2.3438: cannot manipulate blobs
Problem: Cannot manipulate blobs.
Solution: Add blob2list() and list2blob(). (Yegappan Lakshmanan,
closes #8868)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 14 Sep 2021 18:00:08 +0200 |
parents | 7144d2ffc86b |
children | 43d196ca5e7a |
comparison
equal
deleted
inserted
replaced
25805:6f144509b673 | 25806:8d55e978f95b |
---|---|
481 b->bv_ga.ga_len -= end - idx + 1; | 481 b->bv_ga.ga_len -= end - idx + 1; |
482 } | 482 } |
483 } | 483 } |
484 } | 484 } |
485 | 485 |
486 /* | |
487 * blob2list() function | |
488 */ | |
489 void | |
490 f_blob2list(typval_T *argvars, typval_T *rettv) | |
491 { | |
492 blob_T *blob; | |
493 list_T *l; | |
494 int i; | |
495 | |
496 if (rettv_list_alloc(rettv) == FAIL) | |
497 return; | |
498 | |
499 if (check_for_blob_arg(argvars, 0) == FAIL) | |
500 return; | |
501 | |
502 blob = argvars->vval.v_blob; | |
503 l = rettv->vval.v_list; | |
504 for (i = 0; i < blob_len(blob); i++) | |
505 list_append_number(l, blob_get(blob, i)); | |
506 } | |
507 | |
508 /* | |
509 * list2blob() function | |
510 */ | |
511 void | |
512 f_list2blob(typval_T *argvars, typval_T *rettv) | |
513 { | |
514 list_T *l; | |
515 listitem_T *li; | |
516 blob_T *blob; | |
517 | |
518 if (rettv_blob_alloc(rettv) == FAIL) | |
519 return; | |
520 blob = rettv->vval.v_blob; | |
521 | |
522 if (check_for_list_arg(argvars, 0) == FAIL) | |
523 return; | |
524 | |
525 l = argvars->vval.v_list; | |
526 if (l == NULL) | |
527 return; | |
528 | |
529 FOR_ALL_LIST_ITEMS(l, li) | |
530 { | |
531 int error; | |
532 varnumber_T n; | |
533 | |
534 error = FALSE; | |
535 n = tv_get_number_chk(&li->li_tv, &error); | |
536 if (error == TRUE || n < 0 || n > 255) | |
537 { | |
538 if (!error) | |
539 semsg(_(e_invalid_value_for_blob_nr), n); | |
540 ga_clear(&blob->bv_ga); | |
541 return; | |
542 } | |
543 ga_append(&blob->bv_ga, n); | |
544 } | |
545 } | |
546 | |
486 #endif // defined(FEAT_EVAL) | 547 #endif // defined(FEAT_EVAL) |