vim-patch:8.0.0167

Problem:    str2nr() and str2float() do not always work with negative values.
Solution:   Be more flexible about handling signs. (LemonBoy, closes vim/vim#1332)
            Add more tests.

08243d26d2
This commit is contained in:
James McCoy
2017-06-05 22:39:09 -04:00
parent b1d4ef2b42
commit 17d616037d
4 changed files with 45 additions and 3 deletions

View File

@@ -15698,11 +15698,15 @@ static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static void f_str2float(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p = skipwhite((const char_u *)tv_get_string(&argvars[0]));
bool isneg = (*p == '-');
if (*p == '+') {
if (*p == '+' || *p == '-') {
p = skipwhite(p + 1);
}
(void)string2float((char *)p, &rettv->vval.v_float);
if (isneg) {
rettv->vval.v_float *= -1;
}
rettv->v_type = VAR_FLOAT;
}
@@ -15722,7 +15726,8 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
char_u *p = skipwhite((const char_u *)tv_get_string(&argvars[0]));
if (*p == '+') {
bool isneg = (*p == '-');
if (*p == '+' || *p == '-') {
p = skipwhite(p + 1);
}
switch (base) {
@@ -15743,7 +15748,11 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
vim_str2nr(p, NULL, NULL, what, &n, NULL, 0);
rettv->vval.v_number = n;
if (isneg) {
rettv->vval.v_number = -n;
} else {
rettv->vval.v_number = n;
}
}
/*