Introduction
Introduction Statistics Contact Development Disclaimer Help
trset: bracket expressions may contain [ in re_groupcount() - neatvi - [fork] s…
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit 1f5e321f1f46b3e29f0b99015c2dd76a4b790e9b
parent 4e18f428ca3d31fbba8f0cd92ac71dda85a73422
Author: Ali Gholami Rudi <[email protected]>
Date: Wed, 15 Sep 2021 02:07:17 +0430
rset: bracket expressions may contain [ in re_groupcount()
Reported by Kyryl Melekhin <[email protected]>.
Diffstat:
M rset.c | 33 ++++++++++++++++++++---------…
1 file changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/rset.c b/rset.c
t@@ -15,23 +15,32 @@ struct rset {
static int re_groupcount(char *s)
{
- int n = 0;
+ int n = 0; /* number of groups */
+ int brk = 0; /* one if inside a bracket expression */
+ int brk2 = 0; /* nested bracket type: ':', '*', or '=' */
while (*s) {
- if (s[0] == '(')
- n++;
- if (s[0] == '[') {
- int dep = 0;
- s += s[1] == '^' ? 3 : 2;
- while (s[0] && (s[0] != ']' || dep)) {
- if (s[0] == '[')
- dep++;
+ if (!brk) {
+ if (s[0] == '(')
+ n++;
+ if (s[0] == '\\' && s[1]) {
+ s++;
+ } else if (s[0] == '[' && s[1] && s[2]) {
+ s += s[1] == '^' ? 2 : 1;
+ brk = 1;
+ }
+ } else {
+ if (!brk2) {
if (s[0] == ']')
- dep--;
+ brk = 0;
+ if (s[0] == '[' && (s[1] == ':' || s[1] == '*'…
+ brk2 = s[1];
+ s++;
+ }
+ } else if (s[0] == brk2 && s[1] == ']') {
+ brk2 = 0;
s++;
}
}
- if (s[0] == '\\' && s[1])
- s++;
s++;
}
return n;
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.