Difference between revisions of "Template:Str endswith"

m (Protected "Module:Str endswith": High-risk Lua module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
m (1 revision imported)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
−
-- This module implements {{str endswith}}.
+
{{#invoke:Str endswith|main}}<noinclude>
−
 
+
{{documentation}}
−
local TRUE_STRING = 'yes'
+
</noinclude>
−
local FALSE_STRING = ''
 
−
 
 
−
local p = {}
 
−
 
 
−
local function trim(s)
 
−
return s:match('^%s*(.-)%s*$')
 
−
end
 
−
 
 
−
function p.main(frame)
 
−
local args = frame:getParent().args
 
−
local s = args[1]
 
−
local pattern = args[2]
 
−
if not s or not pattern then
 
−
-- TRUE_STRING is not the natural choice here, but is needed for
 
−
-- backwards compatibility.
 
−
return TRUE_STRING
 
−
end
 
−
s = trim(s)
 
−
pattern = trim(pattern)
 
−
if pattern == '' then
 
−
-- All strings end with the empty string.
 
−
return TRUE_STRING
 
−
end
 
−
if mw.ustring.sub(s, 0 - mw.ustring.len(pattern), -1) == pattern then
 
−
return TRUE_STRING
 
−
else
 
−
return FALSE_STRING
 
−
end
 
−
end
 
−
 
 
−
return p
 

Revision as of 17:21, 21 March 2019

Lua error: Internal error: The interpreter exited with status 127. {{#switch:<translate></translate> | = Lua error: Internal error: The interpreter exited with status 127. | #default=

 Script error: No such module "Template translation".

}}