RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: lua/local/ llocal.lua rpm/ CHANGES

From: Ralf S. Engelschall <rse@rpm5.org>
Date: Sun 30 Dec 2007 - 12:27:01 CET
Message-Id: <20071230112701.DE59334845C@rpm5.org>
  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:   30-Dec-2007 12:27:01
  Branch: HEAD                             Handle: 2007123011270100

  Modified files:
    lua/local               llocal.lua
    rpm                     CHANGES

  Log:
    Improve RPM Lua function util.rsubst(): perform repeated substitutions
    and honor prolog/epilog parts. This finally allows the following nice
    substitutions possible:
    
    | $ ./rpm --eval '%{lua: print(util.rsubst("foo,%1,%2,%3,bar", "%([123])", { ["1"] = "one", ["2"] = "two", ["3"] = "three" })) }'
    | foo,one,two,three,bar

  Summary:
    Revision    Changes     Path
    1.5         +15 -8      lua/local/llocal.lua
    1.2039      +1  -0      rpm/CHANGES
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: lua/local/llocal.lua
  ============================================================================
  $ cvs diff -u -r1.4 -r1.5 llocal.lua
  --- lua/local/llocal.lua	24 Dec 2007 22:22:58 -0000	1.4
  +++ lua/local/llocal.lua	30 Dec 2007 11:27:01 -0000	1.5
  @@ -67,16 +67,23 @@
   
   --  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]]
  +    local re = rex.new(regex)
  +    while true do
  +        local s, e, m = re:match(result)
  +        if s ~= nil then
  +            local prolog = string.sub(result, 1, s - 1)
  +            local epilog = string.sub(result, e + 1)
  +            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
  +            result = prolog .. result .. epilog
           else
  -            result = string.gsub(subst, "%$(%n)", function (n) return m[n] end)
  +            break
           end
       end
       return result
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2038 -r1.2039 CHANGES
  --- rpm/CHANGES	29 Dec 2007 21:34:21 -0000	1.2038
  +++ rpm/CHANGES	30 Dec 2007 11:27:01 -0000	1.2039
  @@ -1,4 +1,5 @@
   5.0b3 -> 5.0b4:
  +    - rse: improve RPM Lua function util.rsubst(): perform repeated substitutions and honor prolog/epilog parts
       - jbj: re-add all the debugging spew under --rpmnsdebug for now.
       - jbj: functional signature(...) name space probe.
       - jbj: add rpmnsProbeSignature() & "signature(/text:/sig) = /pub:id" probe.
  @@ .
Received on Sun Dec 30 12:27:01 2007
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.