RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Ralf S. Engelschall
Root: /v/rpm/cvs Email: rse@rpm5.org
Module: rpm lua Date: 24-Dec-2007 16:02:11
Branch: HEAD Handle: 2007122415021001
Modified files:
lua/local llocal.lua
rpm CHANGES
Log:
add local Lua functions util.rmatch() and util.rsubst() for regex
matching/substitution and improve "rex.new" Lua object by using PCRE if
possible and fallback to POSIX regex only.
Summary:
Revision Changes Path
1.2 +32 -1 lua/local/llocal.lua
1.2016 +2 -0 rpm/CHANGES
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: lua/local/llocal.lua
============================================================================
$ cvs diff -u -r1.1 -r1.2 llocal.lua
--- lua/local/llocal.lua 15 Jul 2007 17:56:18 -0000 1.1
+++ lua/local/llocal.lua 24 Dec 2007 15:02:11 -0000 1.2
@@ -1,8 +1,15 @@
-rex.new = rex.newPOSIX
+-- provide a generic regular expression constructor
+-- based on the most powerful regular expression engine
+rex.new = rex.newPCRE
+if rex.new == nil then
+ rex.new = rex.newPOSIX
+end
+-- provide namespace
util = {}
+-- "global regular expression print" on file content
function util.grep(expr, filename)
if not posix.stat(filename, "mode") then
return nil
@@ -22,10 +29,12 @@
return lines
end
+-- iterator version
function util.igrep(expr, filename)
return ipairs(rex.grep(expr, filename))
end
+-- boolean version
function util.bgrep(expr, filename)
if not posix.stat(filename, "mode") then
return nil
@@ -39,3 +48,25 @@
return false
end
+-- regular expression based string matching
+function util.rmatch(str, regex)
+ return rex.new(regex):match(str)
+end
+
+-- regular expression based string substitution
+function util.rsubst(str, regex, subst)
+ local re = rex.new(regex)
+ local s, e, m = re:match(str)
+ local result = str
+ if s ~= nil then
+ if type(subst) == "function" then
+ result = subst(m)
+ elseif type(subst) == "table" then
+ result = subst[m[1]]
+ else
+ result = string.gsub(subst, "%$(%n)", function (n) return m[n] end)
+ end
+ end
+ return result
+end
+
@@ .
patch -p0 <<'@@ .'
Index: rpm/CHANGES
============================================================================
$ cvs diff -u -r1.2015 -r1.2016 CHANGES
--- rpm/CHANGES 24 Dec 2007 14:52:44 -0000 1.2015
+++ rpm/CHANGES 24 Dec 2007 15:02:10 -0000 1.2016
@@ -1,4 +1,6 @@
5.0b3 -> 5.0b4:
+ - rse: add local Lua functions util.rmatch() and util.rsubst() for regex matching/substitution
+ - rse: improve rex.new Lua object by using PCRE if possible and fallback to POSIX regex only
- rse: fix loading of "local" Lua extension: it has to come after the other extensions as uses them
- rse: add error handling to the Lua script loading code generated by bin2c
- rse: add an RPM Lua function rpm.load() for loading external RPM macro definition file
@@ .
Received on Mon Dec 24 16:02:11 2007