aboutsummaryrefslogtreecommitdiff
path: root/text-motions.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-08-01 21:33:02 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-08-02 00:13:51 +0200
commit370a94f6931a7e325ef1b23f0c15996c672ee587 (patch)
tree73c7bc6b8afbef0602d61200c5b449dc95bec0dd /text-motions.c
parentdec8bc0015c9fc0e6f4283557cb088718348ec80 (diff)
downloadvis-370a94f6931a7e325ef1b23f0c15996c672ee587.tar.gz
vis-370a94f6931a7e325ef1b23f0c15996c672ee587.tar.xz
text-motion: make text_bracket_match more robust
Brackets which occur inside strings are ignored.
Diffstat (limited to 'text-motions.c')
-rw-r--r--text-motions.c25
1 files 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, &current))
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++;
+ }
}
}