From 370a94f6931a7e325ef1b23f0c15996c672ee587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 1 Aug 2015 21:33:02 +0200 Subject: text-motion: make text_bracket_match more robust Brackets which occur inside strings are ignored. --- text-motions.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/text-motions.c b/text-motions.c index 306e54c..97012bd 100644 --- a/text-motions.c +++ b/text-motions.c @@ -535,6 +535,7 @@ size_t text_bracket_match(Text *txt, size_t pos) { size_t text_bracket_match_except(Text *txt, size_t pos, const char *except) { int direction, count = 1; char search, current, c; + bool instring = false; Iterator it = text_iterator_get(txt, pos); if (!text_iterator_byte_get(&it, ¤t)) return pos; @@ -569,17 +570,25 @@ size_t text_bracket_match_except(Text *txt, size_t pos, const char *except) { if (direction >= 0) { /* forward search */ while (text_iterator_byte_next(&it, &c)) { - if (c == search && --count == 0) - return it.pos; - else if (c == current) - count++; + if (c != current && (c == '"' || c == '\'')) + instring = !instring; + if (!instring) { + if (c == search && --count == 0) + return it.pos; + else if (c == current) + count++; + } } } else { /* backwards */ while (text_iterator_byte_prev(&it, &c)) { - if (c == search && --count == 0) - return it.pos; - else if (c == current) - count++; + if (c != current && (c == '"' || c == '\'')) + instring = !instring; + if (!instring) { + if (c == search && --count == 0) + return it.pos; + else if (c == current) + count++; + } } } -- cgit v1.2.3