Mercurial > vim
comparison src/typval.c @ 23788:d12ef361d9de v8.2.2435
patch 8.2.2435: setline() gives an error for some types
Commit: https://github.com/vim/vim/commit/3445320839a38b3b0c253513b125da8298ec27d6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 31 13:08:38 2021 +0100
patch 8.2.2435: setline() gives an error for some types
Problem: setline() gives an error for some types.
Solution: Allow any type, convert each item to a string.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 31 Jan 2021 13:15:04 +0100 |
parents | 0512923e54e1 |
children | 5db7d275543c |
comparison
equal
deleted
inserted
replaced
23787:7b30bc27e54b | 23788:d12ef361d9de |
---|---|
925 } | 925 } |
926 | 926 |
927 return OK; | 927 return OK; |
928 } | 928 } |
929 | 929 |
930 /* | |
931 * Convert any type to a string, never give an error. | |
932 * When "quotes" is TRUE add quotes to a string. | |
933 * Returns an allocated string. | |
934 */ | |
930 char_u * | 935 char_u * |
931 typval_tostring(typval_T *arg) | 936 typval_tostring(typval_T *arg, int quotes) |
932 { | 937 { |
933 char_u *tofree; | 938 char_u *tofree; |
934 char_u numbuf[NUMBUFLEN]; | 939 char_u numbuf[NUMBUFLEN]; |
935 char_u *ret = NULL; | 940 char_u *ret = NULL; |
936 | 941 |
937 if (arg == NULL) | 942 if (arg == NULL) |
938 return vim_strsave((char_u *)"(does not exist)"); | 943 return vim_strsave((char_u *)"(does not exist)"); |
939 ret = tv2string(arg, &tofree, numbuf, 0); | 944 if (!quotes && arg->v_type == VAR_STRING) |
940 // Make a copy if we have a value but it's not in allocated memory. | 945 { |
941 if (ret != NULL && tofree == NULL) | 946 ret = vim_strsave(arg->vval.v_string == NULL ? (char_u *)"" |
942 ret = vim_strsave(ret); | 947 : arg->vval.v_string); |
948 } | |
949 else | |
950 { | |
951 ret = tv2string(arg, &tofree, numbuf, 0); | |
952 // Make a copy if we have a value but it's not in allocated memory. | |
953 if (ret != NULL && tofree == NULL) | |
954 ret = vim_strsave(ret); | |
955 } | |
943 return ret; | 956 return ret; |
944 } | 957 } |
945 | 958 |
946 /* | 959 /* |
947 * Return TRUE if typeval "tv" is locked: Either that value is locked itself | 960 * Return TRUE if typeval "tv" is locked: Either that value is locked itself |