1
0
forked from aniani/vim

patch 8.2.2133: Vim9: checking for a non-empty string is too strict

Problem:    Vim9: checking for a non-empty string is too strict.
Solution:   Check for any string. (closes #7447)
This commit is contained in:
Bram Moolenaar
2020-12-12 18:58:40 +01:00
parent 3ae50c775c
commit 2a9d5d386b
6 changed files with 59 additions and 24 deletions

View File

@@ -341,14 +341,12 @@ tv_get_float(typval_T *varp)
#endif
/*
* Give an error and return FAIL unless "tv" is a non-empty string.
* Give an error and return FAIL unless "tv" is a string.
*/
int
check_for_string(typval_T *tv)
{
if (tv->v_type != VAR_STRING
|| tv->vval.v_string == NULL
|| *tv->vval.v_string == NUL)
if (tv->v_type != VAR_STRING)
{
emsg(_(e_stringreq));
return FAIL;
@@ -356,6 +354,22 @@ check_for_string(typval_T *tv)
return OK;
}
/*
* Give an error and return FAIL unless "tv" is a non-empty string.
*/
int
check_for_nonempty_string(typval_T *tv)
{
if (check_for_string(tv) == FAIL)
return FAIL;
if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL)
{
emsg(_(e_non_empty_string_required));
return FAIL;
}
return OK;
}
/*
* Get the string value of a variable.
* If it is a Number variable, the number is converted into a string.