-->
Page 1 of 1

lightweight url decode encode

PostPosted: Sun Apr 05, 2015 3:22 am
by timoline
Is there somewhere a lightweight url decode/encode lua code available..

i tried the following but they are too memory intensive

Code: Select allfunction urldecode(str)
    str = string.gsub(str, "+", " ")
    str = string.gsub(str, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
    str = string.gsub(str, "\r\n", "\n")
    return str
end

or
Code: Select allhex={}
for i=0,255 do
    hex[string.format("%0x",i)]=string.char(i)
    hex[string.format("%0X",i)]=string.char(i)
end

function decodeURI(s)
    return (s:gsub('%%(%x%x)',hex))
end

Re: lightweight url decode encode

PostPosted: Sun Apr 05, 2015 3:54 am
by cal
Moin,

memory usage depends on the firmware you using. Latest march release uses too much.
If you can build firmware yourself reduce LUAI_BUFFERSIZE by removing the factor 4 which was introduced
by some file system changes. Unfortunately no statement from dev team about that issue yet.
There is a "gsub" thread about that issue.

Carsten

Re: lightweight url decode encode

PostPosted: Sun Apr 05, 2015 4:17 am
by timoline
Thanx for your answer
Unfortunately I can't build FW myself yet, I'll try an older FW
But I found the thread:
viewtopic.php?f=18&t=2137&p=13376&hilit=gsub#p12711

same goal, same problem :|

Re: lightweight url decode encode

PostPosted: Sun Apr 05, 2015 4:51 am
by timoline