1
0
forked from aniani/vim

patch 8.2.3694: cannot use quotes in the count of an Ex command

Problem:    Cannot use quotes in the count of an Ex command.
Solution:   Add getdigits_quoted().  Give an error when misplacing a quote in
            a range. (closes #9240)
This commit is contained in:
Bram Moolenaar
2021-11-29 12:12:43 +00:00
parent 293eb9ba46
commit af377e34b0
5 changed files with 78 additions and 3 deletions

View File

@@ -1748,7 +1748,7 @@ skiptowhite_esc(char_u *p)
}
/*
* Getdigits: Get a number from a string and skip over it.
* Get a number from a string and skip over it.
* Note: the argument is a pointer to a char_u pointer!
*/
long
@@ -1766,6 +1766,38 @@ getdigits(char_u **pp)
return retval;
}
/*
* Like getdigits() but allow for embedded single quotes.
*/
long
getdigits_quoted(char_u **pp)
{
char_u *p = *pp;
long retval = 0;
if (*p == '-')
++p;
while (VIM_ISDIGIT(*p))
{
if (retval >= LONG_MAX / 10 - 10)
retval = LONG_MAX;
else
retval = retval * 10 - '0' + *p;
++p;
if (in_vim9script() && *p == '\'' && VIM_ISDIGIT(p[1]))
++p;
}
if (**pp == '-')
{
if (retval == LONG_MAX)
retval = LONG_MIN;
else
retval = -retval;
}
*pp = p;
return retval;
}
/*
* Return TRUE if "lbuf" is empty or only contains blanks.
*/