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.
diff --git a/src/search.c b/src/search.c
index c5810ed..5851d52 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2714,7 +2714,6 @@
/*
* 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 @@
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 @@
#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;
}