aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/typval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-02-28 14:12:58 +0800
committerGitHub <noreply@github.com>2023-02-28 14:12:58 +0800
commitbefb47f2e11a3f1035e6825b6f9fa7574c37ed0e (patch)
treed78b2cc1f02d99828e092e0f27d5dbfce9136668 /src/nvim/eval/typval.c
parent9a271f6afd7a9b1c17d694b57ee1f489496000aa (diff)
parent1f1227f12b69616484cc0f8b49d555df4a94678b (diff)
downloadrneovim-befb47f2e11a3f1035e6825b6f9fa7574c37ed0e.tar.gz
rneovim-befb47f2e11a3f1035e6825b6f9fa7574c37ed0e.tar.bz2
rneovim-befb47f2e11a3f1035e6825b6f9fa7574c37ed0e.zip
Merge pull request #22446 from zeertzjq/vim-8.2.2757
vim-patch:8.2.{2757,2765,2767}
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r--src/nvim/eval/typval.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 0a30cdb62e..7e94e03823 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -2710,6 +2710,46 @@ bool tv_blob_equal(const blob_T *const b1, const blob_T *const b2)
return true;
}
+/// Check if "n1" is a valid index for a blob with length "bloblen".
+int tv_blob_check_index(int bloblen, varnumber_T n1, bool quiet)
+{
+ if (n1 < 0 || n1 > bloblen) {
+ if (!quiet) {
+ semsg(_(e_blobidx), n1);
+ }
+ return FAIL;
+ }
+ return OK;
+}
+
+/// Check if "n1"-"n2" is a valid range for a blob with length "bloblen".
+int tv_blob_check_range(int bloblen, varnumber_T n1, varnumber_T n2, bool quiet)
+{
+ if (n2 < 0 || n2 >= bloblen || n2 < n1) {
+ if (!quiet) {
+ semsg(_(e_blobidx), n2);
+ }
+ return FAIL;
+ }
+ return OK;
+}
+
+/// Set bytes "n1" to "n2" (inclusive) in "dest" to the value of "src".
+/// Caller must make sure "src" is a blob.
+/// Returns FAIL if the number of bytes does not match.
+int tv_blob_set_range(blob_T *dest, long n1, long n2, typval_T *src)
+{
+ if (n2 - n1 + 1 != tv_blob_len(src->vval.v_blob)) {
+ emsg(_("E972: Blob value does not have the right number of bytes"));
+ return FAIL;
+ }
+
+ for (int il = (int)n1, ir = 0; il <= (int)n2; il++) {
+ tv_blob_set(dest, il, tv_blob_get(src->vval.v_blob, ir++));
+ }
+ return OK;
+}
+
/// "remove({blob})" function
void tv_blob_remove(typval_T *argvars, typval_T *rettv, const char *arg_errmsg)
{