summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshmuz <shmuz>2006-11-29 19:33:05 +0000
committershmuz <shmuz>2006-11-29 19:33:05 +0000
commit352e64ad1577c67ca25ddd13153724807a940c5a (patch)
treea0a6799e2a94e8d86115fd3228b738ad50a574ec
parent0f7cd94c0e15225205904755534c98687a1c32ad (diff)
downloadlrexlib-352e64ad1577c67ca25ddd13153724807a940c5a.tar.gz
Method renamed: oldmatch to tfind.
Method renamed: oldgmatch to tgfind.
-rwxr-xr-xlua/generic_gsub.lua2
-rwxr-xr-xlua/rex.lua2
-rwxr-xr-xsrc/lpcre.c20
-rwxr-xr-xsrc/lposix.c24
-rwxr-xr-xtest/Spencer/test.lua2
-rwxr-xr-xtest/all_test.lua7
-rwxr-xr-xtest/pcre_test.lua28
-rwxr-xr-xtest/posix_test.lua22
8 files changed, 56 insertions, 51 deletions
diff --git a/lua/generic_gsub.lua b/lua/generic_gsub.lua
index 4152f85..1300a88 100755
--- a/lua/generic_gsub.lua
+++ b/lua/generic_gsub.lua
@@ -68,7 +68,7 @@ function generic_gsub (new, str, pat, repl, n, cflags, eflags)
while not n or n > reps do
- local from,to,cap = reg:oldmatch(str, start, eflags)
+ local from,to,cap = reg:tfind(str, start, eflags)
if not from then break end
insert( tb_out, sub(str, start, from-1) )
diff --git a/lua/rex.lua b/lua/rex.lua
index 5f2f461..bf75126 100755
--- a/lua/rex.lua
+++ b/lua/rex.lua
@@ -58,7 +58,7 @@ function gsub (s, p, f, n, cf, ef, lo)
local efr = bit.bor (ef or 0, NOTEMPTY, ANCHORED)
local retry
while (not n) or reps < n do
- local from, to, cap = reg:oldmatch (s, st, retry and efr or ef)
+ local from, to, cap = reg:tfind (s, st, retry and efr or ef)
if from then
table.insert (r, string.sub (s, st, from - 1))
if #cap == 0 then
diff --git a/src/lpcre.c b/src/lpcre.c
index 18b5557..eb4e9e1 100755
--- a/src/lpcre.c
+++ b/src/lpcre.c
@@ -127,8 +127,8 @@ static void Checkarg_gmatch_func (lua_State *L, TArgComp *argC, TArgExec *argE)
argC->locale = luaL_optstring (L, 5, NULL);
}
-/* method r:oldgmatch (s, f, [n], [ef]) */
-static void Checkarg_oldgmatch_method (lua_State *L, TArgExec *argE) {
+/* method r:tgfind (s, f, [n], [ef]) */
+static void Checkarg_tgfind_method (lua_State *L, TArgExec *argE) {
argE->ud = CheckUD (L, 1);
argE->text = luaL_checklstring (L, 2, &argE->textlen);
argE->funcpos = CheckFunction (L, 3);
@@ -314,7 +314,7 @@ static void LpcreSetExecData (lua_State *L, const TArgExec *argE, TExecData *trg
typedef void (*fptrPushMatches) (lua_State *L, const TArgExec *argE);
-static int Lpcre_oldmatch_generic (lua_State *L, fptrPushMatches push_matches) {
+static int Lpcre_tfind_generic (lua_State *L, fptrPushMatches push_matches) {
TArgExec argE;
TExecData ed;
int res;
@@ -376,12 +376,12 @@ static int Lpcre_dfa_exec (lua_State *L)
}
#endif /* #if PCRE_MAJOR >= 6 */
-static int Lpcre_oldmatch_method (lua_State *L) {
- return Lpcre_oldmatch_generic (L, Lpcre_push_substrings);
+static int Lpcre_tfind_method (lua_State *L) {
+ return Lpcre_tfind_generic (L, Lpcre_push_substrings);
}
static int Lpcre_exec_method (lua_State *L) {
- return Lpcre_oldmatch_generic (L, Lpcre_push_offsets);
+ return Lpcre_tfind_generic (L, Lpcre_push_offsets);
}
static int Lpcre_gmatch_iter (lua_State *L) {
@@ -513,14 +513,14 @@ static int Lpcre_match_func (lua_State *L) {
return Lpcre_findmatch_func (L, 0);
}
-static int Lpcre_oldgmatch_method (lua_State *L)
+static int Lpcre_tgfind_method (lua_State *L)
{
int res, nmatch=0, startoffset=0;
size_t len;
TPcre *ud;
TArgExec argE;
- Checkarg_oldgmatch_method (L, &argE);
+ Checkarg_tgfind_method (L, &argE);
ud = argE.ud;
while (argE.maxmatch <= 0 || nmatch < argE.maxmatch) {
@@ -602,8 +602,8 @@ static const luaL_reg pcremeta[] = {
{ "match", Lpcre_match_method },
{ "find", Lpcre_find_method },
{ "exec", Lpcre_exec_method },
- { "oldmatch", Lpcre_oldmatch_method },
- { "oldgmatch", Lpcre_oldgmatch_method },
+ { "tfind", Lpcre_tfind_method }, /* old match */
+ { "tgfind", Lpcre_tgfind_method }, /* old gmatch */
{ "__gc", Lpcre_gc },
{ "__tostring", Lpcre_tostring },
#if PCRE_MAJOR >= 6
diff --git a/src/lposix.c b/src/lposix.c
index e960506..7be9fda 100755
--- a/src/lposix.c
+++ b/src/lposix.c
@@ -122,8 +122,8 @@ static void Checkarg_gmatch_func (lua_State *L, TArgComp *argC, TArgExec *argE)
argE->eflags = luaL_optint (L, 4, EFLAGS_DEFAULT);
}
-/* method r:oldgmatch (s, f, [n], [ef]) */
-static void Checkarg_oldgmatch_method (lua_State *L, TArgExec *argE) {
+/* method r:tgfind (s, f, [n], [ef]) */
+static void Checkarg_tgfind_method (lua_State *L, TArgExec *argE) {
argE->ud = CheckUD (L, 1);
argE->text = luaL_checklstring (L, 2, &argE->textlen);
argE->funcpos = CheckFunction (L, 3);
@@ -221,7 +221,7 @@ static void CheckStartEnd (TArgExec *argE) {
#endif
}
-static int posix_oldmatch_generic (lua_State *L, posix_push_matches push_matches)
+static int posix_tfind_generic (lua_State *L, posix_push_matches push_matches)
{
size_t elen;
int res;
@@ -246,14 +246,14 @@ static int posix_oldmatch_generic (lua_State *L, posix_push_matches push_matches
return 2;
}
-static int posix_oldmatch_method (lua_State *L)
+static int posix_tfind_method (lua_State *L)
{
- return posix_oldmatch_generic (L, posix_push_substrings);
+ return posix_tfind_generic (L, posix_push_substrings);
}
static int posix_exec_method (lua_State *L)
{
- return posix_oldmatch_generic (L, posix_push_offsets);
+ return posix_tfind_generic (L, posix_push_offsets);
}
static int posix_gmatch_iter (lua_State *L)
@@ -410,12 +410,12 @@ static int posix_match_func (lua_State *L) {
return posix_findmatch_func (L, 0);
}
-static int posix_oldgmatch_method (lua_State *L) {
+static int posix_tgfind_method (lua_State *L) {
int res, nmatch=0, limit=0;
TArgExec argE;
TPosix *ud;
- Checkarg_oldgmatch_method (L, &argE);
+ Checkarg_tgfind_method (L, &argE);
ud = argE.ud;
if (argE.maxmatch > 0) /* this must be stated in the docs */
@@ -512,12 +512,12 @@ static int posix_get_flags (lua_State *L) {
}
static const luaL_reg posixmeta[] = {
- { "exec", posix_exec_method },
- { "oldmatch", posix_oldmatch_method },
- { "oldgmatch", posix_oldgmatch_method },
{ "gmatch", posix_gmatch_method },
- { "find", posix_find_method },
{ "match", posix_match_method },
+ { "find", posix_find_method },
+ { "exec", posix_exec_method },
+ { "tfind", posix_tfind_method }, /* old match */
+ { "tgfind", posix_tgfind_method }, /* old gmatch */
{ "__gc", posix_gc },
{ "__tostring", posix_tostring },
{ NULL, NULL}
diff --git a/test/Spencer/test.lua b/test/Spencer/test.lua
index a0c1442..5ce22e4 100755
--- a/test/Spencer/test.lua
+++ b/test/Spencer/test.lua
@@ -134,7 +134,7 @@ local function DoOneTest(line, lineno)
end
local function Match(expr)
- local s,e,t = expr:oldmatch(Prop.f3, Start, Eflags)
+ local s,e,t = expr:tfind(Prop.f3, Start, Eflags)
if Mustfail and s or not Mustfail and not s then
return Error("match result is not as expected")
end
diff --git a/test/all_test.lua b/test/all_test.lua
index dbba196..886e373 100755
--- a/test/all_test.lua
+++ b/test/all_test.lua
@@ -4,8 +4,13 @@ require "posix_test"
require "pcre_test"
do
+ local arg1 = ...
+ local verbose = (arg1 == "-v")
local oldprint = print
- print = function() end -- make it silent
+ if not verbose then
+ print = function() end
+ end
+
local n = 0
n = n + pcre_test.testlib ("rex_pcre")
n = n + pcre_test.testlib ("rex_pcre_nr")
diff --git a/test/pcre_test.lua b/test/pcre_test.lua
index 3a23953..5df3569 100755
--- a/test/pcre_test.lua
+++ b/test/pcre_test.lua
@@ -51,9 +51,9 @@ function testlib (libname)
end
}
- local set_m_oldgmatch = {
- -- r:oldgmatch (s, f, [n], [ef])
- SetName = "Method oldgmatch",
+ local set_m_tgfind = {
+ -- r:tgfind (s, f, [n], [ef])
+ SetName = "Method tgfind",
Test = "custom",
Func = function (lib)
local r = lib.new ("(.)b.(d)")
@@ -64,11 +64,11 @@ function testlib (libname)
local decr = function (m, t)
if m == "abcd" and fw.eq (t, {"a","d"}) then rep = rep - 1 end
end
- r:oldgmatch (subj, decr)
+ r:tgfind (subj, decr)
if rep ~= 0 then return 1 end
-------- 2: limiting number of matches in advance
rep, n = 10, 4
- r:oldgmatch (subj, decr, n)
+ r:tgfind (subj, decr, n)
if rep + n ~= 10 then return 1 end
-------- 3: break iterations from the callback
rep = 10
@@ -76,11 +76,11 @@ function testlib (libname)
decr (m, t)
if rep == 3 then return true end
end
- r:oldgmatch (subj, f2)
+ r:tgfind (subj, f2)
if rep ~= 3 then return 1 end
-------- 4: named subpatterns
r = lib.new ("(?P<dog>.)b.(?P<cat>d)")
- rep = r:oldgmatch (subj,
+ rep = r:tgfind (subj,
function (m, t)
if t.dog ~= "a" or t.cat ~= "d" then return true end
end)
@@ -90,11 +90,11 @@ function testlib (libname)
}
local set_named_subpatterns = {
- SetName = "Named Subpatterns (method oldmatch)",
+ SetName = "Named Subpatterns (method tfind)",
Test = "custom",
Func = function (lib)
local r = lib.new ("(?P<dog>.)b.(?P<cat>d)")
- local _,_,caps = r:oldmatch ("abcd")
+ local _,_,caps = r:tfind ("abcd")
if caps.dog ~= "a" or caps.cat ~= "d" then return 1 end
return 0
end
@@ -205,9 +205,9 @@ function testlib (libname)
{ { "(.)b.(d)"}, {"abcd"}, {1,4,{1,1,4,4},3}},--[captures]
}
- local set_m_oldmatch = {
- SetName = "Method oldmatch",
- FMName = "oldmatch",
+ local set_m_tfind = {
+ SetName = "Method tfind",
+ FMName = "tfind",
Test = "method",
-- {patt,cf,lo}, {subj,st,ef,co} { results }
{ {".+"}, {"abcd"}, {1,4,{},1} }, -- [none]
@@ -276,10 +276,10 @@ function testlib (libname)
n = n + fw.test2 (lib, set_m_match)
n = n + fw.test2 (lib, set_m_find)
n = n + fw.test2 (lib, set_m_exec)
- n = n + fw.test2 (lib, set_m_oldmatch)
+ n = n + fw.test2 (lib, set_m_tfind)
n = n + fw.test2 (lib, set_f_gmatch)
n = n + fw.test2 (lib, set_m_gmatch)
- n = n + fw.test2 (lib, set_m_oldgmatch)
+ n = n + fw.test2 (lib, set_m_tgfind)
n = n + fw.test2 (lib, set_named_subpatterns)
if lib.MAJOR >= 6 then
diff --git a/test/posix_test.lua b/test/posix_test.lua
index a9e646d..4a261b5 100755
--- a/test/posix_test.lua
+++ b/test/posix_test.lua
@@ -42,9 +42,9 @@ function testlib (libname)
end
}
- local set_m_oldgmatch = {
- -- r:oldgmatch (s, f, [n], [ef])
- SetName = "Method oldgmatch",
+ local set_m_tgfind = {
+ -- r:tgfind (s, f, [n], [ef])
+ SetName = "Method tgfind",
Test = "custom",
Func = function (lib)
local r = lib.new ("(.)b.(d)")
@@ -55,11 +55,11 @@ function testlib (libname)
local decr = function (m, t)
if m == "abcd" and fw.eq (t, {"a","d"}) then rep = rep - 1 end
end
- r:oldgmatch (subj, decr)
+ r:tgfind (subj, decr)
if rep ~= 0 then return 1 end
-------- 2: limiting number of matches in advance
rep, n = 10, 4
- r:oldgmatch (subj, decr, n)
+ r:tgfind (subj, decr, n)
if rep + n ~= 10 then return 1 end
-------- 3: break iterations from the callback
rep = 10
@@ -67,7 +67,7 @@ function testlib (libname)
decr (m, t)
if rep == 3 then return true end
end
- r:oldgmatch (subj, f2)
+ r:tgfind (subj, f2)
if rep ~= 3 then return 1 end
return 0
end
@@ -158,9 +158,9 @@ function testlib (libname)
{ { "(.)b.(d)"}, {"abcd"}, {1,4,{1,1,4,4},0}},--[captures]
}
- local set_m_oldmatch = {
- SetName = "Method oldmatch",
- FMName = "oldmatch",
+ local set_m_tfind = {
+ SetName = "Method tfind",
+ FMName = "tfind",
Test = "method",
-- {patt,cf}, {subj,st,ef} { results }
{ {".+"}, {"abcd"}, {1,4,{},0} }, -- [none]
@@ -201,10 +201,10 @@ function testlib (libname)
n = n + fw.test2 (lib, set_m_match)
n = n + fw.test2 (lib, set_m_find)
n = n + fw.test2 (lib, set_m_exec)
- n = n + fw.test2 (lib, set_m_oldmatch)
+ n = n + fw.test2 (lib, set_m_tfind)
n = n + fw.test2 (lib, set_f_gmatch)
n = n + fw.test2 (lib, set_m_gmatch)
- n = n + fw.test2 (lib, set_m_oldgmatch)
+ n = n + fw.test2 (lib, set_m_tgfind)
print ""
return n
end