diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-31 13:08:38 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-31 13:08:38 +0100 |
commit | 3445320839a38b3b0c253513b125da8298ec27d6 (patch) | |
tree | 36de5f4e0a019c497710a3cfd6908a5fed0feed4 /src/typval.c | |
parent | f2b26bcf8f498fed72759af4aa768fb2aab3118c (diff) | |
download | vim-git-3445320839a38b3b0c253513b125da8298ec27d6.tar.gz |
patch 8.2.2435: setline() gives an error for some typesv8.2.2435
Problem: setline() gives an error for some types.
Solution: Allow any type, convert each item to a string.
Diffstat (limited to 'src/typval.c')
-rw-r--r-- | src/typval.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/typval.c b/src/typval.c index b3325b663..65e07b3f7 100644 --- a/src/typval.c +++ b/src/typval.c @@ -927,8 +927,13 @@ typval_compare( return OK; } +/* + * Convert any type to a string, never give an error. + * When "quotes" is TRUE add quotes to a string. + * Returns an allocated string. + */ char_u * -typval_tostring(typval_T *arg) +typval_tostring(typval_T *arg, int quotes) { char_u *tofree; char_u numbuf[NUMBUFLEN]; @@ -936,10 +941,18 @@ typval_tostring(typval_T *arg) if (arg == NULL) return vim_strsave((char_u *)"(does not exist)"); - ret = tv2string(arg, &tofree, numbuf, 0); - // Make a copy if we have a value but it's not in allocated memory. - if (ret != NULL && tofree == NULL) - ret = vim_strsave(ret); + if (!quotes && arg->v_type == VAR_STRING) + { + ret = vim_strsave(arg->vval.v_string == NULL ? (char_u *)"" + : arg->vval.v_string); + } + else + { + ret = tv2string(arg, &tofree, numbuf, 0); + // Make a copy if we have a value but it's not in allocated memory. + if (ret != NULL && tofree == NULL) + ret = vim_strsave(ret); + } return ret; } |