summaryrefslogtreecommitdiffstats
path: root/src/charset.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-11-29 12:12:43 +0000
committerBram Moolenaar <Bram@vim.org>2021-11-29 12:12:43 +0000
commitaf377e34b01ba00f9520d2b9de1f911e72db0114 (patch)
treee3863b6aeb06509afdd60fa7448163268f24aca1 /src/charset.c
parent293eb9ba4669b1500370502397d399681e7098f0 (diff)
patch 8.2.3694: cannot use quotes in the count of an Ex commandv8.2.3694
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)
Diffstat (limited to 'src/charset.c')
-rw-r--r--src/charset.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/charset.c b/src/charset.c
index 2c46f7ad04..0c17140c75 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -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
@@ -1767,6 +1767,38 @@ getdigits(char_u **pp)
}
/*
+ * 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.
*/
int