summaryrefslogtreecommitdiffstats
path: root/src/getchar.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-07 18:29:17 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-07 18:29:17 +0200
commit3a7503c34c65ed15cc08deb5b54aaf2ea51525b4 (patch)
treedaa9ac7e436c54459ab4971578929dc0b30779be /src/getchar.c
parentf05d2fc539c389c3b8142d9fb06fb0443de14902 (diff)
patch 8.2.2957: using getchar() in Vim9 script is problematicv8.2.2957
Problem: Using getchar() in Vim9 script is problematic. Solution: Add getcharstr(). (closes #8343)
Diffstat (limited to 'src/getchar.c')
-rw-r--r--src/getchar.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/getchar.c b/src/getchar.c
index 185b73bdb0..3b069c4386 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -2016,10 +2016,10 @@ char_avail(void)
#if defined(FEAT_EVAL) || defined(PROTO)
/*
- * "getchar()" function
+ * "getchar()" and "getcharstr()" functions
*/
- void
-f_getchar(typval_T *argvars, typval_T *rettv)
+ static void
+getchar_common(typval_T *argvars, typval_T *rettv)
{
varnumber_T n;
int error = FALSE;
@@ -2127,6 +2127,42 @@ f_getchar(typval_T *argvars, typval_T *rettv)
}
/*
+ * "getchar()" function
+ */
+ void
+f_getchar(typval_T *argvars, typval_T *rettv)
+{
+ getchar_common(argvars, rettv);
+}
+
+/*
+ * "getcharstr()" function
+ */
+ void
+f_getcharstr(typval_T *argvars, typval_T *rettv)
+{
+ getchar_common(argvars, rettv);
+
+ if (rettv->v_type == VAR_NUMBER)
+ {
+ char_u temp[7]; // mbyte-char: 6, NUL: 1
+ varnumber_T n = rettv->vval.v_number;
+ int i = 0;
+
+ if (n != 0)
+ {
+ if (has_mbyte)
+ i += (*mb_char2bytes)(n, temp + i);
+ else
+ temp[i++] = n;
+ }
+ temp[i++] = NUL;
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = vim_strsave(temp);
+ }
+}
+
+/*
* "getcharmod()" function
*/
void