local p =
-- Usage: -- string: string to parse-- c1, c2...: single characters-- replacement1, replacement2...: what those characters are replaced by-- separator: separator between replacements-- Unknown characters are ignored and may be used for spacing.-- Example: --> dit-daah-daah-ditfunction p.char(frame) -- Extract separator local sep = if frame.args.sep ~= nil then sep = frame.args.sep end -- Extract key-value pairs local tokenlist = local i = 2 -- NB: #frame.args doesn't work; iterating the old way while frame.args[i] ~= nil do if frame.args[i]
-- Usage: -- string: string to parse-- key1, key2...: substrings to replace (one or more characters)-- replacement1, replacement2...: what those substrings are replaced by-- separator: separator between replacements-- If more than one substring matches, the longest one is used.-- If no substring matches, one character is chomped; therefore unknown characters may be used for spacing.-- This function might be more expensive than the .char version.-- Example: --> ./-/-/.function p.str(frame) -- Extract separator local sep = if frame.args.sep ~= nil then sep = frame.args.sep end -- Extract key-value pairs local tokenlist = local i = 2 -- NB: #frame.args doesn't work; iterating the old way while frame.args[i] ~= nil do if frame.args[i]
token.k then -- if str begins with substring if isfirst then isfirst = false else res = res .. sep -- add separator (except for the first time) end res = res .. token.v -- append replacement to res str = str:sub(#token.k+1) -- discard that substring found = true break end end if not found then str = str:sub(2) -- discard one character and try again end end return resend
-- [TEST] Print the arguments passedfunction p.test(frame) local res = for k,v in pairs(frame.args) do res = res .. ' [' .. k .. ']="' .. v .. '"\n' end return resend
return p