@matheusbsbs / matheus-bagliano / commits / e701fadb9e
Fork 0

grep: fix word-regexp colouring

As noticed by Dmitry Gryazin: When a pattern is found but it doesn't start and end at word boundaries, bol is forwarded to after the match and the pattern is searched again. When a pattern is finally found between word boundaries, the match offsets are off by the number of characters that have been skipped. This patch corrects the offsets to be relative to the value of bol as passed to match_one_pattern() by its caller. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 20, 2009 at 23:31 UTC e701fadb9e0e51a6811690d95a53bd1f5b6fad86
1 file changed +5
grep.c
+5
@@ -305,6 +305,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
305 {
306 int hit = 0;
307 int saved_ch = 0;
308 + const char *start = bol;
309
310 if ((p->token != GREP_PATTERN) &&
311 ((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
@@ -365,6 +366,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
366 }
367 if (p->token == GREP_PATTERN_HEAD && saved_ch)
368 *eol = saved_ch;
369 + if (hit) {
370 + pmatch[0].rm_so += bol - start;
371 + pmatch[0].rm_eo += bol - start;
372 + }
373 return hit;
374 }
375