Skip to content

Commit

Permalink
text-motion: make text_bracket_match more robust
Browse files Browse the repository at this point in the history
Brackets which occur inside strings are ignored.
  • Loading branch information
martanne committed Aug 1, 2015
1 parent dec8bc0 commit 370a94f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions text-motions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &current))
return pos;
Expand Down Expand Up @@ -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++;
}
}
}

Expand Down

0 comments on commit 370a94f

Please sign in to comment.