To: vim_dev@googlegroups.com Subject: Patch 8.2.3694 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.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) Files: src/ex_docmd.c, src/charset.c, src/proto/charset.pro, src/testdir/test_usercommands.vim *** ../vim-8.2.3693/src/ex_docmd.c 2021-11-28 20:24:12.231530800 +0000 --- src/ex_docmd.c 2021-11-29 12:05:49.640382827 +0000 *************** *** 2402,2408 **** && (!(ea.argt & EX_BUFNAME) || *(p = skipdigits(ea.arg + 1)) == NUL || VIM_ISWHITE(*p))) { ! n = getdigits(&ea.arg); ea.arg = skipwhite(ea.arg); if (n <= 0 && !ni && (ea.argt & EX_ZEROR) == 0) { --- 2402,2408 ---- && (!(ea.argt & EX_BUFNAME) || *(p = skipdigits(ea.arg + 1)) == NUL || VIM_ISWHITE(*p))) { ! n = getdigits_quoted(&ea.arg); ea.arg = skipwhite(ea.arg); if (n <= 0 && !ni && (ea.argt & EX_ZEROR) == 0) { *************** *** 3950,3959 **** */ char_u * skip_range( ! char_u *cmd, int skip_star, // skip "*" used for Visual range int *ctx) // pointer to xp_context or NULL { unsigned delim; while (vim_strchr((char_u *)" \t0123456789.$%'/?-+,;\\", *cmd) != NULL) --- 3950,3960 ---- */ char_u * skip_range( ! char_u *cmd_start, int skip_star, // skip "*" used for Visual range int *ctx) // pointer to xp_context or NULL { + char_u *cmd = cmd_start; unsigned delim; while (vim_strchr((char_u *)" \t0123456789.$%'/?-+,;\\", *cmd) != NULL) *************** *** 3967,3972 **** --- 3968,3984 ---- } else if (*cmd == '\'') { + char_u *p = cmd; + + // a quote is only valid at the start or after a separator + while (p > cmd_start) + { + --p; + if (!VIM_ISWHITE(*p)) + break; + } + if (cmd > cmd_start && !VIM_ISWHITE(*p) && *p != ',' && *p != ';') + break; if (*++cmd == NUL && ctx != NULL) *ctx = EXPAND_NOTHING; } *** ../vim-8.2.3693/src/charset.c 2021-10-16 17:51:08.047842118 +0100 --- src/charset.c 2021-11-29 11:23:49.591928873 +0000 *************** *** 1748,1754 **** } /* ! * Getdigits: Get a number from a string and skip over it. * Note: the argument is a pointer to a char_u pointer! */ long --- 1748,1754 ---- } /* ! * Get a number from a string and skip over it. * Note: the argument is a pointer to a char_u pointer! */ long *************** *** 1765,1770 **** --- 1765,1802 ---- *pp = p; 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. *** ../vim-8.2.3693/src/proto/charset.pro 2021-04-06 19:21:55.299147728 +0100 --- src/proto/charset.pro 2021-11-29 11:11:11.346955319 +0000 *************** *** 54,59 **** --- 54,60 ---- char_u *skiptowhite(char_u *p); char_u *skiptowhite_esc(char_u *p); long getdigits(char_u **pp); + long getdigits_quoted(char_u **pp); int vim_isblankline(char_u *lbuf); void vim_str2nr(char_u *start, int *prep, int *len, int what, varnumber_T *nptr, uvarnumber_T *unptr, int maxlen, int strict); int hex2nr(int c); *** ../vim-8.2.3693/src/testdir/test_usercommands.vim 2021-11-12 16:06:00.007210755 +0000 --- src/testdir/test_usercommands.vim 2021-11-29 12:06:51.724267043 +0000 *************** *** 677,680 **** --- 677,708 ---- call assert_equal(0, exists(':Global')) endfunc + def Test_count_with_quotes() + command -count GetCount g:nr = + execute("GetCount 1'2") + assert_equal(12, g:nr) + execute("GetCount 1'234'567") + assert_equal(1'234'567, g:nr) + + execute("GetCount 1'234'567'890'123'456'789'012") + assert_equal(v:sizeoflong == 8 ? 9223372036854775807 : 2147483647, g:nr) + + # TODO: test with negative number once this is supported + + assert_fails("GetCount '12", "E488:") + assert_fails("GetCount 12'", "E488:") + assert_fails("GetCount 1''2", "E488:") + + assert_fails(":1'2GetCount", 'E492:') + new + setline(1, 'text') + normal ma + execute(":1, 'aprint") + bwipe! + + unlet g:nr + delcommand GetCount + enddef + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.3693/src/version.c 2021-11-29 10:36:15.916827518 +0000 --- src/version.c 2021-11-29 11:09:04.555193467 +0000 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 3694, /**/ -- It might look like I'm doing nothing, but at the cellular level I'm really quite busy. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///