0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.2957: using getchar() in Vim9 script is problematic

Problem:    Using getchar() in Vim9 script is problematic.
Solution:   Add getcharstr(). (closes #8343)
This commit is contained in:
Bram Moolenaar
2021-06-07 18:29:17 +02:00
parent f05d2fc539
commit 3a7503c34c
6 changed files with 70 additions and 5 deletions

View File

@@ -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;
@@ -2126,6 +2126,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
*/