Arthur Reutenauer wrote:
>>       local optimized_string = formatted_string:gsub('^(%d*\.%d-)(0*)$', 
>> '%1')

okay then, let's go educational ... a better stripper:

local digit   = lpeg.R("09")
local period  = lpeg.P(".")
local zero    = lpeg.P("0")
local finish  = lpeg.P(-1)
local nodigit = (1-digit) + finish
local number  = digit^1 * ((period * zero^1 * #nodigit)/"") + (period * 
(1-zero)^0 * (zero^1/"" + digit^1) * nodigit)

local stripper = lpeg.Cs((number + 1)^0)

local sample = "bla bla 0.11100000 bla bla 0.00000 bla 0.00001 bla bla 
bla 10.11100000 bla bla 1.00000 bla 0.00001 bla"

collectgarbage("collect")
str = string.rep(sample,10000)
local ts = os.clock()
stripper:match(str)
print(#str, os.clock()-ts, stripper:match(sample))



-----------------------------------------------------------------
                                           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
-----------------------------------------------------------------
_______________________________________________
dev-context mailing list
[email protected]
http://www.ntg.nl/mailman/listinfo/dev-context

Reply via email to