summaryrefslogtreecommitdiff
path: root/src/typval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-12 18:58:40 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-12 18:58:40 +0100
commit2a9d5d386bea8455b37c1accebc45683ec51d6fb (patch)
treee5e67a60b0741486ce6e53fe76ca3669a9f7e752 /src/typval.c
parent3ae50c775c00b098cdfc9e90b17c4cc07f00e08d (diff)
downloadvim-git-2a9d5d386bea8455b37c1accebc45683ec51d6fb.tar.gz
patch 8.2.2133: Vim9: checking for a non-empty string is too strictv8.2.2133
Problem: Vim9: checking for a non-empty string is too strict. Solution: Check for any string. (closes #7447)
Diffstat (limited to 'src/typval.c')
-rw-r--r--src/typval.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/typval.c b/src/typval.c
index 64112e738..affd668e9 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -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;
@@ -357,6 +355,22 @@ check_for_string(typval_T *tv)
}
/*
+ * 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.
* tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE!