eval: Refactor f_char2nr

With has_mbyte equal to 1 and &encoding always UTF-8 second argument is no 
longer useful: utf_ptr2char is the same as mb_ptr2char.

Also changes function behaviour a bit: now if second argument is not a number it 
immediately returns with error, without bothering to get a character.
This commit is contained in:
ZyX 2017-04-16 20:02:06 +03:00
parent 97a1ccf8e7
commit 7c9e3d6cad

View File

@ -7305,18 +7305,14 @@ static void f_changenr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/
static void f_char2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (has_mbyte) {
int utf8 = 0;
if (argvars[1].v_type != VAR_UNKNOWN) {
utf8 = tv_get_number_chk(&argvars[1], NULL);
if (argvars[1].v_type != VAR_UNKNOWN) {
if (!tv_check_num(&argvars[1])) {
return;
}
rettv->vval.v_number = (utf8 ? *utf_ptr2char : *mb_ptr2char)(
(const char_u *)tv_get_string(&argvars[0]));
} else {
rettv->vval.v_number = (uint8_t)(tv_get_string(&argvars[0])[0]);
}
rettv->vval.v_number = utf_ptr2char(
(const char_u *)tv_get_string(&argvars[0]));
}
/*