lua-users home
lua-l archive

Re: Feature request: plain option for gsub

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Friday, August 22, 2014 09:31:19 AM Dirk Laurie wrote:
> Another con is that it would be a fifth parameter, preceded by one that
> is usually nil. No standard library routine in Lua 5.2 has that many
> non-vararg parameters.
Well it's usually 1, but...
Another pro would be that gsub can detect when there are no special characters 
in the strings and take the plain shortcut. string.find does this.
And I forgot about the 'g' in gsub, so my Lua equivalent needs to be a loop.
 local b = {}
 local o,p,q = 1,s:find(this,1,plain)
 while p do
 b[#b+1] = s:sub(o,p-1)
 o,p,q = q+1,s:find(this,q+1,plain)
 end
 b[#b+1] = s:sub(o)
 return table.concat(b,that)
-- 
tom <telliamed@whoopdedo.org>

AltStyle によって変換されたページ (->オリジナル) /