lua-users home
lua-l archive

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


> Is there any sort of "null pattern" I could initialize encodedEntity
> and decodedEntity to (i.e. nullpattern + pattern == pattern) so I
> wouldn't need the if block in the for loop?

I guess you could do both encodedEntity and decodedEntity using query
captures. More or less like this:

local encodedEntity, decodedEntity
local entities = {amp="&", lt="<", gt=">", apos=[[']], quot=[["]]}

decodedEntity = "&" * lpeg.C(letter^1) * ";" / entities

local s, t = "", {}
for name, char in pairs(entities) do
  t[char] = "&" .. name .. ";"; s = s .. char
end

encodedEntity = lpeg.S(s) / t


> Also, is that #lpeg.P("&") in xmlTextDecode good practice or
> unnecessary? Any other comments about how I'm doing this?

Usually, I think the less lpeg.P we use the better.

-- Roberto