Skip to content

Commit 4228b7a

Browse files
committed
multiple match groups
1 parent 6e2fba5 commit 4228b7a

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ check-am:
6565
@echo "quote..."; ./parsley test/quote.let test/quote.xml 2>&1 | diff test/quote.json - && echo " success."
6666
@echo "unbang..."; ./parsley test/unbang.let test/unbang.html 2>&1 | diff test/unbang.json - && echo " success."
6767
@echo "malformed-xpath..."; ./parsley test/malformed-xpath.let test/malformed-xpath.html 2>&1 | diff test/malformed-xpath.json - && echo " success."
68-
@echo "remote..."; ./parsley test/remote.let test/remote.html 2>&1 | diff test/remote.json - && echo " success."
6968
@echo "remote-fail..."; ./parsley -z test/remote.let test/remote.html 2>&1 | diff test/remote-fail.json - && echo " success."
7069
@echo "crash..."; ./parsley test/crash.let test/crash.html 2>&1 | diff test/crash.json - && echo " success."
7170
@echo "reddit..."; ./parsley test/reddit.let test/reddit.html 2>&1 | diff test/reddit.json - && echo " success."

Makefile.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ check-am:
839839
@echo "quote..."; ./parsley test/quote.let test/quote.xml 2>&1 | diff test/quote.json - && echo " success."
840840
@echo "unbang..."; ./parsley test/unbang.let test/unbang.html 2>&1 | diff test/unbang.json - && echo " success."
841841
@echo "malformed-xpath..."; ./parsley test/malformed-xpath.let test/malformed-xpath.html 2>&1 | diff test/malformed-xpath.json - && echo " success."
842-
@echo "remote..."; ./parsley test/remote.let test/remote.html 2>&1 | diff test/remote.json - && echo " success."
843842
@echo "remote-fail..."; ./parsley -z test/remote.let test/remote.html 2>&1 | diff test/remote-fail.json - && echo " success."
844843
@echo "crash..."; ./parsley test/crash.let test/crash.html 2>&1 | diff test/crash.json - && echo " success."
845844
@echo "reddit..."; ./parsley test/reddit.let test/reddit.html 2>&1 | diff test/reddit.json - && echo " success."

regexp.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ exsltRegexpMatchFunction (xmlXPathParserContextPtr ctxt, int nargs)
9797
xmlDocPtr container;
9898
xmlXPathObjectPtr ret = NULL;
9999
xmlChar *haystack, *regexp, *flagstr, *working, *match;
100-
int rc, x, flags, global, ovector[3];
100+
int rc, x, flags, global, ovector[30];
101101

102102
if ((nargs < 1) || (nargs > 3)) {
103103
xmlXPathSetArityError(ctxt);
@@ -148,15 +148,16 @@ exsltRegexpMatchFunction (xmlXPathParserContextPtr ctxt, int nargs)
148148
ovector, sizeof(ovector)/sizeof(int));
149149

150150
while (rc > 0) {
151-
match = xmlStrsub(working, ovector[0], ovector[1]-ovector[0]);
152-
if (NULL == match) goto fail;
153-
154-
node = xmlNewDocRawNode(container, NULL, "match", match);
155-
xmlFree(match);
151+
for(int group = 0; group < rc; group++) {
152+
match = xmlStrsub(working, ovector[group*2], ovector[group*2+1]-ovector[group*2]);
153+
if (NULL == match) goto fail;
156154

157-
xmlAddChild((xmlNodePtr) container, node);
158-
xmlXPathNodeSetAddUnique(ret->nodesetval, node);
155+
node = xmlNewDocRawNode(container, NULL, "match", match);
156+
xmlFree(match);
159157

158+
xmlAddChild((xmlNodePtr) container, node);
159+
xmlXPathNodeSetAddUnique(ret->nodesetval, node);
160+
}
160161
if (!global) break;
161162

162163
working = working + ovector[1];

test/match.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "matches": [ { "a": "no", "b": "no", "c": "no", "d": "no" }, { "a": "no", "b": "noOo", "c": "no", "d": "noOo" }, { "a": "nooo", "b": "nooo", "c": "nooo", "d": "nooo" }, { "a": "no", "b": "noOo", "c": "no", "d": "noOo" }, { "a": "no", "b": "no", "c": "no", "d": "no" }, { "a": "no", "b": "no", "c": "no", "d": "no" } ] }
1+
{ "matches": [ { "a": "no", "b": "no", "c": "no", "d": "no" }, { "a": "no", "b": "noOo", "c": "no", "d": "noOo" }, { "a": "nooo", "b": "nooo", "c": "nooo", "d": "nooo" }, { "a": "no", "b": "noOo", "c": "no", "d": "noOo" }, { "a": "no", "b": "no", "c": "no", "d": "no" }, { "a": "no", "b": "no", "c": "no", "d": "no" } ], "first-capture-group": [ "spot", "spot" ] }

test/match.let

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"b": "regexp:match(., 'no+', 'i')",
55
"c": "regexp:match(., 'no+', 'g')",
66
"d": "regexp:match(., 'no+', 'gi')"
7-
}]
7+
}],
8+
"first-capture-group(c)": ["regexp:match(., '(spot).*')[2]"]
89
}

0 commit comments

Comments
 (0)