| tmot: fix lbuf_pair() in lines with multi-byte characters - neatvi - [fork] sim… | |
| git clone git://src.adamsgaard.dk/neatvi | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 0cda11bd3981b5cdf7c73774420019413e9fe032 | |
| parent e4391d06a150886b08bc2fa1965957a7bb27f12a | |
| Author: Ali Gholami Rudi <[email protected]> | |
| Date: Wed, 1 Sep 2021 19:02:16 +0430 | |
| mot: fix lbuf_pair() in lines with multi-byte characters | |
| Reported and tested by Kyryl Melekhin <[email protected]>. | |
| Diffstat: | |
| M mot.c | 19 +++++++++---------- | |
| 1 file changed, 9 insertions(+), 10 deletions(-) | |
| --- | |
| diff --git a/mot.c b/mot.c | |
| t@@ -194,21 +194,20 @@ int lbuf_wordend(struct lbuf *lb, int big, int dir, int … | |
| int lbuf_pair(struct lbuf *lb, int *row, int *off) | |
| { | |
| int r = *row, o = *off; | |
| - char *ln = lbuf_get(lb, *row); | |
| char *pairs = "()[]{}"; | |
| - int p; /* index for pairs[] */ | |
| + int pchr; /* parenthesis character */ | |
| + int pidx; /* index into pairs[] */ | |
| int dep = 1; /* parenthesis depth */ | |
| - if (!ln || !ln[o]) | |
| + while ((pchr = (unsigned char) lbuf_chr(lb, r, o)[0]) && !strchr(pairs… | |
| + o++; | |
| + if (!pchr) | |
| return 1; | |
| - while (!strchr(pairs, ln[o])) | |
| - if (!ln[++o]) | |
| - return 1; | |
| - p = strchr(pairs, ln[o]) - pairs; | |
| - while (!lbuf_next(lb, (p & 1) ? -1 : +1, &r, &o)) { | |
| + pidx = strchr(pairs, pchr) - pairs; | |
| + while (!lbuf_next(lb, (pidx & 1) ? -1 : +1, &r, &o)) { | |
| int c = (unsigned char) lbuf_chr(lb, r, o)[0]; | |
| - if (c == pairs[p ^ 1]) | |
| + if (c == pairs[pidx ^ 1]) | |
| dep--; | |
| - if (c == pairs[p]) | |
| + if (c == pairs[pidx]) | |
| dep++; | |
| if (!dep) { | |
| *row = r; |