aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/search.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-01-31 15:44:54 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-01-31 15:44:54 +0800
commitae649650de3509e22ee6fad5cfa72998d40f2a92 (patch)
treed20ee547a92c0840e829bdcdc6209f3388f89abc /src/nvim/search.c
parentf7801fe138d9677c9333650b4d5581489d4b0613 (diff)
downloadrneovim-ae649650de3509e22ee6fad5cfa72998d40f2a92.tar.gz
rneovim-ae649650de3509e22ee6fad5cfa72998d40f2a92.tar.bz2
rneovim-ae649650de3509e22ee6fad5cfa72998d40f2a92.zip
vim-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. https://github.com/vim/vim/commit/ba26367fea3b63df49d274f3d5cca0af38402add
Diffstat (limited to 'src/nvim/search.c')
-rw-r--r--src/nvim/search.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 6195be42ba..93180f97fe 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -26,6 +26,7 @@
#include "nvim/func_attr.h"
#include "nvim/getchar.h"
#include "nvim/indent.h"
+#include "nvim/indent_c.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
@@ -2313,11 +2314,8 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
return (pos_T *)NULL; // never found it
}
-/*
- * Check if line[] contains a / / comment.
- * Return MAXCOL if not, otherwise return the column.
- * TODO: skip strings.
- */
+/// Check if line[] contains a / / comment.
+/// @returns MAXCOL if not, otherwise return the column.
int check_linecomment(const char_u *line)
{
const char_u *p = line; // scan from start
@@ -2338,7 +2336,8 @@ int check_linecomment(const 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++;
@@ -2348,9 +2347,11 @@ int check_linecomment(const char_u *line)
}
} else {
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;