Oniguruma: add method

This commit is contained in:
Shmuel Zeigerman
2015-04-19 17:20:35 +03:00
parent 065c8403a5
commit 48a2fd3e66
4 changed files with 40 additions and 5 deletions
+11
View File
@@ -744,6 +744,17 @@ library.
------------------------------------------------------------
capturecount
------------
[See *onig_number_of_captures* in the Oniguruma docs.]
:funcdef:`r:capturecount ()`
Returns the number of captures in the pattern.
------------------------------------------------------------
TRE-only functions and methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+7
View File
@@ -286,6 +286,12 @@ static int split_exec (TOnig *ud, TArgExec *argE, int st) {
return gsub_exec(ud, argE, st);
}
static int LOnig_capturecount (lua_State *L) {
TOnig *ud = check_ud(L);
lua_pushinteger(L, onig_number_of_captures(ud->reg));
return 1;
}
static int LOnig_gc (lua_State *L) {
TOnig *ud = check_ud (L);
if (ud->reg) { /* precaution against "manual" __gc calling */
@@ -318,6 +324,7 @@ static const luaL_Reg r_methods[] = {
{ "tfind", algm_tfind }, /* old name: match */
{ "find", algm_find },
{ "match", algm_match },
{ "capturecount", LOnig_capturecount },
{ "__gc", LOnig_gc },
{ "__tostring", LOnig_tostring },
{ NULL, NULL }
+14
View File
@@ -134,6 +134,19 @@ local function set_m_tfind (lib, flg)
}
end
local function set_m_capturecount (lib, flg)
return {
Name = "Method capturecount",
Method = "capturecount",
--{patt,cf,lo}, {subj,st,ef} { results }
{ {"a"}, {}, { 0 } },
{ {"(a)"}, {}, { 1 } },
{ {"(a)(a)"}, {}, { 2 } },
{ {"((a)a)"}, {}, { 2 } },
{ {"((?i)a)(?:a)"}, {}, { 1 } },
}
end
return function (libname)
local lib = require (libname)
local flags = lib.flags ()
@@ -144,6 +157,7 @@ return function (libname)
set_f_split (lib, flags),
set_m_exec (lib, flags),
set_m_tfind (lib, flags),
set_m_capturecount (lib, flags),
}
local MAJOR = tonumber(lib.version():match("%d+"))
if MAJOR >= 0 then
+8 -5
View File
@@ -8,16 +8,19 @@ VERSION = 2.8.0
LUAVERSION = 51
LUADOTVERSION = $(subst 5,5.,$(LUAVERSION))
# Target bitness: 32 or 64
DIRBIT = 32
# INSTALLPATH : Path to install the built DLL.
# LUADLL : Name of Lua DLL to link to (.dll should be omitted).
# LUAEXE : Name of Lua interpreter.
# LUAINC : Path of Lua include files.
# LIBPATH : Path of lua51.dll, lua52.dll, pcre.dll, etc.
INSTALLPATH = s:\exe\lib32\lua\$(LUADOTVERSION)
INSTALLPATH = s:\exe\lib$(DIRBIT)\lua\$(LUADOTVERSION)
LUADLL = lua$(LUAVERSION)
LUAINC = s:\progr\work\system\include\lua\$(LUADOTVERSION)
LIBPATH = c:\exe32
LIBPATH = c:\exe$(DIRBIT)
ifeq ($(LUAVERSION),51)
LUAEXE = lua.exe
@@ -33,16 +36,16 @@ endif
BIN = $(PROJECT).dll
BININSTALL = $(INSTALLPATH)\$(BIN)
CC = mingw32-gcc
CC = gcc
AR = ar rcu
RANLIB = ranlib
CFLAGS = -W -Wall -O2 $(INCS) -DREX_OPENLIB=luaopen_$(PROJECT) \
-DREX_LIBNAME=\"$(PROJECT)\" -DVERSION=\"$(VERSION)\" \
$(CREATEGLOBAL) $(LUA_COMPAT) $(MYCFLAGS)
-m$(DIRBIT) $(CREATEGLOBAL) $(LUA_COMPAT) $(MYCFLAGS)
DEFFILE = $(PROJECT).def
EXPORTED = luaopen_$(PROJECT)
INCS = -I$(LUAINC) $(MYINCS)
LIBS = -l$(LUADLL) $(MYLIBS) -s
LIBS = -l$(LUADLL) -m$(DIRBIT) -s $(MYLIBS)
SRCPATH = ..\..\src
TESTPATH = ..\..\test