Difference between revisions of "Module:Trim quotes"

From blackwiki
Jump to navigation Jump to search
blackwiki>Ahecht
(Correctly move function to p._trim)
m (9 revisions imported)
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
function p._trim(s)
 
function p._trim(s)
 
if s then
 
if s then
if mw.ustring.find(s,'^".*"$') or mw.ustring.find(s,"^'.*'$") then return p._trim(string.sub(s,2,-2)) else return s end
+
if s:match([[^(['"]).*%1$]]) then return p._trim(string.sub(s,2,-2)) else return s end
 
else
 
else
 
return ""
 
return ""
 
end
 
end
 
end
 
end
 
  
 
function p.trim(frame)
 
function p.trim(frame)
Line 14: Line 13:
 
return p._trim(s)
 
return p._trim(s)
 
end
 
end
+
 
 
return p
 
return p

Latest revision as of 17:41, 29 September 2020

Implements {{Trim quotes}}.

Usage

{{#invoke:Trim quotes|trim|string to trim}}

or

{{#invoke:Trim quotes|trim|s=string to trim}}



local p = {}

function p._trim(s)
	if s then
		if s:match([[^(['"]).*%1$]]) then return p._trim(string.sub(s,2,-2)) else return s end
	else
		return ""
	end
end

function p.trim(frame)
	local s = (frame.args['s'] or frame.args[1]) or (frame:getParent().args['s'] or frame:getParent().args[1])
	return p._trim(s)
end

return p