diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LuaRegex.cc | 27 | ||||
-rw-r--r-- | lib/Regex.cc | 4 |
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; |