Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Matroc/Testurlencode
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local subtable = {} subtable[1] = " @r+" subtable[2] = "%%3D@r=" -- Encode substitutions are done using a table in index order subtable[3] = "%%26@r&" subtable[4] = "%%3A@r:" subtable[5] = "%%2F@r/" subtable[6] = "%%3F@r?" function p.encode(frame) local lookfor = "" local replace = "" local a_str = frame.args[1] or "" -- Get URL to process local link = frame.args[2] or "" -- Create a Link if present otherwise return string local option = frame.args[3] or "wikipedia" -- Dummy argument for future special action -- Assumption that a_str begins with http/https/file etc. otherwise -- might force a_str to have "http://" as leading chars - not included -- at this time -- DECODE 1st? a_str = a_str:gsub ("+", " ") a_str = a_str:gsub ("%%(%x%x)", function(h) return string.char(tonumber(h,16)) end) a_str = string.gsub (a_str,"([^%w %-%_%.%~])", function (c) return string.format ("%%%02X", string.byte(c)) end) for i = 1 , #subtable, 1 do lookfor = string.gsub(subtable[i],"@r(.*)","") replace = string.gsub(subtable[i],"^(.*)@r","") a_str = a_str:gsub(lookfor,replace) end if link ~= "" then a_str = "[" .. a_str .. " " .. link .. "]" end return a_str end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Matroc/Testurlencode/doc
(
edit
)