[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Problem with table key iteration when string keys are unpredictable
- From: "S. Fisher" <expandafter@...>
- Date: Tue, 21 May 2013 03:59:34 -0700 (PDT)
--- On Tue, 5/21/13, S. Fisher <expandafter@yahoo.com> wrote:
>
> function substitute(s, substitutions)
> sorted = {}
> for k, _ in pairs( substitutions ) do
> table.insert( sorted, k )
> end
> table.sort( sorted, function (a,b) return #a > #b
> end )
> for _, key in ipairs( sorted ) do
> s,cnt = string.gsub(s, escape(key),
> substitutions)
> end
> return s
> end
>
function substitute(s, substitutions)
local sorted = {}
for k, _ in pairs( substitutions ) do
table.insert( sorted, k )
end
table.sort( sorted, function (a,b) return #a > #b end )
for _, key in ipairs( sorted ) do
s = string.gsub(s, escape(key), substitutions)
end
return s
end