[dev-context] format() without formatting

Hans Hagen pragma at wxs.nl
Tue Jun 17 15:13:46 CEST 2008


Hans Hagen wrote:

a better one

local digit    = lpeg.R("09")
local period   = lpeg.P(".")
local zero     = lpeg.P("0")
local nozero   = 1 - zero
local finish   = lpeg.P(-1)
local nodigit  = (1-digit) + finish
local case_1   = (period * zero^1 * #nodigit)/"" -- .000
local case_2   = (period * (1-(zero^0/"") * #nodigit)^1 * (zero^0/"") * 
nodigit) -- .010 .10 .100100
local number   = digit^1 * (case_1 + case_2)
local stripper = lpeg.Cs((number + 1)^0)

function aux.strip_zeros(str)
     return stripper:match(str)
end


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the dev-context mailing list