mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #25208 from zeertzjq/vim-8.2.2356
This commit is contained in:
@@ -947,38 +947,42 @@ int skip_expr(char **pp, evalarg_T *const evalarg)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert "tv" to a string.
|
||||||
|
///
|
||||||
|
/// @param convert when true convert a List into a sequence of lines.
|
||||||
|
///
|
||||||
|
/// @return an allocated string.
|
||||||
|
static char *typval2string(typval_T *tv, bool convert)
|
||||||
|
{
|
||||||
|
if (convert && tv->v_type == VAR_LIST) {
|
||||||
|
garray_T ga;
|
||||||
|
ga_init(&ga, (int)sizeof(char), 80);
|
||||||
|
if (tv->vval.v_list != NULL) {
|
||||||
|
tv_list_join(&ga, tv->vval.v_list, "\n");
|
||||||
|
if (tv_list_len(tv->vval.v_list) > 0) {
|
||||||
|
ga_append(&ga, NL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ga_append(&ga, NUL);
|
||||||
|
return (char *)ga.ga_data;
|
||||||
|
}
|
||||||
|
return xstrdup(tv_get_string(tv));
|
||||||
|
}
|
||||||
|
|
||||||
/// Top level evaluation function, returning a string.
|
/// Top level evaluation function, returning a string.
|
||||||
///
|
///
|
||||||
/// @param convert when true convert a List into a sequence of lines and convert
|
/// @param convert when true convert a List into a sequence of lines.
|
||||||
/// a Float to a String.
|
|
||||||
///
|
///
|
||||||
/// @return pointer to allocated memory, or NULL for failure.
|
/// @return pointer to allocated memory, or NULL for failure.
|
||||||
char *eval_to_string(char *arg, bool convert)
|
char *eval_to_string(char *arg, bool convert)
|
||||||
{
|
{
|
||||||
typval_T tv;
|
typval_T tv;
|
||||||
char *retval;
|
char *retval;
|
||||||
garray_T ga;
|
|
||||||
|
|
||||||
if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) {
|
if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) {
|
||||||
retval = NULL;
|
retval = NULL;
|
||||||
} else {
|
} else {
|
||||||
if (convert && tv.v_type == VAR_LIST) {
|
retval = typval2string(&tv, convert);
|
||||||
ga_init(&ga, (int)sizeof(char), 80);
|
|
||||||
if (tv.vval.v_list != NULL) {
|
|
||||||
tv_list_join(&ga, tv.vval.v_list, "\n");
|
|
||||||
if (tv_list_len(tv.vval.v_list) > 0) {
|
|
||||||
ga_append(&ga, NL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ga_append(&ga, NUL);
|
|
||||||
retval = (char *)ga.ga_data;
|
|
||||||
} else if (convert && tv.v_type == VAR_FLOAT) {
|
|
||||||
char numbuf[NUMBUFLEN];
|
|
||||||
vim_snprintf(numbuf, NUMBUFLEN, "%g", tv.vval.v_float);
|
|
||||||
retval = xstrdup(numbuf);
|
|
||||||
} else {
|
|
||||||
retval = xstrdup(tv_get_string(&tv));
|
|
||||||
}
|
|
||||||
tv_clear(&tv);
|
tv_clear(&tv);
|
||||||
}
|
}
|
||||||
clear_evalarg(&EVALARG_EVALUATE, NULL);
|
clear_evalarg(&EVALARG_EVALUATE, NULL);
|
||||||
|
Reference in New Issue
Block a user