Mercurial > vim
diff src/search.c @ 26819:0d798c7e1865 v8.2.3938
patch 8.2.3938: line comment start is also found in a string
Commit: https://github.com/vim/vim/commit/ba26367fea3b63df49d274f3d5cca0af38402add
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 29 18:09:13 2021 +0000
patch 8.2.3938: line comment start is also found in a string
Problem: Line comment start is also found in a string.
Solution: Skip line comments in a string.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 29 Dec 2021 19:15:03 +0100 |
parents | 9596c652420b |
children | bce848ec8b1b |
line wrap: on
line diff
--- a/src/search.c +++ b/src/search.c @@ -2714,7 +2714,6 @@ findmatchlimit( /* * Check if line[] contains a / / comment. * Return MAXCOL if not, otherwise return the column. - * TODO: skip strings. */ int check_linecomment(char_u *line) @@ -2746,7 +2745,8 @@ check_linecomment(char_u *line) in_str = TRUE; } else if (!in_str && ((p - line) < 2 - || (*(p - 1) != '\\' && *(p - 2) != '#'))) + || (*(p - 1) != '\\' && *(p - 2) != '#')) + && !is_pos_in_string(line, (colnr_T)(p - line))) break; // found! ++p; } @@ -2758,9 +2758,11 @@ check_linecomment(char_u *line) #endif while ((p = vim_strchr(p, '/')) != NULL) { - // accept a double /, unless it's preceded with * and followed by *, - // because * / / * is an end and start of a C comment - if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*')) + // Accept a double /, unless it's preceded with * and followed by *, + // because * / / * is an end and start of a C comment. + // Only accept the position if it is not inside a string. + if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*') + && !is_pos_in_string(line, (colnr_T)(p - line))) break; ++p; }