summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2008-10-16 02:44:54 +0200
committerPixel <pixel@nobis-crew.org>2008-10-16 02:44:54 +0200
commitab4700c941b95a3c7f6c19b42a1e0e2b35e1fe81 (patch)
treeb05936a89c487de372be657020ec619da910f543 /lib
parent59288143eaf405ea4f855464dea1b1c0eb382ad5 (diff)
Adding submatches system.
Diffstat (limited to 'lib')
-rw-r--r--lib/LuaRegex.cc27
-rw-r--r--lib/Regex.cc4
2 files changed, 27 insertions, 4 deletions
diff --git a/lib/LuaRegex.cc b/lib/LuaRegex.cc
index 16cf732..00c44ee 100644
--- a/lib/LuaRegex.cc
+++ b/lib/LuaRegex.cc
@@ -86,17 +86,40 @@ void LuaRegex::pushstatics(Lua * L) throw (GeneralException) {
L->settable(LUA_GLOBALSINDEX);
}
+#define MAX_MATCHES 64
+
int sLua_Regex::Regex_proceed(Lua * L, int n, Regex * r, int caller) {
+ int r = 0, i, n;
+ bool m;
String s;
+ regmatch_t pmatches[MAX_MATCHES];
switch (caller) {
case REGEX_MATCH:
s = L->tostring(2);
- L->push(r->Match(s));
+ L->push(m = r->Match(s, MAX_MATCHES, pmatches));
+ if (!m)
+ return 1;
+ L->newtable();
+ n = 1;
+ for (i = 0; i < MAX_MATCHES; i++) {
+ if (pmatches[i].rm_so == -1)
+ continue;
+ L->push((lua_Number) n++);
+ L->newtable();
+ L->push("start");
+ L->push((lua_Number) patches.rm_so + 1);
+ L->settable();
+ L->push("size");
+ L->push((lua_Number) patches.rm_eo - patches.rm_so);
+ L->settable();
+ L->settable();
+ }
+ r = 2;
break;
}
- return 1;
+ return r;
}
int sLua_Regex::Regex_proceed_statics(Lua * L, int n, int caller) {
diff --git a/lib/Regex.cc b/lib/Regex.cc
index c614d85..68ccba8 100644
--- a/lib/Regex.cc
+++ b/lib/Regex.cc
@@ -54,8 +54,8 @@ Regex::~Regex() {
free(pattern);
}
-bool Regex::Match(const String & s) const {
- if (regexec(&preg, s.to_charp(), 0, 0, eflags)) {
+bool Regex::Match(const String & s, int nmatch, regmatch_t * pmatch) const {
+ if (regexec(&preg, s.to_charp(), nmatch, pmatch, eflags)) {
return false;
} else {
return true;